psnawp_api.models.listing.pagination_iterator module#
Provides the PaginationIterator class.
- class PaginationArguments(total_limit: int | None, page_size: int, offset: int)[source]#
Bases:
objectClass representing the arguments PlayStation API needs for paginating over list items.
Used by the implementations of
PaginationIterator.- Variables:
- property adjusted_page_size: int#
Calculates the adjusted page size based on the total limit.
If total_limit is None, returns the original page_size. If total_limit is less than page_size, returns total_limit.
- class PaginationIterator(*, authenticator: Authenticator, url: str, pagination_args: PaginationArguments)[source]#
Bases:
Iterator[T],Generic[T]An iterator for paginated API endpoints.
This class simplifies pagination by handling iteration over API responses. Subclasses only need to implement the
fetch_next_page()method, while this class manages the iteration logic.- Variables:
authenticator (Authenticator) – An instance of
Authenticatorused to authenticate and make HTTPS requests._url (str) – URL for the paginated endpoint.
_pagination_args (PaginationArguments) – Pagination-specific arguments, such as page size and limit, passed to the endpoint.
_per_page_iterator (Iterator[T] | None) – A generator that iterates over items in the fetched page.
_has_next (bool) – Indicates whether more pages are available. Is updated when
fetch_next_page()is called._total_item_count (int) – The total number of items available in the paginated endpoint.
Warning
This class is not meant to be used directly.
Initialize the PaginationIterator instance.
- Parameters:
authenticator – An instance of Authenticator for making API requests.
url – The URL of the endpoint.
pagination_args – Pagination-related arguments, such as page size and limit.
- __init__(*, authenticator: Authenticator, url: str, pagination_args: PaginationArguments) None[source]#
Initialize the PaginationIterator instance.
- Parameters:
authenticator – An instance of Authenticator for making API requests.
url – The URL of the endpoint.
pagination_args – Pagination-related arguments, such as page size and limit.
- abstractmethod fetch_next_page() Iterator[T][source]#
Fetch the next page of items from the API.
Note
The implementation of this methods are also responsible for incrementing the offset using
increment_offset(), setting the_total_item_count, and updating the_has_next.