Skip to content

Commit

Permalink
Add pagination to get_snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonxslays committed Aug 8, 2024
1 parent 414dd07 commit b19c60b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Stable Release Candidate 1

10x performance increase when serializing models!
10x performance increase when serializing/deserializing models!

## Breaking changes

Expand Down Expand Up @@ -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

Expand All @@ -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.

---

Expand Down
2 changes: 1 addition & 1 deletion wom/services/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 13 additions & 3 deletions wom/services/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -500,14 +508,16 @@ 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
)
```
"""
params = self._generate_map(
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)
Expand Down

0 comments on commit b19c60b

Please sign in to comment.