diff --git a/tele_giphy/game/giphy.py b/tele_giphy/game/giphy.py index 271209a..fed8640 100644 --- a/tele_giphy/game/giphy.py +++ b/tele_giphy/game/giphy.py @@ -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: @@ -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: