Skip to content

docs(tem): add info about webhooks #604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2024
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
4 changes: 4 additions & 0 deletions scaleway-async/scaleway_async/tem/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@
from .types import CreateDomainRequest
from .types import CreateEmailRequest
from .types import CreateEmailResponse
from .types import CreateWebhookRequest
from .types import DeleteWebhookRequest
from .types import DomainLastStatus
from .types import GetDomainLastStatusRequest
from .types import GetDomainRequest
from .types import GetEmailRequest
from .types import GetStatisticsRequest
from .types import GetWebhookRequest
from .types import ListDomainsRequest
from .types import ListDomainsResponse
from .types import ListEmailsRequest
Expand Down Expand Up @@ -86,12 +88,14 @@
"CreateDomainRequest",
"CreateEmailRequest",
"CreateEmailResponse",
"CreateWebhookRequest",
"DeleteWebhookRequest",
"DomainLastStatus",
"GetDomainLastStatusRequest",
"GetDomainRequest",
"GetEmailRequest",
"GetStatisticsRequest",
"GetWebhookRequest",
"ListDomainsRequest",
"ListDomainsResponse",
"ListEmailsRequest",
Expand Down
89 changes: 89 additions & 0 deletions scaleway-async/scaleway_async/tem/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
CreateEmailRequestAttachment,
CreateEmailRequestHeader,
CreateEmailResponse,
CreateWebhookRequest,
Domain,
DomainLastStatus,
Email,
Expand Down Expand Up @@ -58,6 +59,7 @@
unmarshal_Statistics,
marshal_CreateDomainRequest,
marshal_CreateEmailRequest,
marshal_CreateWebhookRequest,
marshal_UpdateWebhookRequest,
)

