diff --git a/.gitignore b/.gitignore index 12075ea2..a4471c06 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,4 @@ target/ ### Project Specific ### .dnsimple .env +env diff --git a/.travis.yml b/.travis.yml index 4bfb06a7..6a7e09bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,13 @@ language: python + python: - "2.7" - "3.4" - "3.5" - "3.6" + install: - - pip install -r requirements.txt + - make ci-setup + script: - - py.test tests + - make ci-test diff --git a/Makefile b/Makefile index 38639fad..a0f6eb28 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,21 @@ -.DEFAULT_GOAL := setup - -ci: - py.test tests +setup: + test -e env || virtualenv env + ./env/bin/pip install -r requirements.txt --upgrade + ./env/bin/python setup.py develop test: setup + test -f tests/.env || { echo "Set up your env file before running tests"; exit 1; } ./env/bin/py.test tests -env: env/bin/activate +ci-setup: + pip install -r requirements.txt --upgrade -env/bin/activate: requirements.txt - test -d env || virtualenv env; \ - ./env/bin/pip install -r requirements.txt --upgrade; +ci-test: + py.test tests -dnsimple.egg-info/SOURCES.txt: env - ./env/bin/python setup.py develop - -setup: dnsimple.egg-info/SOURCES.txt +deploy: + rm dist/* + python setup.py sdist + twine upload dist/* .PHONY: test diff --git a/README.markdown b/README.markdown deleted file mode 100644 index f3e2ee79..00000000 --- a/README.markdown +++ /dev/null @@ -1,151 +0,0 @@ -Python DNSimple -=============== - -## Introduction - -This is a client for the DNSimple REST API. It currently allows you to fetch -existing domain info, as well as register new domains and manage domain -records. - -`dnsimple-python` works for both python 2 & 3. - -### Getting started - -You'll need the `json` module that is included with python version 2.6 and -later, or the `simplejson` module if you are using an earlier version. - -`dnsimple-python` also depends on the `requests` library. - -Import the module: - - from dnsimple import DNSimple - -You can provide your DNSimple credentials in one of two ways: - -1. Provide username/password or email/api\_token credentials programmatically: - - # Use username/password authentication: HTTP Basic - dns = DNSimple(username=YOUR_USERNAME, password=YOUR_PASSWORD) - - # Use email/api_token credentials - dns = DNSimple(api_token=YOUR_API_TOKEN) - - # If you have many accounts you can provide account_id (661 is an example) - # You can find your account id in url (https://sandbox.dnsimple.com/a/661/account) - dns = DNSimple(username=YOUR_USERNAME, password=YOUR_PASSWORD, account_id=661) - -2. Store you username/password or email/api\_token credentials in a file called -`.dnsimple` in the current directory with the following data: - - [DNSimple] - username: email@domain.com - password: yourpassword - - Or: - - [DNSimple] - api_token: yourapitoken - - Or (assuming `$DNSIMPLE_EMAIL` and `$DNSIMPLE_TOKEN` are environment variables): - - [DNSimple] - email: %(DNSIMPLE_EMAIL)s - api_token: %(DNSIMPLE_TOKEN)s - - You then need not provide any credentials when constructing `DNSimple`: - - dns = DNSimple() - -## Domain Operations - -### Check out your existing domains: - -Just run: - - domains = dns.domains() - -Results appear as a Python dict: - - {'domain': {'created_at': '2010-10-14T09:45:32Z', - 'expires_at': '10/14/2011 5:45:00 AM', - 'id': 999, - 'last_enom_order_id': None, - 'name': 'yourdomain.com', - 'name_server_status': 'active', - 'registrant_id': 99, - 'registration_status': 'registered', - 'updated_at': '2010-10-14T10:00:14Z', - 'user_id': 99}}, - {'domain': {'created_at': '2010-10-15T16:02:34Z', - 'expires_at': '10/15/2011 12:02:00 PM', - 'id': 999, - 'last_enom_order_id': None, - 'name': 'anotherdomain.com', - 'name_server_status': 'active', - 'registrant_id': 99, - 'registration_status': 'registered', - 'updated_at': '2010-10-15T16:30:16Z', - 'user_id': 99}}] - -### Get details for a specific domain - - dns.domain('mikemaccana.com') - -Results are the same as `domains()` above, but only show the domain specified. - -### Check whether a domain is available - - dns.check('google.com') - - # Hmm, looks like I'm too late to get that one... - {u'currency': u'USD', - u'currency_symbol': u'$', - u'minimum_number_of_years': 1, - u'name': u'google.com', - u'price': u'14.00', - u'status': u'unavailable'} - -### Register a new domain - - dns.register('newdomain.com') - -This will register 'newdomain.com', automatically picking the registrant\_id -from your first domain. To specify a particularly `registrant_id`, just run: - - dns.register('newdomain.com', 99) - -Responses will be in a dictionary describing the newly created domain, same as -the `domain()` call above. - -### Delete a domain - -Careful with this one! - - dns.delete('domain-to-die.com') - -## Record operations - -All operations on domain records are now supported: - -* List records: `records(id_or_domainname)` -* Get record details: `record(id_or_domainname, record_id)` -* Add record: `add_record(id_or_domainname, data)` -* Update record: `update_record(id_or_domainname, record_id, data)` -* Delete record: `delete_record(id_or_domainname, record_id)` - -## Running Tests - -Before running tests, you'll need to ensure your environment is set up correctly: - -1. If you don't already have a DNSimple sandbox account, [create one](https://sandbox.dnsimple.com/signup) and make sure to have your email address, password, and API token handy. -1. Ensure you have the `virtualenv` package installed (`pip install virtualenv --upgrade`) since tests are run from this isolated environment -1. Copy the file `tests/.env.example` to `tests/.env` and supply your sandbox credentials -1. From the project root, run `make test` -- this will set up your local environment with `virutalenv`, install all necessary dependencies, and run all the tests. - -## License - -Licensed under the [MIT license](http://www.opensource.org/licenses/mit-license.php) - -## Authors - -* Original Author [Mike MacCana](https://github.com/mikemaccana/) diff --git a/README.md b/README.md new file mode 100644 index 00000000..f0836591 --- /dev/null +++ b/README.md @@ -0,0 +1,174 @@ +Python DNSimple +=============== + +## Introduction + +This is a client for the [DNSimple REST API](https://developer.dnsimple.com/). It currently allows you to fetch existing domain info, as well as register new domains and manage domain records. + +`dnsimple-python` works for both python 2 & 3. + +**Note:** As of 1.0.0 this now uses [DNSimple's APIv2](https://blog.dnsimple.com/2016/12/api-v2-stable/). This has some incompatibilities with APIv1, including auth changes. Please test for breakages before use. + +### Getting started + +You'll need the `json` module that is included with python version 2.6 and later, or the `simplejson` module if you are using an earlier version. + +`dnsimple-python` also depends on the `requests` library. + +Import the module: + +```python +from dnsimple import DNSimple +``` + +You can provide your DNSimple credentials in one of two ways: + +#### Provide username/password or email/api\_token credentials programmatically: + +```python +# Use username/password authentication: HTTP Basic +dns = DNSimple(username=YOUR_USERNAME, password=YOUR_PASSWORD) + +# Use email/api_token credentials +dns = DNSimple(api_token=YOUR_API_TOKEN) + +# If you have many accounts you can provide account_id (661 is an example) +# You can find your account id in url (https://sandbox.dnsimple.com/a/661/account) +dns = DNSimple(username=YOUR_USERNAME, password=YOUR_PASSWORD, account_id=661) +``` + +##### Store you username/password or email/api\_token credentials in a file called `.dnsimple` in the current directory with the following data: + +``` +[DNSimple] +username: email@domain.com +password: yourpassword +``` + +Or: + +``` +[DNSimple] +api_token: yourapitoken +``` + +Or (assuming `$DNSIMPLE_EMAIL` and `$DNSIMPLE_TOKEN` are environment variables): + +``` +[DNSimple] +email: %(DNSIMPLE_EMAIL)s +api_token: %(DNSIMPLE_TOKEN)s +``` + +You then need not provide any credentials when constructing `DNSimple`: + +```python +dns = DNSimple() +``` + +## Domain Operations + +### Check out your existing domains: + +Just run: + +```python +domains = dns.domains() +``` + +Results appear as a Python dict: + +```python +{'domain': {'created_at': '2010-10-14T09:45:32Z', + 'expires_at': '10/14/2011 5:45:00 AM', + 'id': 999, + 'last_enom_order_id': None, + 'name': 'yourdomain.com', + 'name_server_status': 'active', + 'registrant_id': 99, + 'registration_status': 'registered', + 'updated_at': '2010-10-14T10:00:14Z', + 'user_id': 99}}, +{'domain': {'created_at': '2010-10-15T16:02:34Z', + 'expires_at': '10/15/2011 12:02:00 PM', + 'id': 999, + 'last_enom_order_id': None, + 'name': 'anotherdomain.com', + 'name_server_status': 'active', + 'registrant_id': 99, + 'registration_status': 'registered', + 'updated_at': '2010-10-15T16:30:16Z', + 'user_id': 99}}] +``` + +### Get details for a specific domain + +```python +dns.domain('mikemaccana.com') +``` + +Results are the same as `domains()` above, but only show the domain specified. + +### Check whether a domain is available + +```python +dns.check('google.com') + +# Hmm, looks like I'm too late to get that one... +{u'currency': u'USD', +u'currency_symbol': u'$', +u'minimum_number_of_years': 1, +u'name': u'google.com', +u'price': u'14.00', +u'status': u'unavailable'} +``` + +### Register a new domain + +```python +dns.register('newdomain.com') +``` + +This will register 'newdomain.com', automatically picking the registrant\_id from your first domain. To specify a particularly `registrant_id`, just run: + +```python +dns.register('newdomain.com', 99) +``` + +Responses will be in a dictionary describing the newly created domain, same as the `domain()` call above. + +### Delete a domain + +Careful with this one! + +```python +dns.delete('domain-to-die.com') +``` + +## Record operations + +All operations on domain records are now supported: + +* List records: `records(id_or_domainname)` +* Get record details: `record(id_or_domainname, record_id)` +* Add record: `add_record(id_or_domainname, data)` +* Update record: `update_record(id_or_domainname, record_id, data)` +* Delete record: `delete_record(id_or_domainname, record_id)` + +## Running Tests + +Before running tests, you'll need to ensure your environment is set up correctly: + +1. If you don't already have a DNSimple sandbox account, [create one](https://sandbox.dnsimple.com/signup) and make sure to have your email address, password, and API token handy. +1. Ensure you have the `virtualenv` package installed (`pip install virtualenv --upgrade`) since tests are run from this isolated environment +1. Copy the file `tests/.env.example` to `tests/.env` and supply your sandbox credentials +1. From the project root, run `make test` -- this will set up your local environment with `virutalenv`, install all necessary dependencies, and run all the tests. + +## License + +Licensed under the [MIT license](http://www.opensource.org/licenses/mit-license.php) + +## Authors + +* Original Author [Mike MacCana](https://github.com/mikemaccana/) +* APIv2 Support [Kirill Motkov](https://github.com/lcd1232) diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 90424aa8..00000000 --- a/circle.yml +++ /dev/null @@ -1,6 +0,0 @@ -machine: - python: - version: 2.7.11 -test: - override: - - make ci diff --git a/setup.py b/setup.py index 8a04c084..25e34e8c 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from dnsimple import dnsimple -with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.markdown'), 'r') as readme_file: +with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.md'), 'r') as readme_file: readme = readme_file.read() setup( diff --git a/tests/test_auth.py b/tests/test_auth.py index c07e1d86..5f05f981 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -67,22 +67,3 @@ def test_basic_authentication_from_credentials_file_raises_no_exception(self, cr client = DNSimple(sandbox = True) client.domains() - - @pytest.mark.skip(reason='APIv2 does not support auth by domain token') - def test_domain_token_auth(self, client): - domain_name = 'dnsimple-domain-token.test' - - domain = client.add_domain(domain_name) - assert domain - - token_client = DNSimple(domain_token = domain['domain']['token'], sandbox = True) - - with pytest.raises(DNSimpleException) as exception: - token_client.domains() - - assert 'Authentication failed' in str(exception.value) - assert token_client.domain(domain_name)['domain']['name'] == domain_name - - client.delete(domain_name) - - assert len(client.domains()) == 0