diff --git a/pygrocy/grocy.py b/pygrocy/grocy.py index 23310e5..87f0f90 100644 --- a/pygrocy/grocy.py +++ b/pygrocy/grocy.py @@ -5,7 +5,7 @@ CurrentStockResponse, CurrentVolatilStockResponse, GrocyApiClient, ProductData, ProductDetailsResponse, - TransactionType) + TransactionType, UserDto) class Product(object): @@ -44,11 +44,14 @@ def __init__(self, raw_chore: CurrentChoreResponse): self._chore_id = raw_chore.chore_id self._last_tracked_time = raw_chore.last_tracked_time self._next_estimated_execution_time = raw_chore.next_estimated_execution_time + self._name = None + self._last_done_by = None def get_details(self, api_client: GrocyApiClient): details = api_client.get_chore(self.chore_id) self._name = details.chore.name + self._last_done_by = details.last_done_by @property def chore_id(self) -> int: @@ -66,6 +69,10 @@ def next_estimated_execution_time(self) -> datetime: def name(self) -> str: return self._name + @property + def last_done_by(self) -> UserDto: + return self._last_done_by + class Grocy(object): def __init__(self, base_url, api_key): diff --git a/pygrocy/grocy_api_client.py b/pygrocy/grocy_api_client.py index a762142..b162144 100644 --- a/pygrocy/grocy_api_client.py +++ b/pygrocy/grocy_api_client.py @@ -69,6 +69,29 @@ def __init__(self, parsed_json): self._id = parse_int(parsed_json.get('id')) self._username = parsed_json.get('username') + self._first_name = parsed_json.get('first_name') + self._last_name = parsed_json.get('last_name') + self._display_name = parsed_json.get('display_name') + + @property + def id(self) -> int: + return self._id + + @property + def username(self) -> str: + return self._username + + @property + def first_name(self) -> str: + return self._first_name + + @property + def last_name(self) -> str: + return self._last_name + + @property + def display_name(self) -> str: + return self._display_name class CurrentChoreResponse(object): @@ -182,6 +205,10 @@ def __init__(self, parsed_json): def chore(self) -> ChoreData: return self._chore + @property + def last_done_by(self) -> UserDto: + return self._last_done_by + class TransactionType(Enum): PURCHASE = "purchase" diff --git a/test/test_choreDetailsResponse.py b/test/test_choreDetailsResponse.py new file mode 100644 index 0000000..aa9271e --- /dev/null +++ b/test/test_choreDetailsResponse.py @@ -0,0 +1,36 @@ +import json +from unittest import TestCase + +from pygrocy.grocy_api_client import ChoreDetailsResponse + + +class TestChoreDetailsResponse(TestCase): + def test_parse(self): + input_json = """{ + "chore": { + "id": 0, + "name": "string", + "description": "string", + "period_type": "manually", + "period_days": 0, + "row_created_timestamp": "2019-05-04T11:31:04.563Z" + }, + "last_tracked": "2019-05-04T11:31:04.563Z", + "track_count": 0, + "last_done_by": { + "id": 0, + "username": "string", + "first_name": "string", + "last_name": "string", + "display_name": "string", + "row_created_timestamp": "2019-05-04T11:31:04.564Z" + }, + "next_estimated_execution_time": "2019-05-04T11:31:04.564Z" + }""" + + response = ChoreDetailsResponse(json.loads(input_json)) + + assert response.chore.id == 0 + assert response.chore.name == "string" + + assert response.last_done_by.display_name == "string"