Skip to content

Commit 6f919c3

Browse files
committed
make params functional [#20]
1 parent 1529977 commit 6f919c3

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

bunq/sdk/client.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
from bunq.sdk import context
1414
from bunq.sdk import exception
1515

16+
try:
17+
from urllib import urlencode
18+
except ImportError:
19+
from urllib.parse import urlencode
20+
1621

1722
class ApiClient(object):
1823
"""
@@ -79,27 +84,34 @@ def post(self, uri_relative, request_bytes, custom_headers):
7984
custom_headers
8085
)
8186

82-
def _request(self, method, uri_relative, request_bytes, custom_headers):
87+
def _request(self, method, uri_relative, request_bytes, custom_headers,
88+
params=None):
8389
"""
8490
:type method: str
8591
:type uri_relative: str
8692
:type request_bytes: bytes
8793
:type custom_headers: dict[str, str]
94+
:type params: dict[str, str]|None
8895
8996
:return: BunqResponseRaw
9097
"""
9198

99+
if params:
100+
uri_relative_with_params = uri_relative + '?' + urlencode(params)
101+
else:
102+
uri_relative_with_params = uri_relative
103+
92104
self._api_context.ensure_session_active()
93105
all_headers = self._get_all_headers(
94106
method,
95-
uri_relative,
107+
uri_relative_with_params,
96108
request_bytes,
97109
custom_headers
98110
)
99111

100112
response = requests.request(
101113
method,
102-
self._get_uri_full(uri_relative),
114+
self._get_uri_full(uri_relative_with_params),
103115
data=request_bytes,
104116
headers=all_headers,
105117
proxies={self._FIELD_PROXY_HTTPS: self._api_context.proxy_url}
@@ -245,10 +257,11 @@ def put(self, uri_relative, request_bytes, custom_headers):
245257
custom_headers
246258
)
247259

248-
def get(self, uri_relative, custom_headers):
260+
def get(self, uri_relative, custom_headers, params=None):
249261
"""
250262
:type uri_relative: str
251263
:type custom_headers: dict[str, str]
264+
:type params: dict[str, str]
252265
253266
:rtype: BunqResponseRaw
254267
"""
@@ -257,7 +270,8 @@ def get(self, uri_relative, custom_headers):
257270
self._METHOD_GET,
258271
uri_relative,
259272
self._BYTES_EMPTY,
260-
custom_headers
273+
custom_headers,
274+
params
261275
)
262276

263277
def delete(self, uri_relative, custom_headers):
@@ -372,25 +386,25 @@ def __init__(self):
372386
@property
373387
def url_params_previous(self):
374388
"""
375-
:rtype: dict
389+
:rtype: dict[str, str]
376390
"""
377391

378392
params = {
379-
self._FIELD_OLDER_ID: self._older_id,
393+
self._FIELD_OLDER_ID: str(self._older_id),
380394
}
381395
self._add_count_to_params_if_needed(params)
382396

383397
return params
384398

385399
def _add_count_to_params_if_needed(self, params):
386400
"""
387-
:type params: dict
401+
:type params: dict[str, str]
388402
389403
:rtype: None
390404
"""
391405

392406
if self._count is not None:
393-
params[self._FIELD_COUNT] = self._count
407+
params[self._FIELD_COUNT] = str(self._count)
394408

395409
@property
396410
def _next_id(self):
@@ -413,11 +427,11 @@ def has_next_item_assured(self):
413427
@property
414428
def url_params_next(self):
415429
"""
416-
:rtype: dict
430+
:rtype: dict[str, str]
417431
"""
418432

419433
params = {
420-
self._FIELD_NEWER_ID: self._next_id,
434+
self._FIELD_NEWER_ID: str(self._next_id),
421435
}
422436
self._add_count_to_params_if_needed(params)
423437

0 commit comments

Comments
 (0)