Skip to content

Commit 1529977

Browse files
committed
add methods for getting URL params [#20]
1 parent c6b727d commit 1529977

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

bunq/sdk/client.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,18 @@ class BunqResponse(object):
312312
"""
313313
:type _value: T
314314
:type _headers: dict[str, str]
315+
:type _pagination: Pagination
315316
"""
316317

317-
def __init__(self, value, headers):
318+
def __init__(self, value, headers, pagination=None):
318319
"""
319320
:type value: T
320321
:type headers: dict[str, str]
321322
"""
322323

323324
self._value = value
324325
self._headers = headers
326+
self._pagination = pagination
325327

326328
@property
327329
def value(self):
@@ -339,6 +341,14 @@ def headers(self):
339341

340342
return self._headers
341343

344+
@property
345+
def pagination(self):
346+
"""
347+
:rtype: Pagination
348+
"""
349+
350+
return self._pagination
351+
342352

343353
class Pagination(object):
344354
"""
@@ -348,8 +358,67 @@ class Pagination(object):
348358
:type _count: int|None
349359
"""
350360

361+
# Field constants
362+
_FIELD_OLDER_ID = 'older_id'
363+
_FIELD_NEWER_ID = 'newer_id'
364+
_FIELD_COUNT = 'count'
365+
351366
def __init__(self):
352367
self._older_id = None
353368
self._newer_id = None
354369
self._future_id = None
355370
self._count = None
371+
372+
@property
373+
def url_params_previous(self):
374+
"""
375+
:rtype: dict
376+
"""
377+
378+
params = {
379+
self._FIELD_OLDER_ID: self._older_id,
380+
}
381+
self._add_count_to_params_if_needed(params)
382+
383+
return params
384+
385+
def _add_count_to_params_if_needed(self, params):
386+
"""
387+
:type params: dict
388+
389+
:rtype: None
390+
"""
391+
392+
if self._count is not None:
393+
params[self._FIELD_COUNT] = self._count
394+
395+
@property
396+
def _next_id(self):
397+
"""
398+
:rtype: int
399+
"""
400+
401+
if self.has_next_item_assured():
402+
return self._newer_id
403+
404+
return self._future_id
405+
406+
def has_next_item_assured(self):
407+
"""
408+
:rtype: bool
409+
"""
410+
411+
return self._newer_id is not None
412+
413+
@property
414+
def url_params_next(self):
415+
"""
416+
:rtype: dict
417+
"""
418+
419+
params = {
420+
self._FIELD_NEWER_ID: self._next_id,
421+
}
422+
self._add_count_to_params_if_needed(params)
423+
424+
return params

0 commit comments

Comments
 (0)