Skip to content

Commit

Permalink
Merge pull request #1 from inwx/pypi
Browse files Browse the repository at this point in the history
Adds support for Pypi
  • Loading branch information
ddmler authored Sep 6, 2019
2 parents 7cfba22 + 600eb47 commit 38b1b92
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 28 deletions.
6 changes: 3 additions & 3 deletions domrobot.py → INWX/Domrobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class ApiType(Enum):
JSON_RPC = '/jsonrpc/'


class Domrobot:
CLIENT_VERSION = '2.0'
class ApiClient:
CLIENT_VERSION = '3.0'
API_LIVE_URL = 'https://api.domrobot.com'
API_OTE_URL = 'https://api.ote.domrobot.com'

Expand Down Expand Up @@ -117,7 +117,7 @@ def call_api(self, api_method, method_params=None):

headers = {
'Content-Type': 'text/xml',
'User-Agent': 'DomRobot/' + Domrobot.CLIENT_VERSION + ' (Python ' + self.get_python_version() + ')'
'User-Agent': 'DomRobot/' + ApiClient.CLIENT_VERSION + ' (Python ' + self.get_python_version() + ')'
}

response = self.api_session.post(self.api_url + self.api_type.value, data=payload, headers=headers)
Expand Down
1 change: 1 addition & 0 deletions INWX/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from INWX.Domrobot import ApiClient, ApiType
22 changes: 11 additions & 11 deletions examples/domaincheck.py → INWX/examples/domaincheck.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
from domrobot import Domrobot
from INWX.Domrobot import ApiClient

username = ''
password = ''
domain = 'my-test-domain-which-is-definitely-not-registered6737.com'

# By default you Domrobot uses the test api (OT&E). If you want to use the production/live api
# we have a constant named API_LIVE_URL in the Domrobot class. Just set api_url=Domrobot.API_LIVE_URL and you're good.
# By default you ApiClient uses the test api (OT&E). If you want to use the production/live api
# we have a constant named API_LIVE_URL in the ApiClient class. Just set api_url=ApiClient.API_LIVE_URL and you're good.
# You can also choose between XML-RPC and JSON-RPC by setting api_type=ApiType.XML_RPC or api_type=ApiType.JSON_RPC
domrobot = Domrobot(api_url=Domrobot.API_OTE_URL, debug_mode=True)
api_client = ApiClient(api_url=ApiClient.API_OTE_URL, debug_mode=True)

# If you have 2fa enabled, take a look at the documentation of the Domrobot#login method to get further
# If you have 2fa enabled, take a look at the documentation of the ApiClient#login method to get further
# information about the login, especially the shared_secret parameter.
login_result = domrobot.login(username, password)
login_result = api_client.login(username, password)

# login was successful
if login_result['code'] == 1000:

# Make an api call and save the result in a variable.
# We want to check if a domain is available, so we call the api method 'domain.check'.
# Domrobot#call_api returns the api response as a dict.
domain_check_result = domrobot.call_api(api_method='domain.check', method_params={'domain': domain})
# ApiClient#call_api returns the api response as a dict.
domain_check_result = api_client.call_api(api_method='domain.check', method_params={'domain': domain})

# request was successful
if domain_check_result['code'] == 1000:
Expand All @@ -33,10 +33,10 @@
print('Unfortunately, ' + domain + ' is already registered.')

else:
raise Exception('Api error while checking domain status. Code: ' + domain_check_result['code']
raise Exception('Api error while checking domain status. Code: ' + str(domain_check_result['code'])
+ ' Message: ' + domain_check_result['msg'])

# With or without successful check, we perform a logout.
domrobot.logout()
api_client.logout()
else:
raise Exception('Api login error. Code: ' + login_result['code'] + ' Message: ' + login_result['msg'])
raise Exception('Api login error. Code: ' + str(login_result['code']) + ' Message: ' + login_result['msg'])
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,30 @@ If you still experience any kind of problems don't hesitate to contact our [supp

Installation
-------
the recommended way is via pip:
The recommended way is via pip:

```bash
pip install inwx-domrobot
```

You can find more information about the package on [pypi.org](https://pypi.org/project/inwx-domrobot).

Example
-------

```python
from domrobot import Domrobot
from INWX.Domrobot import ApiClient

username = ''
password = ''
domain = 'my-test-domain-which-is-definitely-not-registered6737.com'

domrobot = Domrobot(api_url=Domrobot.API_OTE_URL, debug_mode=True)
api_client = ApiClient(api_url=ApiClient.API_OTE_URL, debug_mode=True)

login_result = domrobot.login(username, password)
login_result = api_client.login(username, password)

if login_result['code'] == 1000:
domain_check_result = domrobot.call_api(api_method='domain.check', method_params={'domain': domain})
domain_check_result = api_client.call_api(api_method='domain.check', method_params={'domain': domain})

if domain_check_result['code'] == 1000:
checked_domain = domain_check_result['resData']['domain'][0]
Expand All @@ -47,14 +52,14 @@ if login_result['code'] == 1000:
print('Unfortunately, ' + domain + ' is already registered.')

else:
raise Exception('Api error while checking domain status. Code: ' + domain_check_result['code']
raise Exception('Api error while checking domain status. Code: ' + str(domain_check_result['code'])
+ ' Message: ' + domain_check_result['msg'])
domrobot.logout()
api_client.logout()
else:
raise Exception('Api login error. Code: ' + login_result['code'] + ' Message: ' + login_result['msg'])
raise Exception('Api login error. Code: ' + str(login_result['code']) + ' Message: ' + login_result['msg'])
```

You can also have a look at the example folder in the project for even more info.
You can also have a look at the [example folder](INWX/examples) in the project for even more info.

License
----
Expand Down
5 changes: 0 additions & 5 deletions requirements.txt

This file was deleted.

2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description-file = README.md
35 changes: 35 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import setuptools
from INWX.Domrobot import ApiClient

with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
name='inwx_domrobot',
version=ApiClient.CLIENT_VERSION,
author='INWX Developer',
author_email='[email protected]',
description='INWX API Python Client',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/inwx/python-client',
download_url='https://github.com/inwx/python-client/archive/v' + ApiClient.CLIENT_VERSION + '.tar.gz',
packages=setuptools.find_packages(),
keywords=['INWX', 'API', 'PYTHON', 'CLIENT', 'DOMROBOT'],
install_requires=[
'requests'
],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Topic :: Software Development',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
],
)

0 comments on commit 38b1b92

Please sign in to comment.