From 5803a760c9f4d80fd0268bda1e127e434aee94c1 Mon Sep 17 00:00:00 2001 From: koval Date: Mon, 2 Dec 2024 11:43:16 +0300 Subject: [PATCH 1/4] Add WebhookType. --- huntflow_api_client/entities/webhooks.py | 16 ++++++++++++++-- huntflow_api_client/models/consts.py | 5 +++++ huntflow_api_client/models/request/webhooks.py | 3 ++- huntflow_api_client/models/response/webhooks.py | 3 ++- pyproject.toml | 2 +- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/huntflow_api_client/entities/webhooks.py b/huntflow_api_client/entities/webhooks.py index 5c0c7a9..260dd3a 100644 --- a/huntflow_api_client/entities/webhooks.py +++ b/huntflow_api_client/entities/webhooks.py @@ -1,23 +1,35 @@ +from typing import Optional + from huntflow_api_client.entities.base import ( BaseEntity, CreateEntityMixin, DeleteEntityMixin, ListEntityMixin, ) +from huntflow_api_client.models.consts import WebhookType from huntflow_api_client.models.request.webhooks import WebhookRequest from huntflow_api_client.models.response.webhooks import WebhookResponse, WebhooksListResponse class Webhook(BaseEntity, ListEntityMixin, CreateEntityMixin, DeleteEntityMixin): - async def list(self, account_id: int) -> WebhooksListResponse: + async def list( + self, + account_id: int, + webhook_type: Optional[WebhookType] = None, + ) -> WebhooksListResponse: """ API method reference https://api.huntflow.ai/v2/docs#get-/accounts/-account_id-/hooks :param account_id: Organization ID + :param webhook_type: Webhook type. If no value provided, webhooks of all types will be + returned. :return: List of webhooks """ path = f"/accounts/{account_id}/hooks" - response = await self._api.request("GET", path) + params = {} + if webhook_type: + params["webhook_type"] = webhook_type.value + response = await self._api.request("GET", path, params=params) return WebhooksListResponse.model_validate(response.json()) async def create(self, account_id: int, data: WebhookRequest) -> WebhookResponse: diff --git a/huntflow_api_client/models/consts.py b/huntflow_api_client/models/consts.py index 8648a08..cbedcd3 100644 --- a/huntflow_api_client/models/consts.py +++ b/huntflow_api_client/models/consts.py @@ -11,6 +11,11 @@ class WebhookEvent(str, Enum): SURVEY_QUESTIONARY = "SURVEY-QUESTIONARY" +class WebhookType(str, Enum): + USER = "USER" + APPLICATION = "APPLICATION" + + class MemberType(str, Enum): owner = "owner" manager = "manager" diff --git a/huntflow_api_client/models/request/webhooks.py b/huntflow_api_client/models/request/webhooks.py index f9226cb..8298a30 100644 --- a/huntflow_api_client/models/request/webhooks.py +++ b/huntflow_api_client/models/request/webhooks.py @@ -3,7 +3,7 @@ from pydantic import Field from huntflow_api_client.models.common import JsonRequestModel -from huntflow_api_client.models.consts import WebhookEvent +from huntflow_api_client.models.consts import WebhookEvent, WebhookType class WebhookRequest(JsonRequestModel): @@ -11,3 +11,4 @@ class WebhookRequest(JsonRequestModel): url: str = Field(..., description="Webhook URL") active: bool = Field(..., description="Webhook activity flag") webhook_events: List[WebhookEvent] = Field(..., description="List of webhook events") + type: WebhookType = Field(default=WebhookType.USER, description="Webhook type") diff --git a/huntflow_api_client/models/response/webhooks.py b/huntflow_api_client/models/response/webhooks.py index f21e96d..7806d74 100644 --- a/huntflow_api_client/models/response/webhooks.py +++ b/huntflow_api_client/models/response/webhooks.py @@ -3,7 +3,7 @@ from pydantic import AnyHttpUrl, BaseModel, Field, PositiveInt -from huntflow_api_client.models.consts import WebhookEvent +from huntflow_api_client.models.consts import WebhookEvent, WebhookType class WebhookResponse(BaseModel): @@ -13,6 +13,7 @@ class WebhookResponse(BaseModel): created: datetime = Field(..., description="Date and time of creating a webhook") active: bool = Field(..., description="Webhook activity flag") webhook_events: List[WebhookEvent] = Field(..., description="List of webhook events") + type: WebhookType = Field(..., description="Webhook type") class WebhooksListResponse(BaseModel): diff --git a/pyproject.toml b/pyproject.toml index e25370a..526e67a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "huntflow-api-client" -version = "2.4.0" +version = "2.5.0" description = "Huntflow API Client for Python" authors = [ {name = "Developers huntflow", email = "developer@huntflow.ru"}, From a9fbcf6ec5ba2f3faef1eafa4fb98a20aa02914c Mon Sep 17 00:00:00 2001 From: koval Date: Mon, 2 Dec 2024 11:45:32 +0300 Subject: [PATCH 2/4] Add typehint. --- huntflow_api_client/entities/webhooks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/huntflow_api_client/entities/webhooks.py b/huntflow_api_client/entities/webhooks.py index 260dd3a..daa0106 100644 --- a/huntflow_api_client/entities/webhooks.py +++ b/huntflow_api_client/entities/webhooks.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Any, Dict, Optional from huntflow_api_client.entities.base import ( BaseEntity, @@ -26,7 +26,7 @@ async def list( :return: List of webhooks """ path = f"/accounts/{account_id}/hooks" - params = {} + params: Dict[str, Any] = {} if webhook_type: params["webhook_type"] = webhook_type.value response = await self._api.request("GET", path, params=params) From 952957f140634dc6aef31c9a54919c44bc027c04 Mon Sep 17 00:00:00 2001 From: koval Date: Mon, 2 Dec 2024 11:58:19 +0300 Subject: [PATCH 3/4] Fix tests. --- tests/test_entities/test_webhooks.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_entities/test_webhooks.py b/tests/test_entities/test_webhooks.py index 3dee175..e3ae634 100644 --- a/tests/test_entities/test_webhooks.py +++ b/tests/test_entities/test_webhooks.py @@ -22,6 +22,7 @@ "created": "2023-05-04T17:21:14+03:00", "active": True, "webhook_events": ["APPLICANT"], + "type": "USER" }, ], } @@ -33,6 +34,7 @@ "created": "2023-05-04T17:24:28+03:00", "active": True, "webhook_events": ["APPLICANT"], + "type": "USER", } From 029ac2c5949c825e0ecf61c710176043ed235a06 Mon Sep 17 00:00:00 2001 From: koval Date: Mon, 2 Dec 2024 11:59:35 +0300 Subject: [PATCH 4/4] Fix codestyle. --- tests/test_entities/test_webhooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_entities/test_webhooks.py b/tests/test_entities/test_webhooks.py index e3ae634..cc9cf43 100644 --- a/tests/test_entities/test_webhooks.py +++ b/tests/test_entities/test_webhooks.py @@ -22,7 +22,7 @@ "created": "2023-05-04T17:21:14+03:00", "active": True, "webhook_events": ["APPLICANT"], - "type": "USER" + "type": "USER", }, ], }