Skip to content

Commit

Permalink
Add sdk.webhooks.patch
Browse files Browse the repository at this point in the history
  • Loading branch information
0e4ef622 committed Oct 21, 2024
1 parent d609da8 commit 70c3b85
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion ntropy_sdk/webhooks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import List, Literal, Optional, TYPE_CHECKING
from typing import List, Literal, Optional, TYPE_CHECKING, Union
import uuid

from pydantic import BaseModel, Field
Expand All @@ -11,6 +11,13 @@
from ntropy_sdk import SDK
from typing_extensions import Unpack


class _Unset:
pass


UNSET = _Unset()

WebhookEventType = Literal[
"reports.resolved",
"reports.rejected",
Expand Down Expand Up @@ -41,6 +48,9 @@ class Webhook(BaseModel):
"value will be included in the `X-Ntropy-Token` header when sending "
"requests to the webhook",
)
enabled: bool = Field(
description="Whether the webhook is enabled or not.",
)
request_id: Optional[str] = None

def delete(self, sdk: "SDK", **extra_kwargs: "Unpack[ExtraKwargs]"):
Expand Down Expand Up @@ -120,3 +130,34 @@ def delete(self, id: str, **extra_kwargs: "Unpack[ExtraKwargs]"):
url=f"/v3/webhooks/{id}",
**extra_kwargs,
)

def patch(
self,
id: str,
*,
url: Union[str, _Unset] = UNSET,
events: Union[List[WebhookEventType], _Unset] = UNSET,
token: Union[str, None, _Unset] = UNSET,
enabled: Union[bool, _Unset] = UNSET,
**extra_kwargs: "Unpack[ExtraKwargs]",
):
payload = {}
if url is not UNSET:
payload["url"] = url
if events is not UNSET:
payload["events"] = events
if token is not UNSET:
payload["token"] = token
if enabled is not UNSET:
payload["enabled"] = enabled

request_id = extra_kwargs.get("request_id")
if request_id is None:
request_id = uuid.uuid4().hex
extra_kwargs["request_id"] = request_id
self._sdk.retry_ratelimited_request(
method="PATCH",
url=f"/v3/webhooks/{id}",
payload=payload,
**extra_kwargs,
)

0 comments on commit 70c3b85

Please sign in to comment.