Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/custom endpoint #1

Merged
merged 4 commits into from May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions lingo24/business_documents/auth.py
Expand Up @@ -34,22 +34,29 @@ def set(self, value):


class Authenticator(object):
def __init__(self, client_id, client_secret, redirect_url, store=None, endpoint='live'):
def __init__(self, client_id, client_secret, redirect_url, store=None, endpoint='live', endpoint_urls=None):
self.client_id = client_id
self.client_secret = client_secret
self.redirect_url = redirect_url
self.endpoint = endpoint
if store is None:
store = DictAuthenticationStore()
self.store = store
# endpoint_urls takes precedence
if endpoint_urls:
self.endpoint_urls = endpoint_urls
else:
self.endpoint_urls = {
'api': API_ENDPOINT_URLS[endpoint],
'ease': EASE_ENDPOINT_URLS[endpoint],
}

@property
def ease_endpoint_url(self):
return EASE_ENDPOINT_URLS[self.endpoint]
return self.endpoint_urls['ease'].rstrip('/') + '/'

@property
def api_endpoint_url(self):
return API_ENDPOINT_URLS[self.endpoint]
return self.endpoint_urls['api'].rstrip('/') + '/'

@property
def authorization_url(self):
Expand Down
10 changes: 7 additions & 3 deletions lingo24/business_documents/client.py
Expand Up @@ -12,15 +12,19 @@


class Client(object):
def __init__(self, authenticator, endpoint='live', per_page=25):
def __init__(self, authenticator, endpoint='live', per_page=25, endpoint_url=None):
self.authenticator = authenticator
self.endpoint = endpoint
self.per_page = per_page
self._api_session = None
# endpoint_url takes precedence
if endpoint_url:
self.endpoint_url = endpoint_url
else:
self.endpoint_url = API_ENDPOINT_URLS[endpoint]

@property
def api_endpoint_url(self):
return API_ENDPOINT_URLS[self.endpoint]
return self.endpoint_url.rstrip('/') + '/'

@property
def status(self):
Expand Down
6 changes: 6 additions & 0 deletions tests/auth.py
Expand Up @@ -29,6 +29,9 @@ def test_ease_endpoint_url(self):
demo_authenticator = Authenticator('xxx', 'yyy', 'https://www.example.com/callback', endpoint='demo')
self.assertURLEqual(demo_authenticator.ease_endpoint_url, 'https://ease-demo.lingo24.com/')

custom_authenticator = Authenticator('xxx', 'yyy', 'https://www.example.com/callback', endpoint='https://www.example.com/')
self.assertURLEqual(custom_authenticator.ease_endpoint_url, 'https://www.example.com/')

def test_api_endpoint_url(self):
default_authenticator = Authenticator('xxx', 'yyy', 'https://www.example.com/callback')
self.assertURLEqual(default_authenticator.api_endpoint_url, 'https://api.lingo24.com/docs/v1/')
Expand All @@ -39,6 +42,9 @@ def test_api_endpoint_url(self):
demo_authenticator = Authenticator('xxx', 'yyy', 'https://www.example.com/callback', endpoint='demo')
self.assertURLEqual(demo_authenticator.api_endpoint_url, 'https://api-demo.lingo24.com/docs/v1/')

custom_authenticator = Authenticator('xxx', 'yyy', 'https://www.example.com/callback', endpoint='https://www.example.com/')
self.assertURLEqual(custom_authenticator.api_endpoint_url, 'https://www.example.com/')

def test_authorization_url(self):
authenticator = Authenticator('xxx', 'yyy', 'https://www.example.com/callback')
self.assertURLEqual(authenticator.authorization_url, 'https://ease.lingo24.com/oauth/authorize?response_type=code&client_id=xxx&redirect_uri=https%3A%2F%2Fwww.example.com%2Fcallback')
Expand Down