Skip to content

Commit

Permalink
Updated to use v2 of the underquoted api
Browse files Browse the repository at this point in the history
  • Loading branch information
jessamynsmith committed Apr 20, 2015
1 parent 1c61d08 commit f5b0923
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions plugins/talk_back.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@

class TalkBackPlugin(WillPlugin):

QUOTES_URL = ("https://underquoted.herokuapp.com/api/v1/quotations/?"
"format=json&random=true&limit=1")
QUOTES_URL = "https://underquoted.herokuapp.com/api/v2/quotations/?random=true&limit=1"

def get_quote(self):
quote = None
response = requests.get(self.QUOTES_URL)
if response.status_code == 200:
try:
quote_obj = response.json()['objects'][0]
quote = u'%s ~ %s' % (quote_obj['text'],
quote_obj['author']['name'])
quote_obj = response.json()['results'][0]
quote = u'%s ~ %s' % (quote_obj['text'], quote_obj['author'])
except ValueError:
logging.error(
"Response from '%s' could not be decoded as JSON:\n%s"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_talk_back.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_get_quote_invalid_response_format(self, mock_get):

@patch('requests.get')
def test_get_quote_success(self, mock_get):
data = {'objects': [{'text': 'Hi!', 'author': {'name': 'An'}}]}
data = {'results': [{'text': 'Hi!', 'author': 'An'}]}
mock_json = MagicMock(return_value=data)
mock_get.return_value = MagicMock(status_code=200, json=mock_json)

Expand All @@ -64,7 +64,7 @@ def test_talk_back_no_quote(self, mock_get, mock_reply):
@patch('will.plugin.WillPlugin.reply')
@patch('requests.get')
def test_talk_back_success(self, mock_get, mock_reply):
data = {'objects': [{'text': 'Hi!', 'author': {'name': 'An'}}]}
data = {'results': [{'text': 'Hi!', 'author': 'An'}]}
mock_json = MagicMock(return_value=data)
mock_get.return_value = MagicMock(status_code=200, json=mock_json)

Expand Down

0 comments on commit f5b0923

Please sign in to comment.