Add max_retries
config for NationBuilder API
b/c a particular install has frequent DNS issues overnight...
This commit is contained in:
parent
9fe89f0190
commit
dfbd8f1652
|
@ -30,11 +30,15 @@ import requests
|
||||||
class NationBuilderWebAPI(object):
|
class NationBuilderWebAPI(object):
|
||||||
"""
|
"""
|
||||||
Simple web API for NationBuilder.
|
Simple web API for NationBuilder.
|
||||||
|
|
||||||
|
https://nationbuilder.com/api_documentation
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, config, base_url=None, access_token=None, **kwargs):
|
def __init__(self, config, base_url=None, access_token=None,
|
||||||
|
max_retries=None, **kwargs):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.app = self.config.get_app()
|
self.app = self.config.get_app()
|
||||||
|
self.session = None
|
||||||
|
|
||||||
self.base_url = base_url or self.config.require(
|
self.base_url = base_url or self.config.require(
|
||||||
'nationbuilder', 'api.base_url')
|
'nationbuilder', 'api.base_url')
|
||||||
|
@ -43,6 +47,18 @@ class NationBuilderWebAPI(object):
|
||||||
self.access_token = access_token or self.config.require(
|
self.access_token = access_token or self.config.require(
|
||||||
'nationbuilder', 'api.access_token')
|
'nationbuilder', 'api.access_token')
|
||||||
|
|
||||||
|
if max_retries is not None:
|
||||||
|
self.max_retries = max_retries
|
||||||
|
else:
|
||||||
|
self.max_retries = self.config.getint('nationbuilder',
|
||||||
|
'api.max_retries')
|
||||||
|
|
||||||
|
self.session = requests.Session()
|
||||||
|
|
||||||
|
if self.max_retries is not None:
|
||||||
|
adapter = requests.adapters.HTTPAdapter(max_retries=self.max_retries)
|
||||||
|
self.session.mount(self.base_url, adapter)
|
||||||
|
|
||||||
def _request(self, request_method, api_method, params=None):
|
def _request(self, request_method, api_method, params=None):
|
||||||
"""
|
"""
|
||||||
Perform a request for the given API method, and return the response.
|
Perform a request for the given API method, and return the response.
|
||||||
|
|
Loading…
Reference in a new issue