Skip to content

Commit 61ed77a

Browse files
committed
Added pagination meta to report time entries list response.
1 parent d49bff0 commit 61ed77a

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,4 @@ ENV/
104104
# IDE settings
105105
.vscode/
106106
local_*.py
107+
.idea/

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "toggl_python"
3-
version = "0.2.5"
3+
version = "0.2.6"
44
description = "Python wraper for Toggl API."
55
authors = ["Ivlev Denis <[email protected]>"]
66
readme = "README.md"

toggl_python/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.2.5"
1+
__version__ = "0.2.6"
22

33
from .auth import BasicAuth, TokenAuth # noqa: F401
44
from .entities import Dashboard # noqa: F401
@@ -23,6 +23,7 @@
2323
Dashboards,
2424
Groups,
2525
ProjectUsers,
26+
ReportTimeEntries,
2627
Tags,
2728
Tasks,
2829
TimeEntries,

toggl_python/repository.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
ReportTimeEntry,
2020
)
2121
from .exceptions import MethodNotAllowed, NotSupported
22+
from .response import ListResponse
2223

2324

2425
class BaseRepository(Api):
@@ -29,6 +30,7 @@ class BaseRepository(Api):
2930
EXCLUDED_METHODS = ()
3031
ADDITIONAL_PARAMS = {}
3132
DATA_CONTAINER = {}
33+
RESPONSE_WRAPPER = {}
3234

3335
def __init__(self, base_url=None, auth=None):
3436
super().__init__(base_url=base_url, auth=auth)
@@ -114,7 +116,11 @@ def _list(self, _url, entity_class, data_key: str = None, **kwargs):
114116
if data_key:
115117
data = data[data_key]
116118
if data:
117-
return [entity_class(**entity) for entity in data]
119+
result = [entity_class(**entity) for entity in data]
120+
wrapper = self.RESPONSE_WRAPPER.get("list")
121+
if wrapper:
122+
result = wrapper(result, response)
123+
return result
118124

119125
def list(self, **kwargs):
120126
if "list" in self.EXCLUDED_METHODS:
@@ -185,6 +191,7 @@ class ReportTimeEntries(BaseRepository):
185191
DATA_CONTAINER = {"list": "data"}
186192
LIST_URL = "details"
187193
ENTITY_CLASS = ReportTimeEntry
194+
RESPONSE_WRAPPER = {"list": ListResponse}
188195

189196

190197
class Users(BaseRepository):

toggl_python/response.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class ListResponse(list):
2+
def __init__(self, value, response):
3+
super(ListResponse, self).__init__(value)
4+
5+
data = response.json()
6+
self.total_count = data.get("total_count")
7+
self.per_page = data.get("per_page")

0 commit comments

Comments
 (0)