mirror of
https://github.com/kennethreitz/neon-api-python.git
synced 2026-06-05 22:50:18 +00:00
Add pagination support to Neon_API_V2 class
This commit is contained in:
@@ -24,6 +24,7 @@ class Neon_API_V2:
|
||||
response_model: BaseModel = None,
|
||||
response_is_array=False,
|
||||
check_status_code=True,
|
||||
include_pagination=False,
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
@@ -62,13 +63,19 @@ class Neon_API_V2:
|
||||
if response_is_array:
|
||||
# Shortcut for when the response is a list of items.
|
||||
if type(response_is_array) == "str":
|
||||
return [
|
||||
response_parsed = [
|
||||
response_model(**item) for item in r.json()[response_is_array]
|
||||
]
|
||||
elif response_is_array == True:
|
||||
return [response_model(**item) for item in r.json()]
|
||||
response_parsed = [response_model(**item) for item in r.json()]
|
||||
else:
|
||||
return response_model(**r.json())
|
||||
response_parsed = response_model(**r.json())
|
||||
|
||||
if include_pagination:
|
||||
pagination = PaginationResponse(**r.json()).pagination
|
||||
response_parsed.pagination = pagination
|
||||
|
||||
return response_parsed
|
||||
else:
|
||||
return r
|
||||
|
||||
|
||||
Reference in New Issue
Block a user