Skip to content
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

Added logic for request timeouts #90

Merged
merged 3 commits into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 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 @@ -93,5 +97,5 @@ def post_public_key(self, path, data):
def _post(self, path, data):
return post_request(
urljoin('https://' + self.environment + '.plaid.com', path),
data=data,
data=data, timeout=self.timeout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please put timeout=self.timeout on a new line?

)
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this two spaces between 600 and the comment? (PEP 8)



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