Skip to content

Commit 13c4f93

Browse files
authored
feat(tem): read update delete webhook(s) (#536)
1 parent 4d589d7 commit 13c4f93

File tree

8 files changed

+1454
-0
lines changed

8 files changed

+1454
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
from .types import EmailStatus
1010
from .content import EMAIL_TRANSIENT_STATUSES
1111
from .types import ListEmailsRequestOrderBy
12+
from .types import ListWebhookEventsRequestOrderBy
13+
from .types import ListWebhooksRequestOrderBy
14+
from .types import WebhookEventStatus
15+
from .types import WebhookEventType
1216
from .types import DomainRecordsDMARC
1317
from .types import EmailTry
1418
from .types import DomainRecords
@@ -22,11 +26,14 @@
2226
from .types import DomainLastStatusDmarcRecord
2327
from .types import DomainLastStatusSpfRecord
2428
from .types import Domain
29+
from .types import WebhookEvent
30+
from .types import Webhook
2531
from .types import CancelEmailRequest
2632
from .types import CheckDomainRequest
2733
from .types import CreateDomainRequest
2834
from .types import CreateEmailRequest
2935
from .types import CreateEmailResponse
36+
from .types import DeleteWebhookRequest
3037
from .types import DomainLastStatus
3138
from .types import GetDomainLastStatusRequest
3239
from .types import GetDomainRequest
@@ -36,8 +43,13 @@
3643
from .types import ListDomainsResponse
3744
from .types import ListEmailsRequest
3845
from .types import ListEmailsResponse
46+
from .types import ListWebhookEventsRequest
47+
from .types import ListWebhookEventsResponse
48+
from .types import ListWebhooksRequest
49+
from .types import ListWebhooksResponse
3950
from .types import RevokeDomainRequest
4051
from .types import Statistics
52+
from .types import UpdateWebhookRequest
4153
from .api import TemV1Alpha1API
4254

4355
__all__ = [
@@ -50,6 +62,10 @@
5062
"EmailStatus",
5163
"EMAIL_TRANSIENT_STATUSES",
5264
"ListEmailsRequestOrderBy",
65+
"ListWebhookEventsRequestOrderBy",
66+
"ListWebhooksRequestOrderBy",
67+
"WebhookEventStatus",
68+
"WebhookEventType",
5369
"DomainRecordsDMARC",
5470
"EmailTry",
5571
"DomainRecords",
@@ -63,11 +79,14 @@
6379
"DomainLastStatusDmarcRecord",
6480
"DomainLastStatusSpfRecord",
6581
"Domain",
82+
"WebhookEvent",
83+
"Webhook",
6684
"CancelEmailRequest",
6785
"CheckDomainRequest",
6886
"CreateDomainRequest",
6987
"CreateEmailRequest",
7088
"CreateEmailResponse",
89+
"DeleteWebhookRequest",
7190
"DomainLastStatus",
7291
"GetDomainLastStatusRequest",
7392
"GetDomainRequest",
@@ -77,7 +96,12 @@
7796
"ListDomainsResponse",
7897
"ListEmailsRequest",
7998
"ListEmailsResponse",
99+
"ListWebhookEventsRequest",
100+
"ListWebhookEventsResponse",
101+
"ListWebhooksRequest",
102+
"ListWebhooksResponse",
80103
"RevokeDomainRequest",
81104
"Statistics",
105+
"UpdateWebhookRequest",
82106
"TemV1Alpha1API",
83107
]

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

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
EmailFlag,
2020
EmailStatus,
2121
ListEmailsRequestOrderBy,
22+
ListWebhookEventsRequestOrderBy,
23+
ListWebhooksRequestOrderBy,
24+
WebhookEventType,
2225
CreateDomainRequest,
2326
CreateEmailRequest,
2427
CreateEmailRequestAddress,
@@ -30,7 +33,12 @@
3033
Email,
3134
ListDomainsResponse,
3235
ListEmailsResponse,
36+
ListWebhookEventsResponse,
37+
ListWebhooksResponse,
3338
Statistics,
39+
UpdateWebhookRequest,
40+
Webhook,
41+
WebhookEvent,
3442
)
3543
from .content import (
3644
DOMAIN_TRANSIENT_STATUSES,
@@ -39,13 +47,17 @@
3947
from .marshalling import (
4048
unmarshal_Email,
4149
unmarshal_Domain,
50+
unmarshal_Webhook,
4251
unmarshal_CreateEmailResponse,
4352
unmarshal_DomainLastStatus,
4453
unmarshal_ListDomainsResponse,
4554
unmarshal_ListEmailsResponse,
55+
unmarshal_ListWebhookEventsResponse,
56+
unmarshal_ListWebhooksResponse,
4657
unmarshal_Statistics,
4758
marshal_CreateDomainRequest,
4859
marshal_CreateEmailRequest,
60+
marshal_UpdateWebhookRequest,
4961
)
5062

5163

@@ -740,3 +752,246 @@ async def get_domain_last_status(
740752

741753
self._throw_on_error(res)
742754
return unmarshal_DomainLastStatus(res.json())
755+
756+
async def list_webhooks(
757+
self,
758+
*,
759+
region: Optional[Region] = None,
760+
order_by: Optional[ListWebhooksRequestOrderBy] = None,
761+
page: Optional[int] = None,
762+
page_size: Optional[int] = None,
763+
project_id: Optional[str] = None,
764+
organization_id: Optional[str] = None,
765+
) -> ListWebhooksResponse:
766+
"""
767+
:param region: Region to target. If none is passed will use default region from the config.
768+
:param order_by: (Optional) List Webhooks corresponding to specific criteria.
769+
:param page: (Optional) Requested page number. Value must be greater or equal to 1.
770+
:param page_size: (Optional) Requested page size. Value must be between 1 and 100.
771+
:param project_id: (Optional) ID of the Project for which to list the Webhooks.
772+
:param organization_id: (Optional) ID of the Organization for which to list the Webhooks.
773+
:return: :class:`ListWebhooksResponse <ListWebhooksResponse>`
774+
775+
Usage:
776+
::
777+
778+
result = await api.list_webhooks()
779+
"""
780+
781+
param_region = validate_path_param(
782+
"region", region or self.client.default_region
783+
)
784+
785+
res = self._request(
786+
"GET",
787+
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks",
788+
params={
789+
"order_by": order_by,
790+
"organization_id": organization_id
791+
or self.client.default_organization_id,
792+
"page": page,
793+
"page_size": page_size or self.client.default_page_size,
794+
"project_id": project_id or self.client.default_project_id,
795+
},
796+
)
797+
798+
self._throw_on_error(res)
799+
return unmarshal_ListWebhooksResponse(res.json())
800+
801+
async def list_webhooks_all(
802+
self,
803+
*,
804+
region: Optional[Region] = None,
805+
order_by: Optional[ListWebhooksRequestOrderBy] = None,
806+
page: Optional[int] = None,
807+
page_size: Optional[int] = None,
808+
project_id: Optional[str] = None,
809+
organization_id: Optional[str] = None,
810+
) -> List[Webhook]:
811+
"""
812+
:param region: Region to target. If none is passed will use default region from the config.
813+
:param order_by: (Optional) List Webhooks corresponding to specific criteria.
814+
:param page: (Optional) Requested page number. Value must be greater or equal to 1.
815+
:param page_size: (Optional) Requested page size. Value must be between 1 and 100.
816+
:param project_id: (Optional) ID of the Project for which to list the Webhooks.
817+
:param organization_id: (Optional) ID of the Organization for which to list the Webhooks.
818+
:return: :class:`List[Webhook] <List[Webhook]>`
819+
820+
Usage:
821+
::
822+
823+
result = await api.list_webhooks_all()
824+
"""
825+
826+
return await fetch_all_pages_async(
827+
type=ListWebhooksResponse,
828+
key="webhooks",
829+
fetcher=self.list_webhooks,
830+
args={
831+
"region": region,
832+
"order_by": order_by,
833+
"page": page,
834+
"page_size": page_size,
835+
"project_id": project_id,
836+
"organization_id": organization_id,
837+
},
838+
)
839+
840+
async def update_webhook(
841+
self,
842+
*,
843+
webhook_id: str,
844+
region: Optional[Region] = None,
845+
name: Optional[str] = None,
846+
event_types: Optional[List[WebhookEventType]] = None,
847+
sns_arn: Optional[str] = None,
848+
) -> Webhook:
849+
"""
850+
:param webhook_id: ID of the Webhook to update.
851+
:param region: Region to target. If none is passed will use default region from the config.
852+
:param name: Name of the Webhook to update.
853+
:param event_types: List of event types to update.
854+
:param sns_arn: Scaleway SNS ARN topic to update.
855+
:return: :class:`Webhook <Webhook>`
856+
857+
Usage:
858+
::
859+
860+
result = await api.update_webhook(
861+
webhook_id="example",
862+
)
863+
"""
864+
865+
param_region = validate_path_param(
866+
"region", region or self.client.default_region
867+
)
868+
param_webhook_id = validate_path_param("webhook_id", webhook_id)
869+
870+
res = self._request(
871+
"PATCH",
872+
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks/{param_webhook_id}",
873+
body=marshal_UpdateWebhookRequest(
874+
UpdateWebhookRequest(
875+
webhook_id=webhook_id,
876+
region=region,
877+
name=name,
878+
event_types=event_types,
879+
sns_arn=sns_arn,
880+
),
881+
self.client,
882+
),
883+
)
884+
885+
self._throw_on_error(res)
886+
return unmarshal_Webhook(res.json())
887+
888+
async def delete_webhook(
889+
self,
890+
*,
891+
webhook_id: str,
892+
region: Optional[Region] = None,
893+
) -> None:
894+
"""
895+
:param webhook_id: ID of the Webhook to delete.
896+
:param region: Region to target. If none is passed will use default region from the config.
897+
898+
Usage:
899+
::
900+
901+
result = await api.delete_webhook(
902+
webhook_id="example",
903+
)
904+
"""
905+
906+
param_region = validate_path_param(
907+
"region", region or self.client.default_region
908+
)
909+
param_webhook_id = validate_path_param("webhook_id", webhook_id)
910+
911+
res = self._request(
912+
"DELETE",
913+
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks/{param_webhook_id}",
914+
)
915+
916+
self._throw_on_error(res)
917+
918+
async def list_webhook_events(
919+
self,
920+
*,
921+
webhook_id: str,
922+
region: Optional[Region] = None,
923+
order_by: Optional[ListWebhookEventsRequestOrderBy] = None,
924+
page: Optional[int] = None,
925+
page_size: Optional[int] = None,
926+
) -> ListWebhookEventsResponse:
927+
"""
928+
:param webhook_id: ID of the Webhook linked to the events.
929+
:param region: Region to target. If none is passed will use default region from the config.
930+
:param order_by: (Optional) List Webhook events corresponding to specific criteria.
931+
:param page: Requested page number. Value must be greater or equal to 1.
932+
:param page_size: Requested page size. Value must be between 1 and 100.
933+
:return: :class:`ListWebhookEventsResponse <ListWebhookEventsResponse>`
934+
935+
Usage:
936+
::
937+
938+
result = await api.list_webhook_events(
939+
webhook_id="example",
940+
)
941+
"""
942+
943+
param_region = validate_path_param(
944+
"region", region or self.client.default_region
945+
)
946+
param_webhook_id = validate_path_param("webhook_id", webhook_id)
947+
948+
res = self._request(
949+
"GET",
950+
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks/{param_webhook_id}/events",
951+
params={
952+
"order_by": order_by,
953+
"page": page,
954+
"page_size": page_size or self.client.default_page_size,
955+
},
956+
)
957+
958+
self._throw_on_error(res)
959+
return unmarshal_ListWebhookEventsResponse(res.json())
960+
961+
async def list_webhook_events_all(
962+
self,
963+
*,
964+
webhook_id: str,
965+
region: Optional[Region] = None,
966+
order_by: Optional[ListWebhookEventsRequestOrderBy] = None,
967+
page: Optional[int] = None,
968+
page_size: Optional[int] = None,
969+
) -> List[WebhookEvent]:
970+
"""
971+
:param webhook_id: ID of the Webhook linked to the events.
972+
:param region: Region to target. If none is passed will use default region from the config.
973+
:param order_by: (Optional) List Webhook events corresponding to specific criteria.
974+
:param page: Requested page number. Value must be greater or equal to 1.
975+
:param page_size: Requested page size. Value must be between 1 and 100.
976+
:return: :class:`List[WebhookEvent] <List[WebhookEvent]>`
977+
978+
Usage:
979+
::
980+
981+
result = await api.list_webhook_events_all(
982+
webhook_id="example",
983+
)
984+
"""
985+
986+
return await fetch_all_pages_async(
987+
type=ListWebhookEventsResponse,
988+
key="webhook_events",
989+
fetcher=self.list_webhook_events,
990+
args={
991+
"webhook_id": webhook_id,
992+
"region": region,
993+
"order_by": order_by,
994+
"page": page,
995+
"page_size": page_size,
996+
},
997+
)

0 commit comments

Comments
 (0)