Skip to content

Commit c8bd434

Browse files
authored
feat(webhosting): add first version of the classic mail api (#623)
1 parent df4f9aa commit c8bd434

File tree

8 files changed

+1082
-1
lines changed

8 files changed

+1082
-1
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,22 @@
1212
from .types import OfferQuotaWarning
1313
from .types import HostingCpanelUrls
1414
from .types import HostingOption
15+
from .types import EmailAddress
1516
from .types import OfferProduct
1617
from .types import CreateHostingRequestDomainConfiguration
1718
from .types import DnsRecord
1819
from .types import Nameserver
1920
from .types import ControlPanel
2021
from .types import Hosting
22+
from .types import Mailbox
2123
from .types import Offer
2224
from .types import CheckUserOwnsDomainRequest
2325
from .types import CheckUserOwnsDomainResponse
26+
from .types import ClassicMailApiCreateMailboxRequest
27+
from .types import ClassicMailApiDeleteMailboxRequest
28+
from .types import ClassicMailApiGetMailboxRequest
29+
from .types import ClassicMailApiListMailboxesRequest
30+
from .types import ClassicMailApiUpdateMailboxRequest
2431
from .types import CreateHostingRequest
2532
from .types import CreateSessionRequest
2633
from .types import DeleteHostingRequest
@@ -31,6 +38,7 @@
3138
from .types import ListControlPanelsResponse
3239
from .types import ListHostingsRequest
3340
from .types import ListHostingsResponse
41+
from .types import ListMailboxesResponse
3442
from .types import ListOffersRequest
3543
from .types import ListOffersResponse
3644
from .types import ResetHostingPasswordRequest
@@ -39,6 +47,7 @@
3947
from .types import Session
4048
from .types import UpdateHostingRequest
4149
from .api import WebhostingV1Alpha1API
50+
from .api import WebhostingV1Alpha1ClassicMailAPI
4251

4352
__all__ = [
4453
"DnsRecordStatus",
@@ -53,15 +62,22 @@
5362
"OfferQuotaWarning",
5463
"HostingCpanelUrls",
5564
"HostingOption",
65+
"EmailAddress",
5666
"OfferProduct",
5767
"CreateHostingRequestDomainConfiguration",
5868
"DnsRecord",
5969
"Nameserver",
6070
"ControlPanel",
6171
"Hosting",
72+
"Mailbox",
6273
"Offer",
6374
"CheckUserOwnsDomainRequest",
6475
"CheckUserOwnsDomainResponse",
76+
"ClassicMailApiCreateMailboxRequest",
77+
"ClassicMailApiDeleteMailboxRequest",
78+
"ClassicMailApiGetMailboxRequest",
79+
"ClassicMailApiListMailboxesRequest",
80+
"ClassicMailApiUpdateMailboxRequest",
6581
"CreateHostingRequest",
6682
"CreateSessionRequest",
6783
"DeleteHostingRequest",
@@ -72,6 +88,7 @@
7288
"ListControlPanelsResponse",
7389
"ListHostingsRequest",
7490
"ListHostingsResponse",
91+
"ListMailboxesResponse",
7592
"ListOffersRequest",
7693
"ListOffersResponse",
7794
"ResetHostingPasswordRequest",
@@ -80,4 +97,5 @@
8097
"Session",
8198
"UpdateHostingRequest",
8299
"WebhostingV1Alpha1API",
100+
"WebhostingV1Alpha1ClassicMailAPI",
83101
]

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

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@
1919
ListOffersRequestOrderBy,
2020
CheckUserOwnsDomainRequest,
2121
CheckUserOwnsDomainResponse,
22+
ClassicMailApiCreateMailboxRequest,
23+
ClassicMailApiUpdateMailboxRequest,
2224
ControlPanel,
2325
CreateHostingRequest,
2426
CreateHostingRequestDomainConfiguration,
2527
DnsRecords,
28+
EmailAddress,
2629
Hosting,
2730
ListControlPanelsResponse,
2831
ListHostingsResponse,
32+
ListMailboxesResponse,
2933
ListOffersResponse,
34+
Mailbox,
3035
ResetHostingPasswordResponse,
3136
Session,
3237
UpdateHostingRequest,
@@ -36,14 +41,18 @@
3641
)
3742
from .marshalling import (
3843
unmarshal_Hosting,
44+
unmarshal_Mailbox,
3945
unmarshal_CheckUserOwnsDomainResponse,
4046
unmarshal_DnsRecords,
4147
unmarshal_ListControlPanelsResponse,
4248
unmarshal_ListHostingsResponse,
49+
unmarshal_ListMailboxesResponse,
4350
unmarshal_ListOffersResponse,
4451
unmarshal_ResetHostingPasswordResponse,
4552
unmarshal_Session,
4653
marshal_CheckUserOwnsDomainRequest,
54+
marshal_ClassicMailApiCreateMailboxRequest,
55+
marshal_ClassicMailApiUpdateMailboxRequest,
4756
marshal_CreateHostingRequest,
4857
marshal_UpdateHostingRequest,
4958
)
@@ -686,3 +695,260 @@ async def reset_hosting_password(
686695

687696
self._throw_on_error(res)
688697
return unmarshal_ResetHostingPasswordResponse(res.json())
698+
699+
700+
class WebhostingV1Alpha1ClassicMailAPI(API):
701+
"""
702+
This API allows you to manage your mailboxes for your Web Hosting services.
703+
"""
704+
705+
async def create_mailbox(
706+
self,
707+
*,
708+
online_id: int,
709+
password: str,
710+
region: Optional[Region] = None,
711+
email: Optional[EmailAddress] = None,
712+
) -> Mailbox:
713+
"""
714+
Create a new mailbox within your hosting plan.
715+
:param online_id: The Online hosting ID.
716+
:param password: Password for the new mailbox.
717+
:param region: Region to target. If none is passed will use default region from the config.
718+
:param email: The email address of the mailbox.
719+
:return: :class:`Mailbox <Mailbox>`
720+
721+
Usage:
722+
::
723+
724+
result = await api.create_mailbox(
725+
online_id=1,
726+
password="example",
727+
)
728+
"""
729+
730+
param_region = validate_path_param(
731+
"region", region or self.client.default_region
732+
)
733+
param_online_id = validate_path_param("online_id", online_id)
734+
735+
res = self._request(
736+
"POST",
737+
f"/webhosting/v1alpha1/regions/{param_region}/classic-hostings/{param_online_id}/mailboxes",
738+
body=marshal_ClassicMailApiCreateMailboxRequest(
739+
ClassicMailApiCreateMailboxRequest(
740+
online_id=online_id,
741+
password=password,
742+
region=region,
743+
email=email,
744+
),
745+
self.client,
746+
),
747+
)
748+
749+
self._throw_on_error(res)
750+
return unmarshal_Mailbox(res.json())
751+
752+
async def get_mailbox(
753+
self,
754+
*,
755+
online_id: int,
756+
mailbox_id: int,
757+
region: Optional[Region] = None,
758+
) -> Mailbox:
759+
"""
760+
Get a mailbox by id within your hosting plan.
761+
:param online_id: The Online hosting ID.
762+
:param mailbox_id: The ID of the mailbox to get.
763+
:param region: Region to target. If none is passed will use default region from the config.
764+
:return: :class:`Mailbox <Mailbox>`
765+
766+
Usage:
767+
::
768+
769+
result = await api.get_mailbox(
770+
online_id=1,
771+
mailbox_id=1,
772+
)
773+
"""
774+
775+
param_region = validate_path_param(
776+
"region", region or self.client.default_region
777+
)
778+
param_online_id = validate_path_param("online_id", online_id)
779+
param_mailbox_id = validate_path_param("mailbox_id", mailbox_id)
780+
781+
res = self._request(
782+
"GET",
783+
f"/webhosting/v1alpha1/regions/{param_region}/classic-hostings/{param_online_id}/mailboxes/{param_mailbox_id}",
784+
)
785+
786+
self._throw_on_error(res)
787+
return unmarshal_Mailbox(res.json())
788+
789+
async def list_mailboxes(
790+
self,
791+
*,
792+
online_id: int,
793+
region: Optional[Region] = None,
794+
page: Optional[int] = None,
795+
page_size: Optional[int] = None,
796+
domain: Optional[str] = None,
797+
) -> ListMailboxesResponse:
798+
"""
799+
List all mailboxes within your hosting plan.
800+
:param online_id: The Online hosting ID.
801+
:param region: Region to target. If none is passed will use default region from the config.
802+
:param page: Page number (must be a positive integer).
803+
:param page_size: Number of mailboxes to return (must be a positive integer lower or equal to 100).
804+
:param domain: Domain to filter the mailboxes.
805+
:return: :class:`ListMailboxesResponse <ListMailboxesResponse>`
806+
807+
Usage:
808+
::
809+
810+
result = await api.list_mailboxes(
811+
online_id=1,
812+
)
813+
"""
814+
815+
param_region = validate_path_param(
816+
"region", region or self.client.default_region
817+
)
818+
param_online_id = validate_path_param("online_id", online_id)
819+
820+
res = self._request(
821+
"GET",
822+
f"/webhosting/v1alpha1/regions/{param_region}/classic-hostings/{param_online_id}/mailboxes",
823+
params={
824+
"domain": domain,
825+
"page": page,
826+
"page_size": page_size or self.client.default_page_size,
827+
},
828+
)
829+
830+
self._throw_on_error(res)
831+
return unmarshal_ListMailboxesResponse(res.json())
832+
833+
async def list_mailboxes_all(
834+
self,
835+
*,
836+
online_id: int,
837+
region: Optional[Region] = None,
838+
page: Optional[int] = None,
839+
page_size: Optional[int] = None,
840+
domain: Optional[str] = None,
841+
) -> List[Mailbox]:
842+
"""
843+
List all mailboxes within your hosting plan.
844+
:param online_id: The Online hosting ID.
845+
:param region: Region to target. If none is passed will use default region from the config.
846+
:param page: Page number (must be a positive integer).
847+
:param page_size: Number of mailboxes to return (must be a positive integer lower or equal to 100).
848+
:param domain: Domain to filter the mailboxes.
849+
:return: :class:`List[Mailbox] <List[Mailbox]>`
850+
851+
Usage:
852+
::
853+
854+
result = await api.list_mailboxes_all(
855+
online_id=1,
856+
)
857+
"""
858+
859+
return await fetch_all_pages_async(
860+
type=ListMailboxesResponse,
861+
key="mailboxes",
862+
fetcher=self.list_mailboxes,
863+
args={
864+
"online_id": online_id,
865+
"region": region,
866+
"page": page,
867+
"page_size": page_size,
868+
"domain": domain,
869+
},
870+
)
871+
872+
async def delete_mailbox(
873+
self,
874+
*,
875+
online_id: int,
876+
mailbox_id: int,
877+
region: Optional[Region] = None,
878+
) -> Mailbox:
879+
"""
880+
:param online_id: The Online hosting ID.
881+
:param mailbox_id: The ID of the mailbox to delete.
882+
:param region: Region to target. If none is passed will use default region from the config.
883+
:return: :class:`Mailbox <Mailbox>`
884+
885+
Usage:
886+
::
887+
888+
result = await api.delete_mailbox(
889+
online_id=1,
890+
mailbox_id=1,
891+
)
892+
"""
893+
894+
param_region = validate_path_param(
895+
"region", region or self.client.default_region
896+
)
897+
param_online_id = validate_path_param("online_id", online_id)
898+
param_mailbox_id = validate_path_param("mailbox_id", mailbox_id)
899+
900+
res = self._request(
901+
"DELETE",
902+
f"/webhosting/v1alpha1/regions/{param_region}/classic-hostings/{param_online_id}/mailboxes/{param_mailbox_id}",
903+
)
904+
905+
self._throw_on_error(res)
906+
return unmarshal_Mailbox(res.json())
907+
908+
async def update_mailbox(
909+
self,
910+
*,
911+
online_id: int,
912+
mailbox_id: int,
913+
region: Optional[Region] = None,
914+
password: Optional[str] = None,
915+
) -> Mailbox:
916+
"""
917+
Update the mailbox within your hosting plan.
918+
:param online_id: The Online hosting ID.
919+
:param mailbox_id: The ID of the mailbox to update.
920+
:param region: Region to target. If none is passed will use default region from the config.
921+
:param password: New password for the mailbox.
922+
:return: :class:`Mailbox <Mailbox>`
923+
924+
Usage:
925+
::
926+
927+
result = await api.update_mailbox(
928+
online_id=1,
929+
mailbox_id=1,
930+
)
931+
"""
932+
933+
param_region = validate_path_param(
934+
"region", region or self.client.default_region
935+
)
936+
param_online_id = validate_path_param("online_id", online_id)
937+
param_mailbox_id = validate_path_param("mailbox_id", mailbox_id)
938+
939+
res = self._request(
940+
"PATCH",
941+
f"/webhosting/v1alpha1/regions/{param_region}/classic-hostings/{param_online_id}/mailboxes/{param_mailbox_id}",
942+
body=marshal_ClassicMailApiUpdateMailboxRequest(
943+
ClassicMailApiUpdateMailboxRequest(
944+
online_id=online_id,
945+
mailbox_id=mailbox_id,
946+
region=region,
947+
password=password,
948+
),
949+
self.client,
950+
),
951+
)
952+
953+
self._throw_on_error(res)
954+
return unmarshal_Mailbox(res.json())

0 commit comments

Comments
 (0)