Skip to content

Commit 6602fac

Browse files
authored
add support for version 2018-05-22 (#121)
* add api versioning * make arguments consistent between http_request and _requests_http_request
1 parent 20a7de3 commit 6602fac

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

plaid/client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def __init__(self,
3333
public_key,
3434
environment,
3535
suppress_warnings=False,
36-
timeout=DEFAULT_TIMEOUT):
36+
timeout=DEFAULT_TIMEOUT,
37+
api_version=None):
3738
'''
3839
Initialize a client with credentials.
3940
@@ -52,6 +53,7 @@ def __init__(self,
5253
self.environment = environment
5354
self.suppress_warnings = suppress_warnings
5455
self.timeout = timeout
56+
self.api_version = api_version
5557

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

9799
def _post(self, path, data):
100+
headers = {}
101+
if self.api_version is not None:
102+
headers = {'Plaid-Version': self.api_version}
98103
return post_request(
99104
urljoin('https://' + self.environment + '.plaid.com', path),
100105
data=data,
101-
timeout=self.timeout
106+
timeout=self.timeout,
107+
headers=headers,
102108
)

plaid/requester.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@
1717
JSONDecodeError = ValueError
1818

1919

20-
def _requests_http_request(url, method, data, timeout=DEFAULT_TIMEOUT):
20+
def _requests_http_request(
21+
url,
22+
method,
23+
data,
24+
headers,
25+
timeout=DEFAULT_TIMEOUT):
2126
normalized_method = method.lower()
27+
headers.update({'User-Agent': 'Plaid Python v{}'.format(__version__)})
2228
if normalized_method in ALLOWED_METHODS:
2329
return getattr(requests, normalized_method)(
2430
url,
2531
json=data,
26-
headers={
27-
'User-Agent': 'Plaid Python v{}'.format(__version__),
28-
},
32+
headers=headers,
2933
timeout=timeout,
3034
)
3135
else:
@@ -34,8 +38,18 @@ def _requests_http_request(url, method, data, timeout=DEFAULT_TIMEOUT):
3438
)
3539

3640

37-
def http_request(url, method=None, data=None, timeout=DEFAULT_TIMEOUT):
38-
response = _requests_http_request(url, method, data or {}, timeout)
41+
def http_request(
42+
url,
43+
method=None,
44+
data=None,
45+
headers=None,
46+
timeout=DEFAULT_TIMEOUT):
47+
response = _requests_http_request(
48+
url,
49+
method,
50+
data or {},
51+
headers or {},
52+
timeout)
3953
try:
4054
response_body = json.loads(response.text)
4155
except JSONDecodeError:

tests/integration/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ def create_client():
1010
return Client(os.environ['CLIENT_ID'],
1111
os.environ['SECRET'],
1212
os.environ['PUBLIC_KEY'],
13-
'sandbox')
13+
'sandbox',
14+
api_version="2017-03-08")
1415

1516
CREDENTIALS = {
1617
'username': 'user_good',

0 commit comments

Comments
 (0)