-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'rr/auth-session-support' into devel
* rr/auth-session-support: fix lint, add doc for AuthorizedSession add strip function to remove property in option add test and fix lint fix get api_config before params assignment clean request payload fix session object not getting through add test for api_config add AuthorizedSession support
- Loading branch information
Showing
12 changed files
with
298 additions
and
20 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
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,57 @@ | ||
import nasdaqdatalink | ||
from nasdaqdatalink.api_config import ApiConfig | ||
from urllib3.util.retry import Retry | ||
from requests.adapters import HTTPAdapter | ||
import requests | ||
import urllib | ||
|
||
|
||
def get_retries(api_config=nasdaqdatalink.ApiConfig): | ||
retries = None | ||
if not api_config.use_retries: | ||
return Retry(total=0) | ||
|
||
Retry.BACKOFF_MAX = api_config.max_wait_between_retries | ||
retries = Retry(total=api_config.number_of_retries, | ||
connect=api_config.number_of_retries, | ||
read=api_config.number_of_retries, | ||
status_forcelist=api_config.retry_status_codes, | ||
backoff_factor=api_config.retry_backoff_factor, | ||
raise_on_status=False) | ||
return retries | ||
|
||
|
||
class AuthorizedSession: | ||
def __init__(self, api_config=ApiConfig) -> None: | ||
super(AuthorizedSession, self).__init__() | ||
if not isinstance(api_config, ApiConfig): | ||
api_config = ApiConfig | ||
self._api_config = api_config | ||
self._auth_session = requests.Session() | ||
retries = get_retries(self._api_config) | ||
adapter = HTTPAdapter(max_retries=retries) | ||
self._auth_session.mount(api_config.api_protocol, adapter) | ||
|
||
proxies = urllib.request.getproxies() | ||
if proxies is not None: | ||
self._auth_session.proxies.update(proxies) | ||
|
||
def get(self, dataset, **kwargs): | ||
nasdaqdatalink.get(dataset, session=self._auth_session, | ||
api_config=self._api_config, **kwargs) | ||
|
||
def bulkdownload(self, database, **kwargs): | ||
nasdaqdatalink.bulkdownload(database, session=self._auth_session, | ||
api_config=self._api_config, **kwargs) | ||
|
||
def export_table(self, datatable_code, **kwargs): | ||
nasdaqdatalink.export_table(datatable_code, session=self._auth_session, | ||
api_config=self._api_config, **kwargs) | ||
|
||
def get_table(self, datatable_code, **options): | ||
nasdaqdatalink.get_table(datatable_code, session=self._auth_session, | ||
api_config=self._api_config, **options) | ||
|
||
def get_point_in_time(self, datatable_code, **options): | ||
nasdaqdatalink.get_point_in_time(datatable_code, session=self._auth_session, | ||
api_config=self._api_config, **options) |
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
Oops, something went wrong.