octo_api.pagination
Class for handling paginated API responses.
Classes:
|
|
|
Represents a multi-page response from a REST API. |
-
typeddict
OctoResponse
[source] Bases:
TypedDict
TypedDict
representing the raw JSON data returned by the Octopus Energy API.
-
class
PaginatedResponse
(query_url, query_params=None, obj_type=<class 'dict'>)[source] Bases:
Iterable
[~_T
]Represents a multi-page response from a REST API.
The items within the response can be iterated over or accessed by their indices. The total number of items can be accessed with
len(response)
.- Parameters
query_url (
SlumberURL
) – The initial query URL.query_params (
Optional
[MutableMapping
[str
,Any
]]) – The parameters to the query. DefaultNone
.obj_type (
Type
) – The object to convert the response data to. Defaultdict
.
Note
This class assumes the JSON response is in the format used by Django REST framework.
The response should be in the following format:
{ "count": 1023, "next": "https://api.example.org/accounts/?page=5", "previous": "https://api.example.org/accounts/?page=3", "results": [] }
See https://www.django-rest-framework.org/api-guide/pagination/ for more information.
Methods:
__eq__
(other)Return
self == other
.__getitem__
(item)Returns the item or items in the
PaginatedResponse
, as given by the index or slice.__iter__
()Iterate over items in the
PaginatedResponse
.__len__
()Returns the number of items in the
PaginatedResponse
.-
__getitem__
(item)[source] Returns the item or items in the
PaginatedResponse
, as given by the index or slice.- Parameters
- Return type
- Overloads
__getitem__
(item:int
) ->~_T
__getitem__
(item:slice
) ->List
[~_T
]
-
__iter__
()[source] Iterate over items in the
PaginatedResponse
.- Return type
Iterator
[~_T
]
-
__len__
()[source] Returns the number of items in the
PaginatedResponse
.- Return type