Skip to content

Commit 5750e9a

Browse files
authored
Adjusted apps.ExAppInfo dataclass. (#146)
Made `ExAppInfo` class to be the in same format as all others. Signed-off-by: Alexander Piskun <[email protected]>
1 parent 13a2abc commit 5750e9a

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ All notable changes to this project will be documented in this file.
44

55
## [0.4.0 - 2023-10-2x]
66

7+
As the project moves closer to `beta`, final unification changes are being made.
78
This release contains some breaking changes in `users` API.
89

910
### Changed
1011

11-
- `users.get_details` renamed to `get_user` and returns a class instead of a dictionary.
12+
- `users.get_details` renamed to `get_user` and returns a class instead of a dictionary. #145
1213
- Optional argument `displayname` in `users.create` renamed to `display_name`.
14+
- The `apps.ExAppInfo` class has been rewritten in the same format as all the others.
1315

1416
### Fixed
1517

nc_py_api/apps.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Nextcloud API for working with applications."""
22

33
import dataclasses
4+
import datetime
45
import typing
56

67
from ._misc import require_capabilities
@@ -11,26 +12,40 @@
1112
class ExAppInfo:
1213
"""Information about the External Application."""
1314

14-
app_id: str
15-
"""`ID` of the application"""
16-
name: str
17-
"""Display name"""
18-
version: str
19-
"""Version of the application"""
20-
enabled: bool
21-
"""Flag indicating if the application enabled"""
22-
last_check_time: int
23-
"""UTC time of last successful application check"""
24-
system: bool
25-
"""Flag indicating if the application is a system application"""
26-
2715
def __init__(self, raw_data: dict):
28-
self.app_id = raw_data["id"]
29-
self.name = raw_data["name"]
30-
self.version = raw_data["version"]
31-
self.enabled = bool(raw_data["enabled"])
32-
self.last_check_time = raw_data["last_check_time"]
33-
self.system = raw_data["system"]
16+
self._raw_data = raw_data
17+
18+
@property
19+
def app_id(self) -> str:
20+
"""`ID` of the application."""
21+
return self._raw_data["id"]
22+
23+
@property
24+
def name(self) -> str:
25+
"""Display name."""
26+
return self._raw_data["name"]
27+
28+
@property
29+
def version(self) -> str:
30+
"""Version of the application."""
31+
return self._raw_data["version"]
32+
33+
@property
34+
def enabled(self) -> bool:
35+
"""Flag indicating if the application enabled."""
36+
return bool(self._raw_data["enabled"])
37+
38+
@property
39+
def last_check_time(self) -> datetime.datetime:
40+
"""Time of the last successful application check."""
41+
return datetime.datetime.utcfromtimestamp(int(self._raw_data["last_check_time"])).replace(
42+
tzinfo=datetime.timezone.utc
43+
)
44+
45+
@property
46+
def system(self) -> bool:
47+
"""Flag indicating if the application is a system application."""
48+
return bool(self._raw_data["system"])
3449

3550

3651
class _AppsAPI:

tests/actual_tests/apps_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import datetime
2+
13
import pytest
24

35
APP_NAME = "files_trashbin"
@@ -68,7 +70,7 @@ def test_ex_app_get_list(nc, nc_app):
6870
assert isinstance(app.name, str)
6971
assert isinstance(app.version, str)
7072
assert isinstance(app.enabled, bool)
71-
assert isinstance(app.last_check_time, int)
73+
assert isinstance(app.last_check_time, datetime.datetime)
7274
assert isinstance(app.system, bool)
7375
if app.app_id == "nc_py_api":
7476
assert app.system is True

0 commit comments

Comments
 (0)