Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions huntflow_api_client/entities/webhooks.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
from typing import Any, Dict, 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: Dict[str, Any] = {}
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:
Expand Down
5 changes: 5 additions & 0 deletions huntflow_api_client/models/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion huntflow_api_client/models/request/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
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):
secret: str = Field(..., description="Secret key")
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")
3 changes: 2 additions & 1 deletion huntflow_api_client/models/response/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"},
Expand Down
2 changes: 2 additions & 0 deletions tests/test_entities/test_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"created": "2023-05-04T17:21:14+03:00",
"active": True,
"webhook_events": ["APPLICANT"],
"type": "USER",
},
],
}
Expand All @@ -33,6 +34,7 @@
"created": "2023-05-04T17:24:28+03:00",
"active": True,
"webhook_events": ["APPLICANT"],
"type": "USER",
}


Expand Down
Loading