Skip to content

Commit 8cb89ac

Browse files
committed
[ERP-1353] wrap list by response parameters
1 parent 61ed77a commit 8cb89ac

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

toggl_python/repository.py

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

2423

2524
class BaseRepository(Api):
@@ -30,7 +29,6 @@ class BaseRepository(Api):
3029
EXCLUDED_METHODS = ()
3130
ADDITIONAL_PARAMS = {}
3231
DATA_CONTAINER = {}
33-
RESPONSE_WRAPPER = {}
3432

3533
def __init__(self, base_url=None, auth=None):
3634
super().__init__(base_url=base_url, auth=auth)
@@ -111,15 +109,24 @@ def _list(self, _url, entity_class, data_key: str = None, **kwargs):
111109
params.update(self.ADDITIONAL_PARAMS.get("list", {}))
112110

113111
response = self.get(_url, params=params)
114-
data = response.json()
112+
response_body = response.json()
113+
response_parameters = (
114+
"total_count",
115+
"per_page",
116+
"total_grand",
117+
"total_billable",
118+
"total_currencies",
119+
)
120+
121+
data = response_body
115122
data_key = data_key or self.DATA_CONTAINER.get("list", None)
116123
if data_key:
117124
data = data[data_key]
118125
if data:
119126
result = [entity_class(**entity) for entity in data]
120-
wrapper = self.RESPONSE_WRAPPER.get("list")
121-
if wrapper:
122-
result = wrapper(result, response)
127+
for parameter in response_parameters:
128+
if parameter in response_body:
129+
setattr(result, parameter, response_body[parameter])
123130
return result
124131

125132
def list(self, **kwargs):
@@ -191,7 +198,6 @@ class ReportTimeEntries(BaseRepository):
191198
DATA_CONTAINER = {"list": "data"}
192199
LIST_URL = "details"
193200
ENTITY_CLASS = ReportTimeEntry
194-
RESPONSE_WRAPPER = {"list": ListResponse}
195201

196202

197203
class Users(BaseRepository):

0 commit comments

Comments
 (0)