Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## [0.7.1 - 2022-12-2x]

### Added

- The `ocs` method is now public, making it easy to use Nextcloud OCS that has not yet been described. #187

## [0.7.0 - 2022-12-17]

### Added
Expand Down
2 changes: 1 addition & 1 deletion nc_py_api/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version of nc_py_api."""

__version__ = "0.7.0"
__version__ = "0.7.1.dev0"
27 changes: 27 additions & 0 deletions nc_py_api/nextcloud.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Nextcloud class providing access to all API endpoints."""

import typing
from abc import ABC

from fastapi import Request as FastAPIRequest
Expand Down Expand Up @@ -112,6 +113,19 @@ def theme(self) -> ThemingInfo | None:
"""Returns Theme information."""
return get_parsed_theme(self.capabilities["theming"]) if "theming" in self.capabilities else None

def ocs(
self,
method: str,
path: str,
*,
content: bytes | str | typing.Iterable[bytes] | typing.AsyncIterable[bytes] | None = None,
json: dict | list | 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)


class _AsyncNextcloudBasic(ABC): # pylint: disable=too-many-instance-attributes
apps: _AsyncAppsAPI
Expand Down Expand Up @@ -185,6 +199,19 @@ async def theme(self) -> ThemingInfo | None:
"""Returns Theme information."""
return get_parsed_theme((await self.capabilities)["theming"]) if "theming" in await self.capabilities else None

async def ocs(
self,
method: str,
path: str,
*,
content: bytes | str | typing.Iterable[bytes] | typing.AsyncIterable[bytes] | None = None,
json: dict | list | 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)


class Nextcloud(_NextcloudBasic):
"""Nextcloud client class.
Expand Down
13 changes: 13 additions & 0 deletions tests/actual_tests/misc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,16 @@ async def test_ocs_timeout_async(anc_any):
if e.value.status_code in (500, 996):
pytest.skip("Some network problem on the host")
assert e.value.status_code == 408


def test_public_ocs(nc_any):
r = nc_any.ocs("GET", "/ocs/v1.php/cloud/capabilities")
assert r == nc_any.ocs("GET", "ocs/v1.php/cloud/capabilities")
assert r == nc_any._session.ocs("GET", "ocs/v1.php/cloud/capabilities") # noqa


@pytest.mark.asyncio(scope="session")
async def test_public_ocs_async(anc_any):
r = await anc_any.ocs("GET", "/ocs/v1.php/cloud/capabilities")
assert r == await anc_any.ocs("GET", "ocs/v1.php/cloud/capabilities")
assert r == await anc_any._session.ocs("GET", "ocs/v1.php/cloud/capabilities") # noqa