Skip to content

Commit 677fa52

Browse files
committed
refactor pagination [#20]
1 parent 1dd213d commit 677fa52

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

bunq/sdk/client.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ class Pagination(object):
389389
:type _count: int|None
390390
"""
391391

392+
# Error constants
393+
_ERROR_NO_PREVIOUS_PAGE = 'Could not generate previous page URL params: ' \
394+
'there is no previous page.'
395+
392396
# Field constants
393397
FIELD_OLDER_ID = 'older_id'
394398
FIELD_NEWER_ID = 'newer_id'
@@ -401,18 +405,29 @@ def __init__(self):
401405
self._count = None
402406

403407
@property
404-
def url_params_previous(self):
408+
def url_params_previous_page(self):
405409
"""
406410
:rtype: dict[str, str]
411+
:raise: exception.BunqException When there is no previous page.
407412
"""
408413

414+
if not self.has_previous_item():
415+
raise exception.BunqException(self._ERROR_NO_PREVIOUS_PAGE)
416+
409417
params = {
410418
self.FIELD_OLDER_ID: str(self._older_id),
411419
}
412420
self._add_count_to_params_if_needed(params)
413421

414422
return params
415423

424+
def has_previous_item(self):
425+
"""
426+
:rtype: bool
427+
"""
428+
429+
return self._older_id is not None
430+
416431
def _add_count_to_params_if_needed(self, params):
417432
"""
418433
:type params: dict[str, str]
@@ -442,7 +457,7 @@ def has_next_item_assured(self):
442457
return self._newer_id is not None
443458

444459
@property
445-
def url_params_next(self):
460+
def url_params_next_page(self):
446461
"""
447462
:rtype: dict[str, str]
448463
"""

0 commit comments

Comments
 (0)