Skip to content

Commit e9497c4

Browse files
Add support for domain research endpoint (#486)
1 parent 368cad1 commit e9497c4

6 files changed

Lines changed: 99 additions & 1 deletion

File tree

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@ domain_id = client.domains.list_domains(account_id).data[0].id
9292
domain = client.domains.get_domain(account_id, domain_id).data # The domain you are looking for
9393
```
9494

95+
### Research a domain
96+
97+
> **Note:** This endpoint is part of a Private Beta. During the beta period, changes to the endpoint may occur at any time. If interested in using this endpoint, reach out to [DNSimple support](support@dnsimple.com).
98+
99+
Research a domain name for availability and registration status information:
100+
101+
```python
102+
from dnsimple import Client
103+
104+
client = Client(access_token='a1b2c3')
105+
106+
account_id = client.identity.whoami().data.account.id
107+
response = client.domains.get_domain_research_status(account_id, 'example.com')
108+
research = response.data
109+
print(research.domain) # "example.com"
110+
print(research.availability) # "unavailable"
111+
print(research.request_id) # "f453dabc-a27e-4bf1-a93e-f263577ffaae"
112+
print(research.errors) # []
113+
```
114+
95115
## Configuration
96116

97117
### Sandbox Environment

dnsimple/service/domains.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
from dnsimple.response import Response
55
from dnsimple.struct import Domain, Dnssec, Collaborator, DelegationSignerRecord, EmailForward, DomainPush
6+
from dnsimple.service.domains_research import DomainsResearch
67

78

8-
class Domains(object):
9+
class Domains(DomainsResearch):
910
"""
1011
The Domains Service handles the domains endpoint of the DNSimple API.
1112
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import json
2+
import warnings
3+
4+
from dnsimple.response import Response
5+
from dnsimple.struct import DomainResearchStatus
6+
7+
8+
class DomainsResearch(object):
9+
"""
10+
The DomainsResearch Service handles the domain research endpoint of the DNSimple API.
11+
"""
12+
13+
def get_domain_research_status(self, account_id, domain):
14+
"""
15+
Research a domain name for availability and registration status information.
16+
17+
This endpoint provides information about a domain's availability status, including whether it's available for registration, already registered, or has other restrictions that prevent registration.
18+
19+
Note: This endpoint is part of a Private Beta. During the beta period, changes to the endpoint may occur at any time. If interested in using this endpoint, reach out to support@dnsimple.com.
20+
21+
See https://developer.dnsimple.com/v2/domains/research/#getDomainsResearchStatus
22+
23+
:param account_id: int
24+
The account ID
25+
:param domain: str
26+
The domain name to research
27+
28+
:return: dnsimple.Response
29+
The domain research result
30+
"""
31+
response = self.client.get(f'/{account_id}/domains/research/status', params={'domain': domain})
32+
return Response(response, DomainResearchStatus)

dnsimple/struct/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from dnsimple.struct.domain_price import DomainPrice
1313
from dnsimple.struct.domain_registration import DomainRegistration, DomainRegistrationRequest
1414
from dnsimple.struct.domain_renewal import DomainRenewal, DomainRenewRequest
15+
from dnsimple.struct.domain_research_status import DomainResearchStatus
1516
from dnsimple.struct.domain_restore import DomainRestore, DomainRestoreRequest
1617
from dnsimple.struct.domain_transfer import DomainTransfer, DomainTransferRequest
1718
from dnsimple.struct.domain_transfer_lock import DomainTransferLock
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from dataclasses import dataclass
2+
3+
from dnsimple.struct import Struct
4+
5+
6+
@dataclass
7+
class DomainResearchStatus(Struct):
8+
request_id = None
9+
"""UUID identifier for this research request"""
10+
domain = None
11+
"""The domain name that was researched"""
12+
availability = None
13+
"""The availability status. See https://developer.dnsimple.com/v2/domains/research/#getDomainsResearchStatus"""
14+
errors = None
15+
"""Array of error messages if the domain cannot be registered or researched"""
16+
17+
def __init__(self, data):
18+
super().__init__(data)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import unittest
2+
3+
import responses
4+
5+
from dnsimple.response import Response
6+
from dnsimple.struct import DomainResearchStatus
7+
from tests.helpers import DNSimpleTest, DNSimpleMockResponse
8+
9+
10+
class DomainsResearchTest(DNSimpleTest):
11+
@responses.activate
12+
def test_domain_research_status(self):
13+
responses.add(DNSimpleMockResponse(method=responses.GET,
14+
path='/1010/domains/research/status?domain=taken.com',
15+
fixture_name='getDomainsResearchStatus/success-unavailable'))
16+
research = self.domains.get_domain_research_status(1010, 'taken.com').data
17+
18+
self.assertIsInstance(research, DomainResearchStatus)
19+
self.assertEqual('25dd77cb-2f71-48b9-b6be-1dacd2881418', research.request_id)
20+
self.assertEqual('taken.com', research.domain)
21+
self.assertEqual('unavailable', research.availability)
22+
self.assertEqual([], research.errors)
23+
24+
25+
if __name__ == '__main__':
26+
unittest.main()

0 commit comments

Comments
 (0)