generated from mwc/lab_riddles
I added the code for the three missing methods so
that the riddles would work. 1. I regularly use the weather app on my phone. This http request would rely on a few different factors. It would need to call upon location first, then pull data based on that location and display it. This is complicated by the requests for additional informaiton such as humidity, sun rise and set, percipitation, etc. However, I think those would all pull fom similar or the same database(s). I Thikn that there is something interesting though in the push notifications that come through when thereis an emergency weather alert. It would have to establish the route, the params would call the location and status information that the app would need to access accurate data to display, then the response would be the answers to the queries. 2. This lab really helped me conceptualize the process of such technological connections. I always knew that the things we "call upon" in our computational daily lives are complex and have so many moving parts. One struggle I had in this lab was that when I was coding the response lines I used the word 'error' instead of 'errors'. The one little 's' threw the entire system into an error (ironically).
This commit is contained in:
parent
dc74331805
commit
eb40603441
24
api.py
24
api.py
|
@ -36,17 +36,31 @@ class RiddleAPI:
|
|||
def get_riddle(self, riddle_id):
|
||||
"Fetches a single riddle from the server"
|
||||
route = "/show"
|
||||
raise NotImplementedError("The API doesn't support `get_riddle` yet. Can you add it?")
|
||||
params = {'id': riddle_id}
|
||||
response = requests.get(self.server_url + route, params=params)
|
||||
if response.ok:
|
||||
return response.json()
|
||||
else:
|
||||
raise APIError(response.json()['errors'])
|
||||
#done
|
||||
|
||||
def get_random_riddle(self):
|
||||
"Fetches all riddles from the server and then randomly returns one"
|
||||
raise NotImplementedError("The API doesn't support `get_random_riddle` yet. Can you add it?")
|
||||
riddles = self.get_all_riddles()
|
||||
return choice(riddles)
|
||||
#done
|
||||
|
||||
|
||||
def add_riddle(self, question, answer):
|
||||
"Adds a new riddle to the server"
|
||||
route = "/new"
|
||||
raise NotImplementedError("The API doesn't support `add_riddle` yet. Can you add it?")
|
||||
|
||||
route = "/new"
|
||||
params = {'question': question, 'answer': answer}
|
||||
response = requests.post(self.server_url + route, json=params)
|
||||
if response.ok:
|
||||
return response.json()
|
||||
else:
|
||||
raise APIError(response.json()['errors'])
|
||||
#done
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue