summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-01-24 12:10:16 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2017-01-24 12:10:16 +0100
commit79d3adafe204639f01968fd09ea2dfed94e01940 (patch)
treeae2332ab72dccf19147315548aed0241f33827ba
parent3ccef39f3fe7c995abd3a7b429bf8e134661097a (diff)
downloadpython-gamelocker-79d3adafe204639f01968fd09ea2dfed94e01940.tar.gz
python-gamelocker-79d3adafe204639f01968fd09ea2dfed94e01940.zip
matches: drop arguments, support only parameter dics0.2.0
-rw-r--r--README.md2
-rw-r--r--examples/dashboard/app.py2
-rw-r--r--gamelocker/api.py54
-rw-r--r--tests/gamelocker_test.py14
4 files changed, 13 insertions, 59 deletions
diff --git a/README.md b/README.md
index c9f9960..0d21511 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@ Example usage:
>>> import gamelocker
>>> APIKEY = "aaa.bbb.ccc"
>>> api = gamelocker.Gamelocker(APIKEY).Vainglory()
->>> m = api.matches(limit=2, player="TheLegend27")
+>>> m = api.matches({"page[limit]": 2, "filter[playerNames]": "TheLegend27"})
>>> m
[<gamelocker.datatypes.Match object at 0x7f2682314ac8>, <gamelocker.datatypes.Match object at 0x7f26823d3c50>]
>>> m.rosters[0].participants[0].player.name
diff --git a/examples/dashboard/app.py b/examples/dashboard/app.py
index f256f10..5d00fd2 100644
--- a/examples/dashboard/app.py
+++ b/examples/dashboard/app.py
@@ -34,7 +34,7 @@ def data():
data = dict()
api = gamelocker.Gamelocker("aaa.bbb.ccc").Vainglory()
data["number"] = config.batchsize
- matches = api.matches(data["number"])
+ matches = api.matches({"page[limit]": data["number"]})
playersactors = dict()
gameModes = dict()
diff --git a/gamelocker/api.py b/gamelocker/api.py
index 1220336..5b5a3fa 100644
--- a/gamelocker/api.py
+++ b/gamelocker/api.py
@@ -142,61 +142,15 @@ class Gamelocker(object):
"""
return self._get("players", elid)
- def matches(self,
- limit=None, offset=None, sort=None,
- player=None, team=None,
- createdAtStart=None, createdAtEnd=None):
+ def matches(self, params=None):
"""Returns a list of recent matches.
- :param limit: Maximum number of matches to return.
- :type limit: int
- :param offset: Offset parameter for pagination.
- :type limit: int
- :param sort: Sort query to use.
- :type sort: str
- :param createdAtStart: Earliest createdAt time.
- :type createdAtStart: `datetime.datetime` or str
- :param createdAtEnd: Latest createdAt time.
- :type createdAtEnd: `datetime.datetime` or str
+ :param params: (optional) Query parameters.
+ :type params: dict
: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:
- params["filter[playerNames]"] = player
- if team:
- params["filter[teamNames]"] = team
- if createdAtStart:
- if isinstance(createdAtStart, datetime.datetime):
- createdAtStart = createdAtStart.isoformat()
- params["filter[createdAt-start]"] = createdAtStart
- if createdAtEnd:
- if isinstance(createdAtEnd, datetime.datetime):
- createdAtEnd = createdAtEnd.isoformat()
- params["filter[createdAt-end]"] = createdAtEnd
-
- # 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+offset
- matches += self._get("matches", params=params)
- limit -= max_limit
-
- return matches
+ return self._get("matches", params=params)
pretty = gamelocker.strings.pretty
diff --git a/tests/gamelocker_test.py b/tests/gamelocker_test.py
index 50c1cb7..422c1d2 100644
--- a/tests/gamelocker_test.py
+++ b/tests/gamelocker_test.py
@@ -49,9 +49,9 @@ class TestGamelocker:
assert matches[0].duration > 0
def test_matchesfilters(self, api):
- matches1 = api.matches(limit=3)
+ matches1 = api.matches({"page[limit]": 3})
assert len(matches1) == 3
- matches2 = api.matches(limit=3, offset=1)
+ matches2 = api.matches({"page[limit]": 3, "page[offset]": 1})
commons = 0 # 3 matches each, offset 1 -> 2 overlap
for match1 in matches1:
@@ -60,10 +60,10 @@ class TestGamelocker:
commons += 1
assert commons == 2
- assert len(api.matches(limit=42)) == 42
+ assert len(api.matches({"page[limit]": 42})) == 42
# TODO uncomment as soon as the API is up
-# matches = api.matches(limit=10, sort="duration")
+# matches = api.matches({"page[limit]": 10, "sort": "duration"})
# assert matches[0].duration < matches[9].duration
def fromiso(s):
@@ -71,12 +71,12 @@ class TestGamelocker:
start = "2017-01-10T02:25:00Z"
end = "2017-01-12T02:30:00Z"
- matches = api.matches(createdAtStart=start, createdAtEnd=end)
+ matches = api.matches({"filter[createdAt-start]": start, "filter[createdAt-end]": end})
for match in matches:
assert fromiso(end) >= fromiso(match.createdAt) >= fromiso(start)
nick = "MMotooks123"
- matches = api.matches(limit=5, player=nick)
+ matches = api.matches({"page[limit]": 5, "filter[playerNames]": nick})
for match in matches:
success = False
for roster in match.rosters:
@@ -87,7 +87,7 @@ class TestGamelocker:
assert success
team = "HALO"
- matches = api.matches(limit=5, team=team)
+ matches = api.matches({"page[limit]": 5, "filter[teamNames]": team})
for match in matches:
success = False
for roster in match.rosters: