Skip to content
Snippets Groups Projects
Commit 5ec54957 authored by Julian Coy's avatar Julian Coy
Browse files

Added delegate support, merged changes from ashkulz, and updated version

parent f8045021
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ python: ...@@ -4,6 +4,7 @@ python:
- 3.4 - 3.4
script: nosetests tests script: nosetests tests
install: install:
- pip install -r requirements.txt - pip install -r requirements.txt --user
- pip install -r test_requirements.txt --user
notifications: notifications:
email: false email: false
...@@ -32,7 +32,9 @@ Examples ...@@ -32,7 +32,9 @@ Examples
>>> from godaddypy import Client, Account >>> from godaddypy import Client, Account
>>> >>>
>>> my_acct = Account(api_key='PUBLIC_KEY', api_secret='SECRET_KEY') >>> my_acct = Account(api_key='PUBLIC_KEY', api_secret='SECRET_KEY')
>>> delegate_acct = Account(api_key='PUBLIC_KEY', api_secret='SECRET_KEY', delegate='X-Shopper-Id')
>>> client = Client(my_acct) >>> client = Client(my_acct)
>>> delegate_client = Client(delegate_acct)
>>> >>>
>>> client.get_domains() >>> client.get_domains()
['domain1.example', 'domain2.example'] ['domain1.example', 'domain2.example']
......
from .client import Client from .client import Client
from .account import Account from .account import Account
__version__ = '2.1.2' __version__ = '2.2.0'
__all__ = ['Client', 'Account', '__version__'] __all__ = ['Client', 'Account', '__version__']
...@@ -11,7 +11,7 @@ class Account(object): ...@@ -11,7 +11,7 @@ class Account(object):
_SSO_KEY_TEMPLATE = 'sso-key {api_key}:{api_secret}' _SSO_KEY_TEMPLATE = 'sso-key {api_key}:{api_secret}'
def __init__(self, api_key, api_secret): def __init__(self, api_key, api_secret, delegate=None):
"""Create a new `godadypy.Account` object. """Create a new `godadypy.Account` object.
:type api_key: str :type api_key: str
...@@ -23,8 +23,16 @@ class Account(object): ...@@ -23,8 +23,16 @@ class Account(object):
self._api_key = api_key self._api_key = api_key
self._api_secret = api_secret self._api_secret = api_secret
if delegate is not None:
self._delegate = delegate
def get_auth_headers(self): def get_headers(self):
return { headers = {
'Authorization': self._SSO_KEY_TEMPLATE.format(api_key=self._api_key, 'Authorization': self._SSO_KEY_TEMPLATE.format(api_key=self._api_key,
api_secret=self._api_secret)} api_secret=self._api_secret)
}
if self._delegate is not None:
headers['X-Shopper-Id'] = self._delegate
return headers
...@@ -49,7 +49,7 @@ class Client(object): ...@@ -49,7 +49,7 @@ class Client(object):
return url return url
def _get_headers(self): def _get_headers(self):
return self.account.get_auth_headers() return self.account.get_headers()
def _get_json_from_response(self, url, json=None, **kwargs): def _get_json_from_response(self, url, json=None, **kwargs):
return self._request_submit(requests.get, url=url, json=json, **kwargs).json() return self._request_submit(requests.get, url=url, json=json, **kwargs).json()
......
requests>=2.4 requests>=2.4
mock>=2.0.0
callee>=0.2.1
mock>=2.0.0
callee>=0.2.1
nose>=1.3.7
...@@ -65,6 +65,19 @@ class TestClient: ...@@ -65,6 +65,19 @@ class TestClient:
put_mock.assert_called_once_with(callee.String(), json=[fake_records[0]]) put_mock.assert_called_once_with(callee.String(), json=[fake_records[0]])
def test_account_with_delegate(self):
_DELEGATE_ID = '1234987234jdsfasdf'
_PRIVATE_KEY = 'blahdeyblah'
_PUBLIC_KEY = 'hooeybalooooooeryasdfasdfsdfs'
acct = Account(api_key=_PUBLIC_KEY, api_secret=_PRIVATE_KEY, delegate=_DELEGATE_ID)
assert acct.get_headers().has_key('X-Shopper-Id')
assert acct.get_headers().has_key('Authorization')
assert acct.get_headers()['X-Shopper-Id'] == _DELEGATE_ID
assert acct.get_headers()['Authorization'] == Account._SSO_KEY_TEMPLATE.format(api_secret=_PRIVATE_KEY,
api_key=_PUBLIC_KEY)
def test_build_record_url_happy_path(self): def test_build_record_url_happy_path(self):
domains = ['test.com', 'apple.com', 'google.com', 'aol.com'] domains = ['test.com', 'apple.com', 'google.com', 'aol.com']
names = ['@', None, 'someName', None] names = ['@', None, 'someName', None]
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment