-
Notifications
You must be signed in to change notification settings - Fork 0
APP_ID is now optional #65
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,9 +75,9 @@ def __init__(self, app_id=None, api_key=None, verify_ssl=None, | |
| app_id = os.getenv('DEEPOMATIC_APP_ID') | ||
| if api_key is None: | ||
| api_key = os.getenv('DEEPOMATIC_API_KEY') | ||
| if app_id is None or api_key is None: | ||
| raise DeepomaticException("Please specify 'app_id' and 'api_key' either by passing those values to the client" | ||
| " or by defining the DEEPOMATIC_APP_ID and DEEPOMATIC_API_KEY environment variables.") | ||
| if api_key is None: | ||
| raise DeepomaticException("Please specify 'api_key' either by passing those values to the client" | ||
| " or by defining the DEEPOMATIC_API_KEY environment variables.") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in #69 |
||
|
|
||
| if not isinstance(version, string_types): | ||
| version = 'v%g' % version | ||
|
|
@@ -111,26 +111,33 @@ def __init__(self, app_id=None, api_key=None, verify_ssl=None, | |
| self.user_agent = ' '.join(user_agent_list).format(**user_agent_params) | ||
|
|
||
| self.api_key = str(api_key) | ||
| self.app_id = str(app_id) | ||
| self.app_id = str(app_id) if app_id else None | ||
| self.verify = verify | ||
| self.host = host | ||
| self.resource_prefix = host + version | ||
|
|
||
| # This is only used in mixins, this should not stay here | ||
| self.check_query_parameters = check_query_parameters | ||
|
|
||
| headers = { | ||
| 'User-Agent': self.user_agent, | ||
| 'X-APP-ID': self.app_id, | ||
| 'X-API-KEY': self.api_key, | ||
| } | ||
| self.session = requests.Session() | ||
| self.session.headers.update(headers) | ||
| self.session.headers.update(self.default_headers()) | ||
| # Use pool_maxsize to cache connections for the same host | ||
| adapter = requests.adapters.HTTPAdapter(pool_maxsize=pool_maxsize) | ||
| self.session.mount('http://', adapter) | ||
| self.session.mount('https://', adapter) | ||
|
|
||
| def default_headers(self): | ||
| """ | ||
| Return the default headers, can be overridden | ||
| """ | ||
| headers = { | ||
| 'User-Agent': self.user_agent, | ||
| 'X-API-KEY': self.api_key, | ||
| } | ||
| if self.app_id: | ||
| headers['X-APP-ID'] = self.app_id | ||
maingoh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return headers | ||
|
|
||
| def setup_headers(self, headers=None, content_type=None): | ||
| """ | ||
| Build additional headers | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/those values/it/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in #69