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
10 changes: 8 additions & 2 deletions plaid/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def __init__(self,
public_key,
environment,
suppress_warnings=False,
timeout=DEFAULT_TIMEOUT):
timeout=DEFAULT_TIMEOUT,
api_version=None):
'''
Initialize a client with credentials.

Expand All @@ -52,6 +53,7 @@ def __init__(self,
self.environment = environment
self.suppress_warnings = suppress_warnings
self.timeout = timeout
self.api_version = api_version

if self.environment == 'development' and not self.suppress_warnings:
warnings.warn('''
Expand Down Expand Up @@ -95,8 +97,12 @@ def post_public_key(self, path, data):
return self._post(path, post_data)

def _post(self, path, data):
headers = {}
if self.api_version is not None:
headers = {'Plaid-Version': self.api_version}
return post_request(
urljoin('https://' + self.environment + '.plaid.com', path),
data=data,
timeout=self.timeout
timeout=self.timeout,
headers=headers,
)
26 changes: 20 additions & 6 deletions plaid/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
JSONDecodeError = ValueError


def _requests_http_request(url, method, data, timeout=DEFAULT_TIMEOUT):
def _requests_http_request(
url,
method,
data,
headers,
timeout=DEFAULT_TIMEOUT):
normalized_method = method.lower()
headers.update({'User-Agent': 'Plaid Python v{}'.format(__version__)})
if normalized_method in ALLOWED_METHODS:
return getattr(requests, normalized_method)(
url,
json=data,
headers={
'User-Agent': 'Plaid Python v{}'.format(__version__),
},
headers=headers,
timeout=timeout,
)
else:
Expand All @@ -34,8 +38,18 @@ def _requests_http_request(url, method, data, timeout=DEFAULT_TIMEOUT):
)


def http_request(url, method=None, data=None, timeout=DEFAULT_TIMEOUT):
response = _requests_http_request(url, method, data or {}, timeout)
def http_request(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's keep the argument order consistent between http_request and _requests_http_request (the order of headers and timeout is reversed between the two).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great catch! You're right about the major release, my mistake.

url,
method=None,
data=None,
headers=None,
timeout=DEFAULT_TIMEOUT):
response = _requests_http_request(
url,
method,
data or {},
headers or {},
timeout)
try:
response_body = json.loads(response.text)
except JSONDecodeError:
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def create_client():
return Client(os.environ['CLIENT_ID'],
os.environ['SECRET'],
os.environ['PUBLIC_KEY'],
'sandbox')
'sandbox',
api_version="2017-03-08")

CREDENTIALS = {
'username': 'user_good',
Expand Down