diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-01-15 19:35:30 +0100 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-01-15 19:35:39 +0100 |
| commit | be0b8968651f98b962a18c4e750d6396c0fdaf47 (patch) | |
| tree | 5d577ecb713068cc91feeb3f1c22ae134dbf236a /gamelocker/api.py | |
| parent | 517ac9c3f5b342327ddb248436fc7b47ce54b885 (diff) | |
| download | python-gamelocker-be0b8968651f98b962a18c4e750d6396c0fdaf47.tar.gz python-gamelocker-be0b8968651f98b962a18c4e750d6396c0fdaf47.zip | |
add functions to fancify items
Diffstat (limited to 'gamelocker/api.py')
| -rw-r--r-- | gamelocker/api.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/gamelocker/api.py b/gamelocker/api.py index 6857eba..c1383d6 100644 --- a/gamelocker/api.py +++ b/gamelocker/api.py @@ -3,7 +3,7 @@ # TODO: generate documentation """ -requests.api +gamelocker.api This module implements the Gamelocker API. """ @@ -11,6 +11,7 @@ This module implements the Gamelocker API. import datetime import requests import gamelocker.datatypes +import gamelocker.strings class Gamelocker(object): @@ -157,12 +158,18 @@ class Gamelocker(object): :return: List of matches. :rtype: list of dict """ + max_limit = 50 # as set by the API + params = dict() # TODO: deprecate by ?limit=x&offset=y soon if limit: params["page[limit]"] = limit + else: + limit = max_limit if offset: params["page[offset]"] = offset + else: + offset = 0 if sort: # TODO make this nice and usable params["sort"] = sort if player: @@ -178,4 +185,12 @@ class Gamelocker(object): createdAtEnd = createdAtEnd.isoformat() params["filter[createdAt-end]"] = createdAtEnd - return self._get("matches", params=params) + # split request to batches of 50 + matches = [] + for batch in range(0, limit, max_limit): + params["page[limit]"] = min(limit, max_limit) + params["page[offset]"] = batch*max_limit+offset + matches += self._get("matches", params=params) + limit -= max_limit + + return matches |
