Skip to content

Commit afb488b

Browse files
authored
feat: adds domain endpoints (#16)
* feat: adds domain endpoints * docs: contact api indication * tests: add test cases for new endpoints * chore: remove print
1 parent 575741c commit afb488b

18 files changed

Lines changed: 548 additions & 7 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ docs/_build
137137
.venv/
138138
venv
139139

140+
test-results/
141+
main.py
142+
140143
# Include tracked hidden files and directories in search and diff tools
141144
!.commitlintrc.json
142145
!.dockerignore

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,18 @@ Currently, we support the following endpoints for the following services:
151151
* [x] delete_zone 100%
152152
* [ ] jobs_find 50% - missing official documentation, functionality cannot be guaranteed
153153
* [x] update_zone 100%
154+
* [x] get_default_nameserver 100%
155+
* Domain
156+
* [x] list_domains 100%
157+
* [x] register_domain 100%
158+
* [x] jobs_find 100%
159+
* [x] list_contacts 100%
160+
* [ ] create_contact 0%
161+
* [ ] update_contact 0%
154162
* Account
155163
* [ ] list_accounts 50% - missing official documentation, functionality cannot be guaranteed
156-
164+
* [ ] get_own_account 50% - missing official documentation, functionality only implemented as far as required
165+
157166
We plan to add more endpoints in the future, for example for SSL and Domain services.
158167

159168
The implemented endpoints do not contain any logic to catch asynchronous behaviour yet. We plan to add a `sync: bool`

hostingde/account/account.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,12 @@ def list_subaccounts_names(
4545
uri = self._build_uri('account', 'subaccountsFind')
4646

4747
return self._iter(uri, Account, filter, limit, sort)
48+
49+
def get_own_account(self, **kwargs):
50+
uri = self._build_uri('account', 'getOwnAccount')
51+
52+
response = self._request(uri)
53+
54+
data = response.json().get('response', {})
55+
56+
return self._instance(Account, data)

hostingde/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from hostingde.account.account import AccountClient
22
from hostingde.dns.dns import DnsClient
3+
from hostingde.domain.domain import DomainClient
34
from hostingde.hostingde import HostingDeCore
45

56

@@ -13,4 +14,5 @@ class HostingDeClient(HostingDeCore):
1314
def __init__(self):
1415
super().__init__()
1516
self.dns: DnsClient = DnsClient(self)
17+
self.domain: DomainClient = DomainClient(self)
1618
self.account: AccountClient = AccountClient(self)

hostingde/dns/dns.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ def build_uri(self, method: str) -> str:
3333
"""
3434
return self._build_uri('dns', method)
3535

36+
def get_default_nameserver(self) -> List[str]:
37+
uri = self.build_uri('nameserverSetGetDefault')
38+
39+
response = self._request(uri)
40+
41+
data = response.json().get('response', {})
42+
43+
return data.get('nameservers', [])
44+
3645
def list_zones(
3746
self,
3847
limit: Optional[int] = None,

hostingde/domain/__init__.py

Whitespace-only changes.

hostingde/domain/domain.py

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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

hostingde/domain/requests/__init__.py

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from dataclasses import dataclass
2+
3+
from hostingde.model import Model
4+
from hostingde.model.domain import Domain
5+
6+
7+
@dataclass
8+
class RegisterDomainRequest(Model):
9+
domain: Domain

hostingde/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ def __str__(self) -> str:
1313

1414
class ClientException(Exception):
1515
pass
16+
17+
18+
class ContextConditionException(Exception):
19+
pass

0 commit comments

Comments
 (0)