Skip to content

Instantly share code, notes, and snippets.

@ricomoss
Created January 20, 2015 17:03
Show Gist options
  • Save ricomoss/9bf1da6df55307771274 to your computer and use it in GitHub Desktop.
Save ricomoss/9bf1da6df55307771274 to your computer and use it in GitHub Desktop.
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