| Total Complexity | 5 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | # -*- coding: utf-8 -*- |
||
| 4 | 1 | class PagedList(list): |
|
| 5 | """ |
||
| 6 | Enumerable structure for array-like responses of the Route4Me API. |
||
| 7 | |||
| 8 | Several endpoints of Route4Me API return enumerable responses, which |
||
| 9 | contains meta-information about paging (fields like ``total``, ``limit``, |
||
| 10 | ``offset``). This class allows enumerating requested data along with |
||
| 11 | mentioned meta-data fields. |
||
| 12 | """ |
||
| 13 | 1 | def __init__(self, total=None, limit=None, offset=None, items=None): |
|
| 14 | 1 | _i = tuple() if items is None else items |
|
| 15 | 1 | super(PagedList, self).__init__(_i) |
|
| 16 | |||
| 17 | 1 | self._r4m_total = total |
|
| 18 | 1 | self._r4m_limit = limit |
|
| 19 | 1 | self._r4m_offset = offset |
|
| 20 | |||
| 21 | 1 | @property |
|
| 22 | def total(self): |
||
| 23 | """ |
||
| 24 | Total results count (taken from API response) |
||
| 25 | |||
| 26 | :getter: Results count, when available |
||
| 27 | :rtype: int |
||
| 28 | """ |
||
| 29 | 1 | return self._r4m_total |
|
| 30 | |||
| 31 | 1 | @property |
|
| 32 | def limit(self): |
||
| 33 | """ |
||
| 34 | Limit used during endpoint access |
||
| 35 | |||
| 36 | :getter: Value of ``limit`` parameter if it was used in query |
||
| 37 | :rtype: int |
||
| 38 | """ |
||
| 39 | 1 | return self._r4m_limit |
|
| 40 | |||
| 41 | 1 | @property |
|
| 42 | def offset(self): |
||
| 43 | """ |
||
| 44 | Offset used during endpoint access |
||
| 45 | |||
| 46 | :getter: Value of ``offset`` parameter if it was used in query |
||
| 47 | :rtype: int |
||
| 48 | """ |
||
| 49 | return self._r4m_offset |
||
| 50 |