|
| 1 | +from typing import Optional, List |
| 2 | + |
| 3 | +from hostingde.domain.requests.register_domain import RegisterDomainRequest |
| 4 | +from hostingde.paginator import HostingDePaginator |
| 5 | +from hostingde.hostingde import HostingDeCore |
| 6 | +from hostingde.job_waiter import AsynchronousClient, JobWaiter |
| 7 | +from hostingde.model.domain import Domain, Nameserver, DomainContactRef |
| 8 | +from hostingde.model.filter import FilterElement |
| 9 | +from hostingde.model.job import Job |
| 10 | +from hostingde.model.sort import SortConfiguration |
| 11 | + |
| 12 | + |
| 13 | +class DomainClient(HostingDeCore, AsynchronousClient): |
| 14 | + |
| 15 | + def __init__(self, parent: HostingDeCore): |
| 16 | + """ |
| 17 | + Construct a new client |
| 18 | +
|
| 19 | + :param parent: The parent to retrieve the session from |
| 20 | + """ |
| 21 | + super().__init__(parent) |
| 22 | + |
| 23 | + def build_uri(self, method: str) -> str: |
| 24 | + """ |
| 25 | + Utility method to easily construct URLs for this service. |
| 26 | +
|
| 27 | + :param method: The method within this service |
| 28 | + :return: The URL string |
| 29 | + """ |
| 30 | + return self._build_uri('domain', method) |
| 31 | + |
| 32 | + def jobs_find( |
| 33 | + self, |
| 34 | + limit: Optional[int] = None, |
| 35 | + filter: Optional[FilterElement] = None, |
| 36 | + sort: Optional[SortConfiguration] = None, |
| 37 | + *args: list, |
| 38 | + **kwargs: dict |
| 39 | + ) -> HostingDePaginator[Job]: |
| 40 | + """ |
| 41 | + Retrieves a list of Job objects from the generic filtering and sorting API. |
| 42 | +
|
| 43 | + :param limit: The limit of objects to retrieve per call. If not set, defaults to 25. |
| 44 | + :param filter: A filter that is applied to the query |
| 45 | + :param sort: Configuration how results are sorted. |
| 46 | + :return: An iterator that yields ZoneConfig objects. |
| 47 | + """ |
| 48 | + uri = self._build_uri('domain', 'jobsFind') |
| 49 | + |
| 50 | + return self._iter(uri, Job, filter, limit, sort) |
| 51 | + |
| 52 | + def list_domains( |
| 53 | + self, |
| 54 | + limit: Optional[int] = None, |
| 55 | + filter: Optional[FilterElement] = None, |
| 56 | + sort: Optional[SortConfiguration] = None, |
| 57 | + *args: list, |
| 58 | + **kwargs: dict |
| 59 | + ) -> HostingDePaginator[Domain]: |
| 60 | + """ |
| 61 | + Retrieves a list of Domain objects from the generic filtering and sorting API. |
| 62 | +
|
| 63 | + :param limit: The limit of objects to retrieve per call. If not set, defaults to 25. |
| 64 | + :param filter: A filter that is applied to the query |
| 65 | + :param sort: Configuration how results are sorted. |
| 66 | + :return: An iterator that yields Zone objects. |
| 67 | + """ |
| 68 | + |
| 69 | + uri = self._build_uri('domain', 'domainsFind') |
| 70 | + |
| 71 | + return self._iter(uri, Domain, filter, limit, sort) |
| 72 | + |
| 73 | + def list_contacts( |
| 74 | + self, |
| 75 | + limit: Optional[int] = None, |
| 76 | + filter: Optional[FilterElement] = None, |
| 77 | + sort: Optional[SortConfiguration] = None, |
| 78 | + *args: list, |
| 79 | + **kwargs: dict |
| 80 | + ) -> HostingDePaginator[Domain]: |
| 81 | + """ |
| 82 | + Retrieves a list of Domain objects from the generic filtering and sorting API. |
| 83 | +
|
| 84 | + :param limit: The limit of objects to retrieve per call. If not set, defaults to 25. |
| 85 | + :param filter: A filter that is applied to the query |
| 86 | + :param sort: Configuration how results are sorted. |
| 87 | + :return: An iterator that yields Zone objects. |
| 88 | + """ |
| 89 | + |
| 90 | + uri = self._build_uri('domain', 'contactsFind') |
| 91 | + |
| 92 | + return self._iter(uri, Domain, filter, limit, sort) |
| 93 | + |
| 94 | + def register_domain( |
| 95 | + self, |
| 96 | + name: str, |
| 97 | + contacts: List[DomainContactRef], |
| 98 | + nameservers: List[Nameserver], |
| 99 | + transfer_lock_enabled=True, |
| 100 | + asynchronous: Optional[bool] = None, |
| 101 | + ) -> Domain: |
| 102 | + """ |
| 103 | + In order to create a domain, you need to send a domainCreate request. This request takes one parameter domain |
| 104 | + which contains all required information of a domain object. |
| 105 | +
|
| 106 | + :param name: |
| 107 | + :param contacts: |
| 108 | + :param nameservers: |
| 109 | + :param transfer_lock_enabled: |
| 110 | + :param asynchronous: |
| 111 | + :return: |
| 112 | + """ |
| 113 | + url = self.build_uri('domainCreate') |
| 114 | + |
| 115 | + response = self._request( |
| 116 | + url, |
| 117 | + RegisterDomainRequest( |
| 118 | + domain=Domain( |
| 119 | + name=name, |
| 120 | + contacts=contacts, |
| 121 | + nameservers=nameservers, |
| 122 | + transfer_lock_enabled=transfer_lock_enabled |
| 123 | + ) |
| 124 | + ), |
| 125 | + ) |
| 126 | + |
| 127 | + domain: Domain = self._instance(Domain, response.json().get('response', {})) |
| 128 | + |
| 129 | + if not asynchronous and domain.id is not None: |
| 130 | + JobWaiter(self, domain.id, 'domainCreate').wait() |
| 131 | + |
| 132 | + return domain |
0 commit comments