From c66b2b99b8509ed0f19209c8d884d43fa1fa29ac Mon Sep 17 00:00:00 2001 From: Jana Peper Date: Mon, 17 Mar 2025 15:29:09 +0100 Subject: [PATCH 1/2] fix: handle JSON responses Signed-off-by: Jana Peper --- nc_py_api/_session.py | 6 ++++++ nc_py_api/nextcloud.py | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/nc_py_api/_session.py b/nc_py_api/_session.py index f4bc66cc..ecedd7da 100644 --- a/nc_py_api/_session.py +++ b/nc_py_api/_session.py @@ -197,6 +197,7 @@ def ocs( *, content: bytes | str | typing.Iterable[bytes] | typing.AsyncIterable[bytes] | None = None, json: dict | list | None = None, + response_type: str | None = None, params: dict | None = None, files: dict | None = None, **kwargs, @@ -215,6 +216,8 @@ def ocs( if response.status_code == 204: # NO_CONTENT return [] response_data = loads(response.text) + if response_type == "json": + return response_data ocs_meta = response_data["ocs"]["meta"] if ocs_meta["status"] != "ok": if ( @@ -319,6 +322,7 @@ async def ocs( *, content: bytes | str | typing.Iterable[bytes] | typing.AsyncIterable[bytes] | None = None, json: dict | list | None = None, + response_type: str | None = None, params: dict | None = None, files: dict | None = None, **kwargs, @@ -337,6 +341,8 @@ async def ocs( if response.status_code == 204: # NO_CONTENT return [] response_data = loads(response.text) + if response_type == "json": + return response_data ocs_meta = response_data["ocs"]["meta"] if ocs_meta["status"] != "ok": if ( diff --git a/nc_py_api/nextcloud.py b/nc_py_api/nextcloud.py index 97eee898..9ca03828 100644 --- a/nc_py_api/nextcloud.py +++ b/nc_py_api/nextcloud.py @@ -137,11 +137,14 @@ def ocs( *, content: bytes | str | typing.Iterable[bytes] | typing.AsyncIterable[bytes] | None = None, json: dict | list | None = None, + response_type: str | None = None, params: dict | None = None, **kwargs, ): """Performs OCS call and returns OCS response payload data.""" - return self._session.ocs(method, path, content=content, json=json, params=params, **kwargs) + return self._session.ocs( + method, path, content=content, json=json, response_type=response_type, params=params, **kwargs + ) def download_log(self, fp) -> None: """Downloads Nextcloud log file. Requires Admin privileges.""" @@ -238,11 +241,14 @@ async def ocs( *, content: bytes | str | typing.Iterable[bytes] | typing.AsyncIterable[bytes] | None = None, json: dict | list | None = None, + response_type: str | None = None, params: dict | None = None, **kwargs, ): """Performs OCS call and returns OCS response payload data.""" - return await self._session.ocs(method, path, content=content, json=json, params=params, **kwargs) + return await self._session.ocs( + method, path, content=content, json=json, response_type=response_type, params=params, **kwargs + ) async def download_log(self, fp) -> None: """Downloads Nextcloud log file. Requires Admin privileges.""" From 55d2e09d217389e947d9ccd62a0b64c502ebaaf7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 17 Mar 2025 15:42:52 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- nc_py_api/nextcloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nc_py_api/nextcloud.py b/nc_py_api/nextcloud.py index 9ca03828..09b6eb07 100644 --- a/nc_py_api/nextcloud.py +++ b/nc_py_api/nextcloud.py @@ -248,7 +248,7 @@ async def ocs( """Performs OCS call and returns OCS response payload data.""" return await self._session.ocs( method, path, content=content, json=json, response_type=response_type, params=params, **kwargs - ) + ) async def download_log(self, fp) -> None: """Downloads Nextcloud log file. Requires Admin privileges."""