Skip to content

Commit 1356204

Browse files
committed
returned to ListResponse
1 parent 3b33a4c commit 1356204

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

toggl_python/repository.py

Lines changed: 3 additions & 12 deletions
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):
@@ -110,24 +111,14 @@ def _list(self, _url, entity_class, data_key: str = None, **kwargs):
110111

111112
response = self.get(_url, params=params)
112113
response_body = response.json()
113-
response_parameters = (
114-
"total_count",
115-
"per_page",
116-
"total_grand",
117-
"total_billable",
118-
"total_currencies",
119-
)
120114

121115
data = response_body
122116
data_key = data_key or self.DATA_CONTAINER.get("list", None)
123117
if data_key:
124118
data = data[data_key]
125119
if data:
126-
result = [entity_class(**entity) for entity in data]
127-
for parameter in response_parameters:
128-
if parameter in response_body:
129-
setattr(result, parameter, response_body[parameter])
130-
return result
120+
value = [entity_class(**entity) for entity in data]
121+
return ListResponse(value, response_body)
131122

132123
def list(self, **kwargs):
133124
if "list" in self.EXCLUDED_METHODS:

toggl_python/response.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class ListResponse(list):
2+
def __init__(self, value, response_body):
3+
super(ListResponse, self).__init__(value)
4+
5+
response_parameters = (
6+
"total_count",
7+
"per_page",
8+
"total_grand",
9+
"total_billable",
10+
"total_currencies",
11+
)
12+
13+
for parameter in response_parameters:
14+
if parameter in response_body:
15+
setattr(self, parameter, response_body[parameter])

0 commit comments

Comments
 (0)