Skip to content

Commit

Permalink
Add WebhookType.
Browse files Browse the repository at this point in the history
  • Loading branch information
koval committed Dec 2, 2024
1 parent 3d399b3 commit 5803a76
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
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 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:
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 = "[email protected]"},
Expand Down

0 comments on commit 5803a76

Please sign in to comment.