From 835b0d3649f50e84e53014543265646dfd7b7a56 Mon Sep 17 00:00:00 2001 From: Peter Annabel Date: Tue, 29 Jul 2025 10:17:38 -0500 Subject: [PATCH] add pagination to accounts/{id}/phishing-campaigns add pagination to accounts/{id}/phishing-scenarios --- pyproject.toml | 2 +- .../AccountsIdPhishingCampaignsEndpoint.py | 35 +++++++++++++++++++ .../AccountsIdPhishingScenariosEndpoint.py | 35 +++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8dab00a..4709382 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pyhuntress" -version = "0.2.7" +version = "0.2.8" authors = [ { name="Peter Annabel", email="peter.annabel@gmail.com" }, ] diff --git a/src/pyhuntress/endpoints/managedsat/AccountsIdPhishingCampaignsEndpoint.py b/src/pyhuntress/endpoints/managedsat/AccountsIdPhishingCampaignsEndpoint.py index 308d0fe..bfd667b 100644 --- a/src/pyhuntress/endpoints/managedsat/AccountsIdPhishingCampaignsEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/AccountsIdPhishingCampaignsEndpoint.py @@ -1,8 +1,10 @@ from pyhuntress.endpoints.base.huntress_endpoint import HuntressEndpoint from pyhuntress.interfaces import ( IGettable, + IPaginateable, ) from pyhuntress.models.managedsat import SATPhishingCampaigns +from pyhuntress.responses.paginated_response import PaginatedResponse from pyhuntress.types import ( JSON, HuntressSATRequestParams, @@ -12,10 +14,43 @@ from pyhuntress.types import ( class AccountsIdPhishingCampaignsEndpoint( HuntressEndpoint, IGettable[SATPhishingCampaigns, HuntressSATRequestParams], + IPaginateable[SATPhishingCampaigns, HuntressSATRequestParams], ): def __init__(self, client, parent_endpoint=None) -> None: HuntressEndpoint.__init__(self, client, "phishing_campaigns", parent_endpoint=parent_endpoint) IGettable.__init__(self, SATPhishingCampaigns) + IPaginateable.__init__(self, SATPhishingCampaigns) + + def paginated( + self, + page: int, + limit: int, + params: HuntressSATRequestParams | None = None, + ) -> PaginatedResponse[SATPhishingCampaigns]: + """ + Performs a GET request against the /accounts/{id}/phishing-campaigns endpoint and returns an initialized PaginatedResponse object. + + Parameters: + page (int): The page number to request. + limit (int): The number of results to return per page. + params (dict[str, int | str]): The parameters to send in the request query string. + Returns: + PaginatedResponse[SATPhishingCampaigns]: The initialized PaginatedResponse object. + """ + if params: + params["page[number]"] = page + params["page[size]"] = limit + else: + params = {"page[number]": page, "page[size]": limit} + return PaginatedResponse( + super()._make_request("GET", params=params), + SATPhishingCampaigns, + self, + "data", + page, + limit, + params, + ) def get( self, diff --git a/src/pyhuntress/endpoints/managedsat/AccountsIdPhishingScenariosEndpoint.py b/src/pyhuntress/endpoints/managedsat/AccountsIdPhishingScenariosEndpoint.py index 8cc49aa..a47d06e 100644 --- a/src/pyhuntress/endpoints/managedsat/AccountsIdPhishingScenariosEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/AccountsIdPhishingScenariosEndpoint.py @@ -1,8 +1,10 @@ from pyhuntress.endpoints.base.huntress_endpoint import HuntressEndpoint from pyhuntress.interfaces import ( IGettable, + IPaginateable, ) from pyhuntress.models.managedsat import SATPhishingScenarios +from pyhuntress.responses.paginated_response import PaginatedResponse from pyhuntress.types import ( JSON, HuntressSATRequestParams, @@ -12,10 +14,43 @@ from pyhuntress.types import ( class AccountsIdPhishingScenariosEndpoint( HuntressEndpoint, IGettable[SATPhishingScenarios, HuntressSATRequestParams], + IPaginateable[SATPhishingScenarios, HuntressSATRequestParams], ): def __init__(self, client, parent_endpoint=None) -> None: HuntressEndpoint.__init__(self, client, "phishing_scenarios", parent_endpoint=parent_endpoint) IGettable.__init__(self, SATPhishingScenarios) + IPaginateable.__init__(self, SATPhishingScenarios) + + def paginated( + self, + page: int, + limit: int, + params: HuntressSATRequestParams | None = None, + ) -> PaginatedResponse[SATPhishingScenarios]: + """ + Performs a GET request against the /accounts/{id}/phishing-scenarios endpoint and returns an initialized PaginatedResponse object. + + Parameters: + page (int): The page number to request. + limit (int): The number of results to return per page. + params (dict[str, int | str]): The parameters to send in the request query string. + Returns: + PaginatedResponse[SATPhishingScenarios]: The initialized PaginatedResponse object. + """ + if params: + params["page[number]"] = page + params["page[size]"] = limit + else: + params = {"page[number]": page, "page[size]": limit} + return PaginatedResponse( + super()._make_request("GET", params=params), + SATPhishingScenarios, + self, + "data", + page, + limit, + params, + ) def get( self,