add pagination to accounts/{id}/phishing-campaigns

add pagination to accounts/{id}/phishing-scenarios
This commit is contained in:
Peter Annabel 2025-07-29 10:17:38 -05:00
parent 01d6783d3e
commit 835b0d3649
3 changed files with 71 additions and 1 deletions

View File

@ -1,6 +1,6 @@
[project]
name = "pyhuntress"
version = "0.2.7"
version = "0.2.8"
authors = [
{ name="Peter Annabel", email="peter.annabel@gmail.com" },
]

View File

@ -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,

View File

@ -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,