Expand Down Expand Up @@ -755,6 +757,60 @@ async def get_domain_last_status(
self._throw_on_error(res)
return unmarshal_DomainLastStatus(res.json())

async def create_webhook(
self,
*,
domain_id: str,
name: str,
sns_arn: str,
region: Optional[Region] = None,
project_id: Optional[str] = None,
event_types: Optional[List[WebhookEventType]] = None,
) -> Webhook:
"""
Create a Webhook.
Create a new Webhook triggered by a list of event types and pushed to a Scaleway SNS ARN.
:param domain_id: ID of the Domain to watch for triggering events.
:param name: Name of the Webhook.
:param sns_arn: Scaleway SNS ARN topic to push the events to.
:param region: Region to target. If none is passed will use default region from the config.
:param project_id: ID of the project to which the Webhook belongs.
:param event_types: List of event types that will trigger an event.
:return: :class:`Webhook <Webhook>`

Usage:
::

result = await api.create_webhook(
domain_id="example",
name="example",
sns_arn="example",
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)

res = self._request(
"POST",
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks",
body=marshal_CreateWebhookRequest(
CreateWebhookRequest(
domain_id=domain_id,
name=name,
sns_arn=sns_arn,
region=region,
project_id=project_id,
event_types=event_types,
),
self.client,
),
)

self._throw_on_error(res)
return unmarshal_Webhook(res.json())

async def list_webhooks(
self,
*,
Expand Down Expand Up @@ -845,6 +901,39 @@ async def list_webhooks_all(
},
)

async def get_webhook(
self,
*,
webhook_id: str,
region: Optional[Region] = None,
) -> Webhook:
"""
Get information about a Webhook.
:param webhook_id: ID of the Webhook to check.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Webhook <Webhook>`

Usage:
::

result = await api.get_webhook(
webhook_id="example",
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)
param_webhook_id = validate_path_param("webhook_id", webhook_id)

res = self._request(
"GET",
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks/{param_webhook_id}",
)

self._throw_on_error(res)
return unmarshal_Webhook(res.json())

async def update_webhook(
self,
*,
Expand Down
25 changes: 25 additions & 0 deletions scaleway-async/scaleway_async/tem/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
CreateEmailRequestAttachment,
CreateEmailRequestHeader,
CreateEmailRequest,
CreateWebhookRequest,
UpdateWebhookRequest,
)

Expand Down Expand Up @@ -837,6 +838,30 @@ def marshal_CreateEmailRequest(
return output


def marshal_CreateWebhookRequest(
request: CreateWebhookRequest,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.domain_id is not None:
output["domain_id"] = request.domain_id

if request.name is not None:
output["name"] = request.name

if request.sns_arn is not None:
output["sns_arn"] = request.sns_arn

if request.project_id is not None:
output["project_id"] = request.project_id or defaults.default_project_id

if request.event_types is not None:
output["event_types"] = [str(item) for item in request.event_types]

return output


def marshal_UpdateWebhookRequest(
request: UpdateWebhookRequest,
defaults: ProfileDefaults,
Expand Down
46 changes: 46 additions & 0 deletions scaleway-async/scaleway_async/tem/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,39 @@ class CreateEmailResponse:
"""


@dataclass
class CreateWebhookRequest:
domain_id: str
"""
ID of the Domain to watch for triggering events.
"""

name: str
"""
Name of the Webhook.
"""

sns_arn: str
"""
Scaleway SNS ARN topic to push the events to.
"""

region: Optional[Region]
"""
Region to target. If none is passed will use default region from the config.
"""

project_id: Optional[str]
"""
ID of the project to which the Webhook belongs.
"""

event_types: Optional[List[WebhookEventType]]
"""
List of event types that will trigger an event.
"""


@dataclass
class DeleteWebhookRequest:
webhook_id: str
Expand Down Expand Up @@ -823,6 +856,19 @@ class GetStatisticsRequest:
"""


@dataclass
class GetWebhookRequest:
webhook_id: str
"""
ID of the Webhook to check.
"""

region: Optional[Region]
"""
Region to target. If none is passed will use default region from the config.
"""


@dataclass
class ListDomainsRequest:
region: Optional[Region]
Expand Down
4 changes: 4 additions & 0 deletions scaleway/scaleway/tem/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@
from .types import CreateDomainRequest
from .types import CreateEmailRequest
from .types import CreateEmailResponse
from .types import CreateWebhookRequest
from .types import DeleteWebhookRequest
from .types import DomainLastStatus
from .types import GetDomainLastStatusRequest
from .types import GetDomainRequest
from .types import GetEmailRequest
from .types import GetStatisticsRequest
from .types import GetWebhookRequest
from .types import ListDomainsRequest
from .types import ListDomainsResponse
from .types import ListEmailsRequest
Expand Down Expand Up @@ -86,12 +88,14 @@
"CreateDomainRequest",
"CreateEmailRequest",
"CreateEmailResponse",
"CreateWebhookRequest",
"DeleteWebhookRequest",
"DomainLastStatus",
"GetDomainLastStatusRequest",
"GetDomainRequest",
"GetEmailRequest",
"GetStatisticsRequest",
"GetWebhookRequest",
"ListDomainsRequest",
"ListDomainsResponse",
"ListEmailsRequest",
Expand Down
89 changes: 89 additions & 0 deletions scaleway/scaleway/tem/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
CreateEmailRequestAttachment,
CreateEmailRequestHeader,
CreateEmailResponse,
CreateWebhookRequest,
Domain,
DomainLastStatus,
Email,
Expand Down Expand Up @@ -58,6 +59,7 @@
unmarshal_Statistics,
marshal_CreateDomainRequest,
marshal_CreateEmailRequest,
marshal_CreateWebhookRequest,
marshal_UpdateWebhookRequest,
)

Expand Down Expand Up @@ -755,6 +757,60 @@ def get_domain_last_status(
self._throw_on_error(res)
return unmarshal_DomainLastStatus(res.json())

def create_webhook(
self,
*,
domain_id: str,
name: str,
sns_arn: str,
region: Optional[Region] = None,
project_id: Optional[str] = None,
event_types: Optional[List[WebhookEventType]] = None,
) -> Webhook:
"""
Create a Webhook.
Create a new Webhook triggered by a list of event types and pushed to a Scaleway SNS ARN.
:param domain_id: ID of the Domain to watch for triggering events.
:param name: Name of the Webhook.
:param sns_arn: Scaleway SNS ARN topic to push the events to.
:param region: Region to target. If none is passed will use default region from the config.
:param project_id: ID of the project to which the Webhook belongs.
:param event_types: List of event types that will trigger an event.
:return: :class:`Webhook <Webhook>`

Usage:
::

result = api.create_webhook(
domain_id="example",
name="example",
sns_arn="example",
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)

res = self._request(
"POST",
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks",
body=marshal_CreateWebhookRequest(
CreateWebhookRequest(
domain_id=domain_id,
name=name,
sns_arn=sns_arn,
region=region,
project_id=project_id,
event_types=event_types,
),
self.client,
),
)

self._throw_on_error(res)
return unmarshal_Webhook(res.json())

def list_webhooks(
self,
*,
Expand Down Expand Up @@ -845,6 +901,39 @@ def list_webhooks_all(
},
)

def get_webhook(
self,
*,
webhook_id: str,
region: Optional[Region] = None,
) -> Webhook:
"""
Get information about a Webhook.
:param webhook_id: ID of the Webhook to check.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Webhook <Webhook>`

Usage:
::

result = api.get_webhook(
webhook_id="example",
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)
param_webhook_id = validate_path_param("webhook_id", webhook_id)

res = self._request(
"GET",
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks/{param_webhook_id}",
)

self._throw_on_error(res)
return unmarshal_Webhook(res.json())

def update_webhook(
self,
*,
Expand Down
Loading