From 91f5495eea8eae7cb6c2088b50ec06531bb0c2b5 Mon Sep 17 00:00:00 2001 From: t-900-a Date: Tue, 18 Aug 2020 08:45:57 -0400 Subject: [PATCH 1/2] update_dns_settings() now using PUT request instead of POST https://github.com/namebasehq/api-documentation/blob/master/dns-settings-api.md A 404 is return with post, put has to be used as specified within the api docs. --- namebase_exchange/exchange.py | 2 +- namebase_exchange/utils.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/namebase_exchange/exchange.py b/namebase_exchange/exchange.py index 6d8c8c9..dd023e1 100644 --- a/namebase_exchange/exchange.py +++ b/namebase_exchange/exchange.py @@ -1176,4 +1176,4 @@ def update_dns_settings(self, domain: str, record_type: str = 'TXT', value: str "ttl": ttl } - return self.request.post(path=f'/dns/domains/{domain}', json_data=api_params) + return self.request.put(path=f'/dns/domains/{domain}', json_data=api_params) diff --git a/namebase_exchange/utils.py b/namebase_exchange/utils.py index 5a63133..076473b 100644 --- a/namebase_exchange/utils.py +++ b/namebase_exchange/utils.py @@ -51,3 +51,13 @@ def status(self): r = requests.get(url=self.url + "/info", headers=self.headers) r.raise_for_status() return r.json() + + def put(self, path, data=None, json_data=None, params=None): + """Perform PUT request""" + r = requests.put(url=self.url + path, data=data, json=json_data, params=params, timeout=self.timeout, + headers=self.headers) + try: + r.raise_for_status() + except requests.exceptions.HTTPError as e: + return json.loads(e.response.content) + return r.json() From 2dab80b116494b42cd9ecc741d84985486d066e4 Mon Sep 17 00:00:00 2001 From: t-900-a Date: Tue, 18 Aug 2020 09:10:38 -0400 Subject: [PATCH 2/2] update_dns_settings() parameters are now only the domain and a list of records Each record should contain the previous parameters --- namebase_exchange/exchange.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/namebase_exchange/exchange.py b/namebase_exchange/exchange.py index dd023e1..fde234f 100644 --- a/namebase_exchange/exchange.py +++ b/namebase_exchange/exchange.py @@ -1142,14 +1142,14 @@ def get_dns_settings(self, domain: str): """ return self.request.get(path=f'/dns/domains/{domain}') - def update_dns_settings(self, domain: str, record_type: str = 'TXT', value: str = '', - host: Optional[str] = None, ttl: Optional[int] = 0) -> dict: + def update_dns_settings(self, domain: str, records: [dict]) -> dict: """ Function to updates the Handshake DNS settings for a domain. Execution of this function is as follows:: # https://blog.sia.tech/skynet-handshake-d5d16e6b632f - update_dns_settings(domain = 'test.testdomain', record_type = 'TXT', - value = 'AAApJJPnci_CzFnddB076HGu1_C64T6bfoiQqvsiVB5XeQ', - host: '') + update_dns_settings([{'type':'TXT', + 'host':'', + 'value':'AAApJJPnci_CzFnddB076HGu1_C64T6bfoiQqvsiVB5XeQ', + 'ttl':0}]) The expected return result:: @@ -1162,18 +1162,14 @@ def update_dns_settings(self, domain: str, record_type: str = 'TXT', value: str } ] - :param value: - :param record_type: - :param domain: - :param host: + :param records + records consist of a list of records, each record consists of a value, type, and host + :param domain :return: List of records """ api_params = { - "type": record_type, - "host": host, - "value": value, - "ttl": ttl + "records": records, } return self.request.put(path=f'/dns/domains/{domain}', json_data=api_params)