Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions plaid/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Sandbox,
Transactions,
)
from plaid.requester import post_request
from plaid.requester import DEFAULT_TIMEOUT, post_request
from plaid.utils import urljoin


Expand All @@ -32,7 +32,8 @@ def __init__(self,
secret,
public_key,
environment,
suppress_warnings=False):
suppress_warnings=False,
timeout=DEFAULT_TIMEOUT):
'''
Initialize a client with credentials.

Expand All @@ -42,12 +43,15 @@ def __init__(self,
:arg str environment: One of ``sandbox``,
``development``, or ``production``.
:arg bool suppress_warnings: Suppress Plaid warnings.
:arg int timeout: Timeout for API requests.

'''
self.client_id = client_id
self.secret = secret
self.public_key = public_key
self.environment = environment
self.suppress_warnings = suppress_warnings
self.timeout = timeout

if self.environment == 'development' and not self.suppress_warnings:
warnings.warn('''
Expand Down Expand Up @@ -94,4 +98,5 @@ def _post(self, path, data):
return post_request(
urljoin('https://' + self.environment + '.plaid.com', path),
data=data,
timeout=self.timeout
)
10 changes: 5 additions & 5 deletions plaid/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@


ALLOWED_METHODS = {'post'}
TIMEOUT = 600 # 10 minutes
DEFAULT_TIMEOUT = 600 # 10 minutes


def _requests_http_request(url, method, data):
def _requests_http_request(url, method, data, timeout=DEFAULT_TIMEOUT):
normalized_method = method.lower()
if normalized_method in ALLOWED_METHODS:
return getattr(requests, normalized_method)(
Expand All @@ -20,16 +20,16 @@ def _requests_http_request(url, method, data):
headers={
'User-Agent': 'Plaid Python v{}'.format(__version__),
},
timeout=TIMEOUT,
timeout=timeout,
)
else:
raise Exception(
'Invalid request method {}'.format(method)
)


def http_request(url, method=None, data=None):
response = _requests_http_request(url, method, data or {})
def http_request(url, method=None, data=None, timeout=DEFAULT_TIMEOUT):
response = _requests_http_request(url, method, data or {}, timeout)
response_body = json.loads(response.text)
if response_body.get('error_type'):
raise PlaidError.from_response(response_body)
Expand Down