Skip to content

Commit a511bb0

Browse files
authored
Add schemes endpoint (#179)
1 parent f554cb3 commit a511bb0

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

go2rtc_client/rest.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
_LOGGER = logging.getLogger(__name__)
2323

2424
_API_PREFIX = "/api"
25-
_MIN_VERSION_SUPPORTED: Final = AwesomeVersion("1.9.5")
25+
_MIN_VERSION_SUPPORTED: Final = AwesomeVersion("1.9.12")
2626
_MIN_VERSION_UNSUPPORTED: Final = AwesomeVersion("2.0.0")
2727

2828

@@ -141,13 +141,29 @@ async def list(self) -> dict[str, Stream]:
141141
return _GET_STREAMS_DECODER.decode(await resp.json())
142142

143143

144+
class _SchemesClient:
145+
PATH: Final = _API_PREFIX + "/schemes"
146+
_DECODER = BasicDecoder(set[str])
147+
148+
def __init__(self, client: _BaseClient) -> None:
149+
"""Initialize Client."""
150+
self._client = client
151+
152+
@handle_error
153+
async def list(self) -> set[str]:
154+
"""List all supported schemes."""
155+
resp = await self._client.request("GET", self.PATH)
156+
return self._DECODER.decode(await resp.json())
157+
158+
144159
class Go2RtcRestClient:
145160
"""Rest client for go2rtc server."""
146161

147162
def __init__(self, websession: ClientSession, server_url: str) -> None:
148163
"""Initialize Client."""
149164
self._client = _BaseClient(websession, server_url)
150165
self.application: Final = _ApplicationClient(self._client)
166+
self.schemes: Final = _SchemesClient(self._client)
151167
self.streams: Final = _StreamClient(self._client)
152168
self.webrtc: Final = _WebRTCClient(self._client)
153169

tests/__snapshots__/test_rest.ambr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
'version': '1.9.4',
1010
})
1111
# ---
12+
# name: test_schemes
13+
set({
14+
'exec',
15+
'ffmpeg',
16+
'rtsp',
17+
'rtsps',
18+
'rtspx',
19+
'webrtc',
20+
})
21+
# ---
1222
# name: test_streams_get[empty]
1323
dict({
1424
})

tests/test_rest.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from go2rtc_client.rest import (
1717
_API_PREFIX,
1818
_ApplicationClient,
19+
_SchemesClient,
1920
_StreamClient,
2021
_WebRTCClient,
2122
)
@@ -134,16 +135,17 @@ async def test_streams_add_str(
134135
)
135136

136137

137-
VERSION_ERR = "server version '{}' not >= 1.9.5 and < 2.0.0"
138+
VERSION_ERR = "server version '{}' not >= 1.9.12 and < 2.0.0"
138139

139140

140141
@pytest.mark.parametrize(
141142
("server_version", "expected_result"),
142143
[
143144
("0.0.0", pytest.raises(Go2RtcVersionError, match=VERSION_ERR.format("0.0.0"))),
144-
("1.9.4", pytest.raises(Go2RtcVersionError, match=VERSION_ERR.format("1.9.4"))),
145-
("1.9.5", does_not_raise()),
146-
("1.9.6", does_not_raise()),
145+
("1.9.5", pytest.raises(Go2RtcVersionError, match=VERSION_ERR.format("1.9.5"))),
146+
("1.9.6", pytest.raises(Go2RtcVersionError, match=VERSION_ERR.format("1.9.6"))),
147+
("1.9.12", does_not_raise()),
148+
("1.9.13", does_not_raise()),
147149
("2.0.0", pytest.raises(Go2RtcVersionError, match=VERSION_ERR.format("2.0.0"))),
148150
("BLAH", pytest.raises(Go2RtcVersionError, match=VERSION_ERR.format("BLAH"))),
149151
],
@@ -220,3 +222,18 @@ async def test_get_jpeg_snapshot(
220222
assert isinstance(resp, bytes)
221223

222224
assert resp == image_bytes
225+
226+
227+
async def test_schemes(
228+
responses: aioresponses,
229+
rest_client: Go2RtcRestClient,
230+
snapshot: SnapshotAssertion,
231+
) -> None:
232+
"""Test schemes."""
233+
responses.get(
234+
f"{URL}{_SchemesClient.PATH}",
235+
status=200,
236+
body=json.dumps(["webrtc", "exec", "ffmpeg", "rtsp", "rtsps", "rtspx"]),
237+
)
238+
resp = await rest_client.schemes.list()
239+
assert resp == snapshot

0 commit comments

Comments
 (0)