Skip to content

Commit

Permalink
Add records_key to SinglePagePaginator
Browse files Browse the repository at this point in the history
  • Loading branch information
burnash committed Feb 22, 2024
1 parent 884120b commit d5eaee1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion sources/rest_api/paginators.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def extract_records(self, response: Response) -> Any:

class SinglePagePaginator(BasePaginator):
"""A paginator for single-page API responses."""
def __init__(
self,
records_key: Union[str, Sequence[str]] = None,
):
super().__init__()
self.records_key = records_key
self._records_accessor = create_nested_accessor(records_key)

def update_state(self, response: Response) -> None:
self._has_next_page = False
Expand All @@ -83,7 +90,9 @@ def prepare_next_request_args(self, url, params, json):
return None, None, None

def extract_records(self, response: Response) -> Any:
return response.json()
if self.records_key is None:
return response.json()
return self._records_accessor(response.json())


class OffsetPaginator(BasePaginator):
Expand Down

0 comments on commit d5eaee1

Please sign in to comment.