diff --git a/CHANGELOG.md b/CHANGELOG.md index aa270781..1cf0dfdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. ### Added - `VERIFY_NC_CERTIFICATE` option. +- `apps.ex_app_get_list` and `apps.ex_app_get_info` methods. ## [0.0.23 - 2023-07-07] diff --git a/nc_py_api/apps.py b/nc_py_api/apps.py index ed2b5218..90285576 100644 --- a/nc_py_api/apps.py +++ b/nc_py_api/apps.py @@ -2,13 +2,24 @@ Nextcloud API for working with applications. """ -from typing import Optional +from typing import Optional, TypedDict from ._session import NcSessionBasic +from .constants import APP_V2_BASIC_URL +from .misc import require_capabilities ENDPOINT = "/ocs/v1.php/cloud/apps" +class ExAppInfo(TypedDict): + id: str + name: str + version: str + enabled: bool + last_response_time: int + system: bool + + class AppAPI: def __init__(self, session: NcSessionBasic): self._session = session @@ -44,3 +55,15 @@ def is_disabled(self, app_name: str) -> bool: if not app_name: raise ValueError("`app_name` parameter can not be empty") return app_name in self.get_list(enabled=False) + + def ex_app_get_list(self) -> list[str]: + """Gets list of the external applications installed on the server.""" + + require_capabilities("app_ecosystem_v2", self._session.capabilities) + return self._session.ocs(method="GET", path=f"{APP_V2_BASIC_URL}/ex-app/all", params={"extended": 0}) + + def ex_app_get_info(self) -> list[ExAppInfo]: + """Gets information of the external applications installed on the server.""" + + require_capabilities("app_ecosystem_v2", self._session.capabilities) + return self._session.ocs(method="GET", path=f"{APP_V2_BASIC_URL}/ex-app/all", params={"extended": 1}) diff --git a/tests/apps_test.py b/tests/apps_test.py index 81369bfe..d7640271 100644 --- a/tests/apps_test.py +++ b/tests/apps_test.py @@ -47,3 +47,27 @@ def test_invalid_param(nc): nc.apps.enable("") with pytest.raises(ValueError): nc.apps.disable("") + + +@pytest.mark.parametrize("nc", NC_TO_TEST) +def test_ex_app_get_list(nc): + if "app_ecosystem_v2" not in nc.capabilities: + pytest.skip("app_ecosystem_v2 is not installed.") + ex_apps = nc.apps.ex_app_get_list() + assert isinstance(ex_apps, list) + assert isinstance(ex_apps[0], str) + + +@pytest.mark.parametrize("nc", NC_TO_TEST) +def test_ex_app_get_info(nc): + if "app_ecosystem_v2" not in nc.capabilities: + pytest.skip("app_ecosystem_v2 is not installed.") + ex_apps = nc.apps.ex_app_get_info() + assert isinstance(ex_apps, list) + nc_py_api = [i for i in ex_apps if i["id"] == "nc_py_api"][0] + assert nc_py_api["id"] == "nc_py_api" + assert isinstance(nc_py_api["name"], str) + assert isinstance(nc_py_api["version"], str) + assert nc_py_api["enabled"] + assert isinstance(nc_py_api["last_response_time"], int) + assert nc_py_api["system"]