Skip to content

Commit 668d80e

Browse files
authored
docs(tem): add info about webhooks (#604)
1 parent 71d55bc commit 668d80e

File tree

8 files changed

+328
-0
lines changed

8 files changed

+328
-0
lines changed

scaleway-async/scaleway_async/tem/v1alpha1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@
3333
from .types import CreateDomainRequest
3434
from .types import CreateEmailRequest
3535
from .types import CreateEmailResponse
36+
from .types import CreateWebhookRequest
3637
from .types import DeleteWebhookRequest
3738
from .types import DomainLastStatus
3839
from .types import GetDomainLastStatusRequest
3940
from .types import GetDomainRequest
4041
from .types import GetEmailRequest
4142
from .types import GetStatisticsRequest
43+
from .types import GetWebhookRequest
4244
from .types import ListDomainsRequest
4345
from .types import ListDomainsResponse
4446
from .types import ListEmailsRequest
@@ -86,12 +88,14 @@
8688
"CreateDomainRequest",
8789
"CreateEmailRequest",
8890
"CreateEmailResponse",
91+
"CreateWebhookRequest",
8992
"DeleteWebhookRequest",
9093
"DomainLastStatus",
9194
"GetDomainLastStatusRequest",
9295
"GetDomainRequest",
9396
"GetEmailRequest",
9497
"GetStatisticsRequest",
98+
"GetWebhookRequest",
9599
"ListDomainsRequest",
96100
"ListDomainsResponse",
97101
"ListEmailsRequest",

scaleway-async/scaleway_async/tem/v1alpha1/api.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
CreateEmailRequestAttachment,
3030
CreateEmailRequestHeader,
3131
CreateEmailResponse,
32+
CreateWebhookRequest,
3233
Domain,
3334
DomainLastStatus,
3435
Email,
@@ -58,6 +59,7 @@
5859
unmarshal_Statistics,
5960
marshal_CreateDomainRequest,
6061
marshal_CreateEmailRequest,
62+
marshal_CreateWebhookRequest,
6163
marshal_UpdateWebhookRequest,
6264
)
6365

