From b19c60bb532bd088815b2f9a2c88b8d2234c3735 Mon Sep 17 00:00:00 2001 From: Jonxslays <51417989+Jonxslays@users.noreply.github.com> Date: Wed, 7 Aug 2024 20:45:42 -0700 Subject: [PATCH] Add pagination to get_snapshots --- CHANGELOG.md | 5 +++-- wom/services/http.py | 2 +- wom/services/players.py | 16 +++++++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8715774..52d91ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ Stable Release Candidate 1 -10x performance increase when serializing models! +10x performance increase when serializing/deserializing models! ## Breaking changes @@ -46,6 +46,7 @@ Stable Release Candidate 1 - Added `CompetitionService.get_details_csv` method. - Added `MetricLeader` class for the different flavors of leader to derive from. - Added `CompetitionCSVTableType` enum for the competition details csv endpoint. +- Added pagination to `PlayerService.get_snapshots`. ## Changes @@ -55,7 +56,7 @@ Stable Release Candidate 1 `Bosses`, and `ComputedMetrics` enums. - `GroupService.create_group` now returns a `CreatedGroupDetail` model. - Updated docstrings for group classes. -- Fixed broken poetry install link in contriubuting guide. +- Fixed broken poetry install link in contributing guide. --- diff --git a/wom/services/http.py b/wom/services/http.py index 2975965..f2ca5b9 100644 --- a/wom/services/http.py +++ b/wom/services/http.py @@ -109,7 +109,7 @@ def _get_request_func(self, method: str) -> t.Callable[..., t.Awaitable[t.Any]]: if not hasattr(self, "_method_mapping"): raise RuntimeError("HttpService.start was never called, aborting...") - return self._method_mapping[method] # type: ignore[return-value] + return self._method_mapping[method] async def _init_session(self) -> None: self._session = aiohttp.ClientSession( diff --git a/wom/services/players.py b/wom/services/players.py index 610a1a8..aa0b010 100644 --- a/wom/services/players.py +++ b/wom/services/players.py @@ -52,9 +52,9 @@ async def search_players( Keyword Args: limit: The maximum number of paginated items to receive. - Defaults to `None` (I think thats 20 items?). + Defaults to `None`. - offset: The page offset for requesting multiple pages. + offset: The page offset for requesting the next page. Defaults to `None`. Returns: @@ -466,6 +466,8 @@ async def get_snapshots( period: t.Optional[enums.Period] = None, start_date: t.Optional[datetime] = None, end_date: t.Optional[datetime] = None, + limit: t.Optional[int] = None, + offset: t.Optional[int] = None, ) -> ResultT[t.List[models.Snapshot]]: """Gets the snapshots for the player. @@ -482,6 +484,12 @@ async def get_snapshots( end_date: The maximum date to get the snapshots from. Defaults to `None`. + limit: The maximum number of paginated items to receive. + Defaults to `None`. + + offset: The page offset for requesting the next page. + Defaults to `None`. + Returns: A [`Result`][wom.Result] containing the list of snapshots. @@ -500,7 +508,7 @@ async def get_snapshots( await client.start() result = await client.players.get_snapshots( - "Jonxslays", period=wom.Period.Week + "Jonxslays", period=wom.Period.Week, limit=3 ) ``` """ @@ -508,6 +516,8 @@ async def get_snapshots( period=period.value if period else None, startDate=start_date.isoformat() if start_date else None, endDate=end_date.isoformat() if end_date else None, + limit=limit if limit else None, + offset=offset if offset else None, ) route = routes.PLAYER_SNAPSHOTS.compile(username)