Return complete response instance from API methods

master
Nikola Forró 7 years ago
parent ad0c3294db
commit bf2c33c31a

@ -97,26 +97,26 @@ class TwitchBot(irc.bot.SingleServerIRCBot):
def get(self, params):
r = requests.get('{0}/quotes'.format(self.api_url), params=params)
r.raise_for_status()
return r.json()
return r
def post(self, data):
r = requests.post('{0}/quotes'.format(self.api_url), data=data,
headers={'X-Quotes-API-Key': self.api_key})
r.raise_for_status()
return r.json()
return r
def delete(self, id):
r = requests.delete('{0}/quotes/{1}'.format(self.api_url, id),
headers={'X-Quotes-API-Key': self.api_key})
r.raise_for_status()
return r.json()
return r
def last_quote(self, connection, tags, **kwargs):
try:
quotes = self.get(dict(
sort_by='id',
sort_order='desc',
page_size=1))
page_size=1)).json()
quote = quotes[0]
except (requests.exceptions.HTTPError, IndexError):
msg = 'Sorry @{0}, no quotes found'.format(tags['display-name'])
@ -134,7 +134,7 @@ class TwitchBot(irc.bot.SingleServerIRCBot):
filter=filter,
sort_by='id',
sort_order='desc',
page_size=1))
page_size=1)).json()
quote = quotes[0]
except (requests.exceptions.HTTPError, IndexError):
msg = 'Sorry @{0}, no quotes found'.format(tags['display-name'])
@ -152,7 +152,7 @@ class TwitchBot(irc.bot.SingleServerIRCBot):
quotes = self.get(dict(
sort_by='id',
sort_order='desc',
page_size=1))
page_size=1)).json()
quote = quotes[0]
except requests.exceptions.HTTPError as e:
log.error('Failed to get quotes: %s', str(e))

Loading…
Cancel
Save