@@ -755,6 +757,60 @@ async def get_domain_last_status(
755757
self._throw_on_error(res)
756758
return unmarshal_DomainLastStatus(res.json())
757759

760+
async def create_webhook(
761+
self,
762+
*,
763+
domain_id: str,
764+
name: str,
765+
sns_arn: str,
766+
region: Optional[Region] = None,
767+
project_id: Optional[str] = None,
768+
event_types: Optional[List[WebhookEventType]] = None,
769+
) -> Webhook:
770+
"""
771+
Create a Webhook.
772+
Create a new Webhook triggered by a list of event types and pushed to a Scaleway SNS ARN.
773+
:param domain_id: ID of the Domain to watch for triggering events.
774+
:param name: Name of the Webhook.
775+
:param sns_arn: Scaleway SNS ARN topic to push the events to.
776+
:param region: Region to target. If none is passed will use default region from the config.
777+
:param project_id: ID of the project to which the Webhook belongs.
778+
:param event_types: List of event types that will trigger an event.
779+
:return: :class:`Webhook <Webhook>`
780+
781+
Usage:
782+
::
783+
784+
result = await api.create_webhook(
785+
domain_id="example",
786+
name="example",
787+
sns_arn="example",
788+
)
789+
"""
790+
791+
param_region = validate_path_param(
792+
"region", region or self.client.default_region
793+
)
794+
795+
res = self._request(
796+
"POST",
797+
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks",
798+
body=marshal_CreateWebhookRequest(
799+
CreateWebhookRequest(
800+
domain_id=domain_id,
801+
name=name,
802+
sns_arn=sns_arn,
803+
region=region,
804+
project_id=project_id,
805+
event_types=event_types,
806+
),
807+
self.client,
808+
),
809+
)
810+
811+
self._throw_on_error(res)
812+
return unmarshal_Webhook(res.json())
813+
758814
async def list_webhooks(
759815
self,
760816
*,
@@ -845,6 +901,39 @@ async def list_webhooks_all(
845901
},
846902
)
847903

904+
async def get_webhook(
905+
self,
906+
*,
907+
webhook_id: str,
908+
region: Optional[Region] = None,
909+
) -> Webhook:
910+
"""
911+
Get information about a Webhook.
912+
:param webhook_id: ID of the Webhook to check.
913+
:param region: Region to target. If none is passed will use default region from the config.
914+
:return: :class:`Webhook <Webhook>`
915+
916+
Usage:
917+
::
918+
919+
result = await api.get_webhook(
920+
webhook_id="example",
921+
)
922+
"""
923+
924+
param_region = validate_path_param(
925+
"region", region or self.client.default_region
926+
)
927+
param_webhook_id = validate_path_param("webhook_id", webhook_id)
928+
929+
res = self._request(
930+
"GET",
931+
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks/{param_webhook_id}",
932+
)
933+
934+
self._throw_on_error(res)
935+
return unmarshal_Webhook(res.json())
936+
848937
async def update_webhook(
849938
self,
850939
*,

scaleway-async/scaleway_async/tem/v1alpha1/marshalling.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
CreateEmailRequestAttachment,
3333
CreateEmailRequestHeader,
3434
CreateEmailRequest,
35+
CreateWebhookRequest,
3536
UpdateWebhookRequest,
3637
)
3738

@@ -837,6 +838,30 @@ def marshal_CreateEmailRequest(
837838
return output
838839

839840

841+
def marshal_CreateWebhookRequest(
842+
request: CreateWebhookRequest,
843+
defaults: ProfileDefaults,
844+
) -> Dict[str, Any]:
845+
output: Dict[str, Any] = {}
846+
847+
if request.domain_id is not None:
848+
output["domain_id"] = request.domain_id
849+
850+
if request.name is not None:
851+
output["name"] = request.name
852+
853+
if request.sns_arn is not None:
854+
output["sns_arn"] = request.sns_arn
855+
856+
if request.project_id is not None:
857+
output["project_id"] = request.project_id or defaults.default_project_id
858+
859+
if request.event_types is not None:
860+
output["event_types"] = [str(item) for item in request.event_types]
861+
862+
return output
863+
864+
840865
def marshal_UpdateWebhookRequest(
841866
request: UpdateWebhookRequest,
842867
defaults: ProfileDefaults,

scaleway-async/scaleway_async/tem/v1alpha1/types.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,39 @@ class CreateEmailResponse:
710710
"""
711711

712712

713+
@dataclass
714+
class CreateWebhookRequest:
715+
domain_id: str
716+
"""
717+
ID of the Domain to watch for triggering events.
718+
"""
719+
720+
name: str
721+
"""
722+
Name of the Webhook.
723+
"""
724+
725+
sns_arn: str
726+
"""
727+
Scaleway SNS ARN topic to push the events to.
728+
"""
729+
730+
region: Optional[Region]
731+
"""
732+
Region to target. If none is passed will use default region from the config.
733+
"""
734+
735+
project_id: Optional[str]
736+
"""
737+
ID of the project to which the Webhook belongs.
738+
"""
739+
740+
event_types: Optional[List[WebhookEventType]]
741+
"""
742+
List of event types that will trigger an event.
743+
"""
744+
745+
713746
@dataclass
714747
class DeleteWebhookRequest:
715748
webhook_id: str
@@ -823,6 +856,19 @@ class GetStatisticsRequest:
823856
"""
824857

825858

859+
@dataclass
860+
class GetWebhookRequest:
861+
webhook_id: str
862+
"""
863+
ID of the Webhook to check.
864+
"""
865+
866+
region: Optional[Region]
867+
"""
868+
Region to target. If none is passed will use default region from the config.
869+
"""
870+
871+
826872
@dataclass
827873
class ListDomainsRequest:
828874
region: Optional[Region]

scaleway/scaleway/tem/v1alpha1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@
3333
from .types import CreateDomainRequest
3434
from .types import CreateEmailRequest
3535
from .types import CreateEmailResponse
36+
from .types import CreateWebhookRequest
3637
from .types import DeleteWebhookRequest
3738
from .types import DomainLastStatus
3839
from .types import GetDomainLastStatusRequest
3940
from .types import GetDomainRequest
4041
from .types import GetEmailRequest
4142
from .types import GetStatisticsRequest
43+
from .types import GetWebhookRequest
4244
from .types import ListDomainsRequest
4345
from .types import ListDomainsResponse
4446
from .types import ListEmailsRequest
@@ -86,12 +88,14 @@
8688
"CreateDomainRequest",
8789
"CreateEmailRequest",
8890
"CreateEmailResponse",
91+
"CreateWebhookRequest",
8992
"DeleteWebhookRequest",
9093
"DomainLastStatus",
9194
"GetDomainLastStatusRequest",
9295
"GetDomainRequest",
9396
"GetEmailRequest",
9497
"GetStatisticsRequest",
98+
"GetWebhookRequest",
9599
"ListDomainsRequest",
96100
"ListDomainsResponse",
97101
"ListEmailsRequest",

scaleway/scaleway/tem/v1alpha1/api.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
CreateEmailRequestAttachment,
3030
CreateEmailRequestHeader,
3131
CreateEmailResponse,
32+
CreateWebhookRequest,
3233
Domain,
3334
DomainLastStatus,
3435
Email,
@@ -58,6 +59,7 @@
5859
unmarshal_Statistics,
5960
marshal_CreateDomainRequest,
6061
marshal_CreateEmailRequest,
62+
marshal_CreateWebhookRequest,
6163
marshal_UpdateWebhookRequest,
6264
)
6365

@@ -755,6 +757,60 @@ def get_domain_last_status(
755757
self._throw_on_error(res)
756758
return unmarshal_DomainLastStatus(res.json())
757759

760+
def create_webhook(
761+
self,
762+
*,
763+
domain_id: str,
764+
name: str,
765+
sns_arn: str,
766+
region: Optional[Region] = None,
767+
project_id: Optional[str] = None,
768+
event_types: Optional[List[WebhookEventType]] = None,
769+
) -> Webhook:
770+
"""
771+
Create a Webhook.
772+
Create a new Webhook triggered by a list of event types and pushed to a Scaleway SNS ARN.
773+
:param domain_id: ID of the Domain to watch for triggering events.
774+
:param name: Name of the Webhook.
775+
:param sns_arn: Scaleway SNS ARN topic to push the events to.
776+
:param region: Region to target. If none is passed will use default region from the config.
777+
:param project_id: ID of the project to which the Webhook belongs.
778+
:param event_types: List of event types that will trigger an event.
779+
:return: :class:`Webhook <Webhook>`
780+
781+
Usage:
782+
::
783+
784+
result = api.create_webhook(
785+
domain_id="example",
786+
name="example",
787+
sns_arn="example",
788+
)
789+
"""
790+
791+
param_region = validate_path_param(
792+
"region", region or self.client.default_region
793+
)
794+
795+
res = self._request(
796+
"POST",
797+
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks",
798+
body=marshal_CreateWebhookRequest(
799+
CreateWebhookRequest(
800+
domain_id=domain_id,
801+
name=name,
802+
sns_arn=sns_arn,
803+
region=region,
804+
project_id=project_id,
805+
event_types=event_types,
806+
),
807+
self.client,
808+
),
809+
)
810+
811+
self._throw_on_error(res)
812+
return unmarshal_Webhook(res.json())
813+
758814
def list_webhooks(
759815
self,
760816
*,
@@ -845,6 +901,39 @@ def list_webhooks_all(
845901
},
846902
)
847903

904+
def get_webhook(
905+
self,
906+
*,
907+
webhook_id: str,
908+
region: Optional[Region] = None,
909+
) -> Webhook:
910+
"""
911+
Get information about a Webhook.
912+
:param webhook_id: ID of the Webhook to check.
913+
:param region: Region to target. If none is passed will use default region from the config.
914+
:return: :class:`Webhook <Webhook>`
915+
916+
Usage:
917+
::
918+
919+
result = api.get_webhook(
920+
webhook_id="example",
921+
)
922+
"""
923+
924+
param_region = validate_path_param(
925+
"region", region or self.client.default_region
926+
)
927+
param_webhook_id = validate_path_param("webhook_id", webhook_id)
928+
929+
res = self._request(
930+
"GET",
931+
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks/{param_webhook_id}",
932+
)
933+
934+
self._throw_on_error(res)
935+
return unmarshal_Webhook(res.json())
936+
848937
def update_webhook(
849938
self,
850939
*,

0 commit comments

Comments
 (0)