diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-02-25 12:22:47 +0100 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-02-25 12:22:47 +0100 |
| commit | 174019005c5dbb3b77d7a9db7e51c633fa7cbf71 (patch) | |
| tree | 6c5d1fbfb8f2e686fc0bc85c4ab83b1e1a55a272 /gamelocker/api.py | |
| parent | 29deddab122b6dca89030e9a9c2ef641be53f45c (diff) | |
| download | python-gamelocker-174019005c5dbb3b77d7a9db7e51c633fa7cbf71.tar.gz python-gamelocker-174019005c5dbb3b77d7a9db7e51c633fa7cbf71.zip | |
update wrapper and tests for latest API changes
* deprecated "strings" module: API returns clean names already
* an API token needs to be passed to the unit tests by an environment
variable
Diffstat (limited to 'gamelocker/api.py')
| -rw-r--r-- | gamelocker/api.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/gamelocker/api.py b/gamelocker/api.py index 93b1068..8753cce 100644 --- a/gamelocker/api.py +++ b/gamelocker/api.py @@ -6,9 +6,9 @@ gamelocker.api This module implements the Gamelocker API. """ +import logging import requests import gamelocker.datatypes -import gamelocker.strings class Gamelocker(object): @@ -41,13 +41,19 @@ class Gamelocker(object): :rtype: dict """ headers = { - "Authorization": "Bearer " + self.apikey, + "Authorization": self.apikey, "X-TITLE-ID": self.title, "Accept": "application/vnd.api+json" } - http = requests.get(self._apiurl + method, - headers=headers, - params=params) + while True: + http = requests.get(self._apiurl + method, + headers=headers, + params=params) + if http.status_code != 429: + # 429 -> rate limit, retry + break + logging.info("You are being rate limited by the API") + http.raise_for_status() return http.json() @@ -137,7 +143,7 @@ class Gamelocker(object): See http://developer.vainglorygame.com/docs/#get-a-collection-of-matches for parameters. - :param params: (optional) Query parameters. + :param params: Query parameters. :type params: dict :param region: (optional) Shard to query. Defaults to "na". :type region: str @@ -145,6 +151,3 @@ class Gamelocker(object): :rtype: list of dict """ return self._get("matches", params=params, region=region) - - -pretty = gamelocker.strings.pretty |
