-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Construct CartAPI URL from OS environment variables (#15)
* Construct CartAPI URL from OS environment variables * Fix environment variables prefix for CartAPI class * Add logger debug statements to CartAPI instance methods * Remove unused import * Revert changes to Downloader class Commit 3449fb7 did not resolve merge conflicts. * Resolve pylint "protected-access" warning * Resolve pylint D200 and D401 warnings * Resolve pylint pep257 warning * Resolve flake8 F401 warning * resolve autopep8 warnings * CartAPI response is not JSON data * Add coverage test for CartAPI URL * Resolve pylint "protected-access" warning
- Loading branch information
1 parent
ee3660f
commit fd9b464
Showing
6 changed files
with
98 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
"""Common downloader functionality.""" | ||
from os import getenv | ||
import requests | ||
|
||
|
||
# pylint: disable=too-few-public-methods | ||
class CommonBase(object): | ||
"""Contains methods to implement common functionality.""" | ||
|
||
session = None | ||
|
||
def _setup_requests_session(self): | ||
"""Setup a requests retry session so we can talk to http services.""" | ||
self.session = requests.session() | ||
retry_adapter = requests.adapters.HTTPAdapter(max_retries=5) | ||
self.session.mount('https://', retry_adapter) | ||
self.session.mount('http://', retry_adapter) | ||
|
||
def _server_url(self, parts, env_prefix, kwargs): | ||
"""Server URL parsing for init class method.""" | ||
for part, default in parts: | ||
attr_name = '_{}'.format(part) | ||
setattr(self, attr_name, kwargs.get(part)) | ||
if not getattr(self, attr_name): | ||
setattr(self, attr_name, getenv('{}{}'.format( | ||
env_prefix, attr_name.upper()), default)) | ||
# pylint: enable=too-few-public-methods |
This file contains 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 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