Skip to content

Commit

Permalink
add in rating support for #99
Browse files Browse the repository at this point in the history
  • Loading branch information
zapplecat committed Sep 25, 2016
1 parent fc9c837 commit 21142f0
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions tele_giphy/game/giphy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,37 @@
KEY = 'dc6zaTOxFJmzC'


def _gif_random(tag='american psycho', api_key=KEY):
def _gif_random(tag='american psycho', api_key=KEY, rating=''):
# See https://github.com/Giphy/GiphyAPI#random-endpoint
endpoint = GIPHY_URL + 'random'
params = {'api_key': api_key, 'tag': tag}
if not rating:
params['rating'] = rating
data = get(endpoint, params)
return data


def _gif_translate(string='leeroy', api_key=KEY):
def _gif_translate(string='leeroy', api_key=KEY, rating=''):
# See https://github.com/Giphy/GiphyAPI#translate-endpoint
endpoint = GIPHY_URL + 'translate'
params = {'api_key': api_key, 's': string}
if not rating:
params['rating'] = rating
data = get(endpoint, params)
return data


# Standarize random and translate endpoint returns
def giphy_call(call_type='translate', phrase='doge', api_key=KEY):
def giphy_call(call_type='translate', phrase='doge', api_key=KEY, rating=''):
standard_data = {'call_type': '',
'image_url': '',
'phrase': '',
'meta': {}}
if call_type == 'translate':
resp = _gif_translate(string=phrase, api_key=api_key)
if not rating:
resp = _gif_translate(string=phrase, api_key=api_key)
else:
resp = _gif_translate(string=phrase, api_key=api_key, rating=rating)
resp_json = resp.json()
standard_data['meta'] = resp_json['meta']
if resp.status_code == 200:
Expand All @@ -38,7 +45,10 @@ def giphy_call(call_type='translate', phrase='doge', api_key=KEY):
return standard_data

elif call_type == 'random':
resp = _gif_random(tag=phrase, api_key=api_key)
if not rating:
resp = _gif_random(tag=phrase, api_key=api_key)
else:
resp = _gif_random(tag=phrase, api_key=api_key, rating=rating)
resp_json = resp.json()
standard_data['meta'] = resp_json['meta']
if resp.status_code == 200:
Expand Down

0 comments on commit 21142f0

Please sign in to comment.