generated from mwc/lab_riddles
Compare commits
No commits in common. "6de3b3ab617f5eb7e7ac3b439deb7937decf62e3" and "63e2e7096e92ca89673f980145d9d12bb070b582" have entirely different histories.
6de3b3ab61
...
63e2e7096e
Binary file not shown.
18
api.py
18
api.py
|
@ -36,28 +36,16 @@ class RiddleAPI:
|
||||||
def get_riddle(self, riddle_id):
|
def get_riddle(self, riddle_id):
|
||||||
"Fetches a single riddle from the server"
|
"Fetches a single riddle from the server"
|
||||||
route = "/show"
|
route = "/show"
|
||||||
params = {'id' : riddle_id}
|
raise NotImplementedError("The API doesn't support `get_riddle` yet. Can you add it?")
|
||||||
response = requests.get(self.server_url + route, json=params)
|
|
||||||
if response.ok:
|
|
||||||
return response.json()
|
|
||||||
else:
|
|
||||||
raise APIError(response.json()['errors'])
|
|
||||||
|
|
||||||
def get_random_riddle(self):
|
def get_random_riddle(self):
|
||||||
"Fetches all riddles from the server and then randomly returns one"
|
"Fetches all riddles from the server and then randomly returns one"
|
||||||
riddles = self.get_all_riddles()
|
raise NotImplementedError("The API doesn't support `get_random_riddle` yet. Can you add it?")
|
||||||
riddle = choice(riddles)
|
|
||||||
return riddle
|
|
||||||
|
|
||||||
def add_riddle(self, question, answer):
|
def add_riddle(self, question, answer):
|
||||||
"Adds a new riddle to the server"
|
"Adds a new riddle to the server"
|
||||||
route = "/new"
|
route = "/new"
|
||||||
params = {'question': question, 'answer': answer}
|
raise NotImplementedError("The API doesn't support `add_riddle` yet. Can you add it?")
|
||||||
response = requests.post(self.server_url + route, json=params)
|
|
||||||
if response.ok:
|
|
||||||
return response.json()
|
|
||||||
else:
|
|
||||||
raise APIError(response.json()['errors'])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
10
notes.md
10
notes.md
|
@ -7,16 +7,6 @@ about the meaning of the line, and some situation in which it might be useful.
|
||||||
You are welcome to research the meanings of these headers, but it's also
|
You are welcome to research the meanings of these headers, but it's also
|
||||||
fine to speculate for now.
|
fine to speculate for now.
|
||||||
|
|
||||||
Line 5: Keeps the connection open for multiple requests/responses.
|
|
||||||
|
|
||||||
Line 6: Shows where the request is being sent
|
|
||||||
|
|
||||||
Line 7: This shows who is making the HTTP request.
|
|
||||||
|
|
||||||
Line 13: This shows the length of the requested information.
|
|
||||||
|
|
||||||
Line 14: This shows the filetype of what was requested.
|
|
||||||
|
|
||||||
## Checkpoint 2
|
## Checkpoint 2
|
||||||
The goal of this checkpoint is to see what status codes you can get back from
|
The goal of this checkpoint is to see what status codes you can get back from
|
||||||
the riddle server. Paste below several `http` requests and the status codes
|
the riddle server. Paste below several `http` requests and the status codes
|
||||||
|
|
Loading…
Reference in New Issue