fix get_next_page() to actually get next page

This commit is contained in:
Peter Annabel 2025-07-23 15:57:49 -05:00
parent 75037a6166
commit bcf940e5ff
3 changed files with 33 additions and 31 deletions

View File

@ -84,7 +84,6 @@ class PaginatedResponse(Generic[TModel]):
self.endpointmodel = endpointmodel
self.endpoint = endpoint
self.limit = limit
print(self.endpoint)
# The following for SIEM is in the response body, not the headers
self.parsed_pagination_response = parse_response_body(json.loads(response.content.decode('utf-8')).get('pagination', {}))
self.params = params
@ -125,6 +124,7 @@ class PaginatedResponse(Generic[TModel]):
next_response.response,
next_response.response_model,
next_response.endpointmodel,
next_response.endpoint,
self.next_page,
next_response.limit,
self.params,

View File

@ -69,34 +69,34 @@ def parse_response_body(
result = {}
if first_page is not None:
result["first_page"] = first_page
if body.get("first_page") is not None:
result["first_page"] = body.get("first_page")
if prev_page is not None:
result["prev_page"] = prev_page
elif current_page is not None:
if current_page > 1:
result["prev_page"] = current_page - 1
if body.get("prev_page") is not None:
result["prev_page"] = body.get("prev_page")
elif body.get("current_page") is not None:
if body.get("current_page") > 1:
result["prev_page"] = body.get("current_page") - 1
if next_page is not None:
result["next_page"] = next_page
if body.get("next_page") is not None:
result["next_page"] = body.get("next_page")
if last_page is not None:
result["last_page"] = last_page
elif last_page is None and current_page is not None:
result["last_page"] = math.ceil(total_count/limit)
if body.get("last_page") is not None:
result["last_page"] = body.get("last_page")
elif body.get("last_page") is None and body.get("current_page") is not None:
result["last_page"] = math.ceil(body.get("total_count")/body.get("limit"))
if has_next_page:
result["has_next_page"] = has_next_page
elif current_page is not None and next_page is not None:
if body.get("has_next_page"):
result["has_next_page"] = body.get("has_next_page")
elif body.get("current_page") is not None and body.get("next_page") is not None:
result["has_next_page"] = True
elif current_page is not None and next_page is None:
elif body.get("current_page") is not None and body.get("next_page") is None:
result["has_next_page"] = False
if has_prev_page:
result["has_prev_page"] = has_prev_page
elif current_page is not None:
if current_page > 1:
if body.get("has_prev_page"):
result["has_prev_page"] = body.get("has_prev_page")
elif body.get("current_page") is not None:
if body.get("current_page") > 1:
result["has_prev_page"] = True
return result

View File

@ -39,17 +39,19 @@ siem_api_client = HuntressSIEMAPIClient(
#signals = siem_api_client.signals.get()
#print(signals)
paginated_billingreports = siem_api_client.billing_reports.paginated(1, 10)
print(paginated_billingreports.data)
#paginated_billingreports = siem_api_client.billing_reports.paginated(1, 10)
#print(paginated_billingreports.data)
paginated_incidentreports = siem_api_client.incident_reports.paginated(1, 10)
print(paginated_incidentreports.data)
#paginated_incidentreports = siem_api_client.incident_reports.paginated(1, 10)
#print(paginated_incidentreports.data)
paginated_organizations = siem_api_client.organizations.paginated(1, 10)
paginated_organizations = siem_api_client.organizations.paginated(1, 1)
print(paginated_organizations.data)
paginated_organizations.get_next_page()
print(paginated_organizations.data)
paginated_reports = siem_api_client.reports.paginated(1, 10)
print(paginated_reports.data)
#paginated_reports = siem_api_client.reports.paginated(1, 10)
#print(paginated_reports.data)
paginated_signals = siem_api_client.signals.paginated(1, 10)
print(paginated_signals.data)
#paginated_signals = siem_api_client.signals.paginated(1, 10)
#print(paginated_signals.data)