Add pagination support to Neon_API_V2 class

This commit is contained in:
2024-01-14 17:27:28 -05:00
parent b547bb0941
commit 10368c78f1
3 changed files with 83 additions and 49 deletions
+10 -3
View File
@@ -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