diff --git a/CHANGELOG.md b/CHANGELOG.md index e0e92481..6f0e0796 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,14 @@ All notable changes to this project will be documented in this file. ## [0.4.0 - 2023-10-2x] +As the project moves closer to `beta`, final unification changes are being made. This release contains some breaking changes in `users` API. ### Changed -- `users.get_details` renamed to `get_user` and returns a class instead of a dictionary. +- `users.get_details` renamed to `get_user` and returns a class instead of a dictionary. #145 - Optional argument `displayname` in `users.create` renamed to `display_name`. +- The `apps.ExAppInfo` class has been rewritten in the same format as all the others. ### Fixed diff --git a/nc_py_api/apps.py b/nc_py_api/apps.py index dfac3a76..2a28245e 100644 --- a/nc_py_api/apps.py +++ b/nc_py_api/apps.py @@ -1,6 +1,7 @@ """Nextcloud API for working with applications.""" import dataclasses +import datetime import typing from ._misc import require_capabilities @@ -11,26 +12,40 @@ class ExAppInfo: """Information about the External Application.""" - app_id: str - """`ID` of the application""" - name: str - """Display name""" - version: str - """Version of the application""" - enabled: bool - """Flag indicating if the application enabled""" - last_check_time: int - """UTC time of last successful application check""" - system: bool - """Flag indicating if the application is a system application""" - def __init__(self, raw_data: dict): - self.app_id = raw_data["id"] - self.name = raw_data["name"] - self.version = raw_data["version"] - self.enabled = bool(raw_data["enabled"]) - self.last_check_time = raw_data["last_check_time"] - self.system = raw_data["system"] + self._raw_data = raw_data + + @property + def app_id(self) -> str: + """`ID` of the application.""" + return self._raw_data["id"] + + @property + def name(self) -> str: + """Display name.""" + return self._raw_data["name"] + + @property + def version(self) -> str: + """Version of the application.""" + return self._raw_data["version"] + + @property + def enabled(self) -> bool: + """Flag indicating if the application enabled.""" + return bool(self._raw_data["enabled"]) + + @property + def last_check_time(self) -> datetime.datetime: + """Time of the last successful application check.""" + return datetime.datetime.utcfromtimestamp(int(self._raw_data["last_check_time"])).replace( + tzinfo=datetime.timezone.utc + ) + + @property + def system(self) -> bool: + """Flag indicating if the application is a system application.""" + return bool(self._raw_data["system"]) class _AppsAPI: diff --git a/tests/actual_tests/apps_test.py b/tests/actual_tests/apps_test.py index fa684250..761be4a9 100644 --- a/tests/actual_tests/apps_test.py +++ b/tests/actual_tests/apps_test.py @@ -1,3 +1,5 @@ +import datetime + import pytest APP_NAME = "files_trashbin" @@ -68,7 +70,7 @@ def test_ex_app_get_list(nc, nc_app): assert isinstance(app.name, str) assert isinstance(app.version, str) assert isinstance(app.enabled, bool) - assert isinstance(app.last_check_time, int) + assert isinstance(app.last_check_time, datetime.datetime) assert isinstance(app.system, bool) if app.app_id == "nc_py_api": assert app.system is True