Skip to content

Commit 2060fee

Browse files
authored
added public ocs method (#187)
Many OCS have not yet been described, but can now be used quite easily using the "osc" method. --------- Signed-off-by: Alexander Piskun <[email protected]>
1 parent 8739f12 commit 2060fee

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

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

5+
## [0.7.1 - 2022-12-2x]
6+
7+
### Added
8+
9+
- The `ocs` method is now public, making it easy to use Nextcloud OCS that has not yet been described. #187
10+
511
## [0.7.0 - 2022-12-17]
612

713
### Added

nc_py_api/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Version of nc_py_api."""
22

3-
__version__ = "0.7.0"
3+
__version__ = "0.7.1.dev0"

nc_py_api/nextcloud.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Nextcloud class providing access to all API endpoints."""
22

3+
import typing
34
from abc import ABC
45

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

116+
def ocs(
117+
self,
118+
method: str,
119+
path: str,
120+
*,
121+
content: bytes | str | typing.Iterable[bytes] | typing.AsyncIterable[bytes] | None = None,
122+
json: dict | list | None = None,
123+
params: dict | None = None,
124+
**kwargs,
125+
):
126+
"""Performs OCS call and returns OCS response payload data."""
127+
return self._session.ocs(method, path, content=content, json=json, params=params, **kwargs)
128+
115129

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

202+
async def ocs(
203+
self,
204+
method: str,
205+
path: str,
206+
*,
207+
content: bytes | str | typing.Iterable[bytes] | typing.AsyncIterable[bytes] | None = None,
208+
json: dict | list | None = None,
209+
params: dict | None = None,
210+
**kwargs,
211+
):
212+
"""Performs OCS call and returns OCS response payload data."""
213+
return await self._session.ocs(method, path, content=content, json=json, params=params, **kwargs)
214+
188215

189216
class Nextcloud(_NextcloudBasic):
190217
"""Nextcloud client class.

tests/actual_tests/misc_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,16 @@ async def test_ocs_timeout_async(anc_any):
167167
if e.value.status_code in (500, 996):
168168
pytest.skip("Some network problem on the host")
169169
assert e.value.status_code == 408
170+
171+
172+
def test_public_ocs(nc_any):
173+
r = nc_any.ocs("GET", "/ocs/v1.php/cloud/capabilities")
174+
assert r == nc_any.ocs("GET", "ocs/v1.php/cloud/capabilities")
175+
assert r == nc_any._session.ocs("GET", "ocs/v1.php/cloud/capabilities") # noqa
176+
177+
178+
@pytest.mark.asyncio(scope="session")
179+
async def test_public_ocs_async(anc_any):
180+
r = await anc_any.ocs("GET", "/ocs/v1.php/cloud/capabilities")
181+
assert r == await anc_any.ocs("GET", "ocs/v1.php/cloud/capabilities")
182+
assert r == await anc_any._session.ocs("GET", "ocs/v1.php/cloud/capabilities") # noqa

0 commit comments

Comments
 (0)