13
13
from bunq .sdk import context
14
14
from bunq .sdk import exception
15
15
16
+ try :
17
+ from urllib import urlencode
18
+ except ImportError :
19
+ from urllib .parse import urlencode
20
+
16
21
17
22
class ApiClient (object ):
18
23
"""
@@ -79,27 +84,34 @@ def post(self, uri_relative, request_bytes, custom_headers):
79
84
custom_headers
80
85
)
81
86
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 ):
83
89
"""
84
90
:type method: str
85
91
:type uri_relative: str
86
92
:type request_bytes: bytes
87
93
:type custom_headers: dict[str, str]
94
+ :type params: dict[str, str]|None
88
95
89
96
:return: BunqResponseRaw
90
97
"""
91
98
99
+ if params :
100
+ uri_relative_with_params = uri_relative + '?' + urlencode (params )
101
+ else :
102
+ uri_relative_with_params = uri_relative
103
+
92
104
self ._api_context .ensure_session_active ()
93
105
all_headers = self ._get_all_headers (
94
106
method ,
95
- uri_relative ,
107
+ uri_relative_with_params ,
96
108
request_bytes ,
97
109
custom_headers
98
110
)
99
111
100
112
response = requests .request (
101
113
method ,
102
- self ._get_uri_full (uri_relative ),
114
+ self ._get_uri_full (uri_relative_with_params ),
103
115
data = request_bytes ,
104
116
headers = all_headers ,
105
117
proxies = {self ._FIELD_PROXY_HTTPS : self ._api_context .proxy_url }
@@ -245,10 +257,11 @@ def put(self, uri_relative, request_bytes, custom_headers):
245
257
custom_headers
246
258
)
247
259
248
- def get (self , uri_relative , custom_headers ):
260
+ def get (self , uri_relative , custom_headers , params = None ):
249
261
"""
250
262
:type uri_relative: str
251
263
:type custom_headers: dict[str, str]
264
+ :type params: dict[str, str]
252
265
253
266
:rtype: BunqResponseRaw
254
267
"""
@@ -257,7 +270,8 @@ def get(self, uri_relative, custom_headers):
257
270
self ._METHOD_GET ,
258
271
uri_relative ,
259
272
self ._BYTES_EMPTY ,
260
- custom_headers
273
+ custom_headers ,
274
+ params
261
275
)
262
276
263
277
def delete (self , uri_relative , custom_headers ):
@@ -372,25 +386,25 @@ def __init__(self):
372
386
@property
373
387
def url_params_previous (self ):
374
388
"""
375
- :rtype: dict
389
+ :rtype: dict[str, str]
376
390
"""
377
391
378
392
params = {
379
- self ._FIELD_OLDER_ID : self ._older_id ,
393
+ self ._FIELD_OLDER_ID : str ( self ._older_id ) ,
380
394
}
381
395
self ._add_count_to_params_if_needed (params )
382
396
383
397
return params
384
398
385
399
def _add_count_to_params_if_needed (self , params ):
386
400
"""
387
- :type params: dict
401
+ :type params: dict[str, str]
388
402
389
403
:rtype: None
390
404
"""
391
405
392
406
if self ._count is not None :
393
- params [self ._FIELD_COUNT ] = self ._count
407
+ params [self ._FIELD_COUNT ] = str ( self ._count )
394
408
395
409
@property
396
410
def _next_id (self ):
@@ -413,11 +427,11 @@ def has_next_item_assured(self):
413
427
@property
414
428
def url_params_next (self ):
415
429
"""
416
- :rtype: dict
430
+ :rtype: dict[str, str]
417
431
"""
418
432
419
433
params = {
420
- self ._FIELD_NEWER_ID : self ._next_id ,
434
+ self ._FIELD_NEWER_ID : str ( self ._next_id ) ,
421
435
}
422
436
self ._add_count_to_params_if_needed (params )
423
437
0 commit comments