Created
January 20, 2015 17:03
-
-
Save ricomoss/9bf1da6df55307771274 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class YourClass(object): | |
# this decorator will only work with internal class functions | |
def api_retry(func): | |
api_retry_limit = 3 | |
def wrapped(*args): | |
self = args[0] | |
for i in range(api_retry_limit): | |
try: | |
result = func(*args) | |
except ValueError: | |
continue | |
return result | |
# If the API client can't get good data in 3 tries | |
# it will return None. | |
return | |
return wrapped | |
@api_retry | |
def get_content_api(self, adid): | |
url = '{}{}'.format(settings.PROTON_BASE_URL, | |
constants.PROTON_OFFER_META_API) | |
return requests.get(url, params={'offer_id': offer_id, | |
'adid': adid}).json() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment