Skip to content

Commit 41990f6

Browse files
committed
Add moq publisher/subscriber endpoints
1 parent 2f18378 commit 41990f6

File tree

7 files changed

+457
-0
lines changed

7 files changed

+457
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Contains endpoint functions for accessing the API"""
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
from http import HTTPStatus
2+
from typing import Any
3+
from urllib.parse import quote
4+
5+
import httpx
6+
7+
from ... import errors
8+
from ...client import AuthenticatedClient, Client
9+
from ...models.error import Error
10+
from ...models.moq_token import MoqToken
11+
from ...types import Response
12+
13+
14+
def _get_kwargs(
15+
stream_id: str,
16+
) -> dict[str, Any]:
17+
_kwargs: dict[str, Any] = {
18+
"method": "post",
19+
"url": "/moq/{stream_id}/publisher".format(
20+
stream_id=quote(str(stream_id), safe=""),
21+
),
22+
}
23+
24+
return _kwargs
25+
26+
27+
def _parse_response(
28+
*, client: AuthenticatedClient | Client, response: httpx.Response
29+
) -> Error | MoqToken | None:
30+
if response.status_code == 200:
31+
response_200 = MoqToken.from_dict(response.json())
32+
33+
return response_200
34+
35+
if response.status_code == 401:
36+
response_401 = Error.from_dict(response.json())
37+
38+
return response_401
39+
40+
if response.status_code == 503:
41+
response_503 = Error.from_dict(response.json())
42+
43+
return response_503
44+
45+
if client.raise_on_unexpected_status:
46+
raise errors.UnexpectedStatus(response.status_code, response.content)
47+
else:
48+
return None
49+
50+
51+
def _build_response(
52+
*, client: AuthenticatedClient | Client, response: httpx.Response
53+
) -> Response[Error | MoqToken]:
54+
return Response(
55+
status_code=HTTPStatus(response.status_code),
56+
content=response.content,
57+
headers=response.headers,
58+
parsed=_parse_response(client=client, response=response),
59+
)
60+
61+
62+
def sync_detailed(
63+
stream_id: str,
64+
*,
65+
client: AuthenticatedClient,
66+
) -> Response[Error | MoqToken]:
67+
"""Creates a MoQ publisher token for the given stream
68+
69+
Args:
70+
stream_id (str):
71+
72+
Raises:
73+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
74+
httpx.TimeoutException: If the request takes longer than Client.timeout.
75+
76+
Returns:
77+
Response[Error | MoqToken]
78+
"""
79+
80+
kwargs = _get_kwargs(
81+
stream_id=stream_id,
82+
)
83+
84+
response = client.get_httpx_client().request(
85+
**kwargs,
86+
)
87+
88+
return _build_response(client=client, response=response)
89+
90+
91+
def sync(
92+
stream_id: str,
93+
*,
94+
client: AuthenticatedClient,
95+
) -> Error | MoqToken | None:
96+
"""Creates a MoQ publisher token for the given stream
97+
98+
Args:
99+
stream_id (str):
100+
101+
Raises:
102+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
103+
httpx.TimeoutException: If the request takes longer than Client.timeout.
104+
105+
Returns:
106+
Error | MoqToken
107+
"""
108+
109+
return sync_detailed(
110+
stream_id=stream_id,
111+
client=client,
112+
).parsed
113+
114+
115+
async def asyncio_detailed(
116+
stream_id: str,
117+
*,
118+
client: AuthenticatedClient,
119+
) -> Response[Error | MoqToken]:
120+
"""Creates a MoQ publisher token for the given stream
121+
122+
Args:
123+
stream_id (str):
124+
125+
Raises:
126+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
127+
httpx.TimeoutException: If the request takes longer than Client.timeout.
128+
129+
Returns:
130+
Response[Error | MoqToken]
131+
"""
132+
133+
kwargs = _get_kwargs(
134+
stream_id=stream_id,
135+
)
136+
137+
response = await client.get_async_httpx_client().request(**kwargs)
138+
139+
return _build_response(client=client, response=response)
140+
141+
142+
async def asyncio(
143+
stream_id: str,
144+
*,
145+
client: AuthenticatedClient,
146+
) -> Error | MoqToken | None:
147+
"""Creates a MoQ publisher token for the given stream
148+
149+
Args:
150+
stream_id (str):
151+
152+
Raises:
153+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
154+
httpx.TimeoutException: If the request takes longer than Client.timeout.
155+
156+
Returns:
157+
Error | MoqToken
158+
"""
159+
160+
return (
161+
await asyncio_detailed(
162+
stream_id=stream_id,
163+
client=client,
164+
)
165+
).parsed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
from http import HTTPStatus
2+
from typing import Any
3+
from urllib.parse import quote
4+
5+
import httpx
6+
7+
from ... import errors
8+
from ...client import AuthenticatedClient, Client
9+
from ...models.error import Error
10+
from ...models.moq_token import MoqToken
11+
from ...types import Response
12+
13+
14+
def _get_kwargs(
15+
stream_id: str,
16+
) -> dict[str, Any]:
17+
_kwargs: dict[str, Any] = {
18+
"method": "post",
19+
"url": "/moq/{stream_id}/subscriber".format(
20+
stream_id=quote(str(stream_id), safe=""),
21+
),
22+
}
23+
24+
return _kwargs
25+
26+
27+
def _parse_response(
28+
*, client: AuthenticatedClient | Client, response: httpx.Response
29+
) -> Error | MoqToken | None:
30+
if response.status_code == 200:
31+
response_200 = MoqToken.from_dict(response.json())
32+
33+
return response_200
34+
35+
if response.status_code == 401:
36+
response_401 = Error.from_dict(response.json())
37+
38+
return response_401
39+
40+
if response.status_code == 503:
41+
response_503 = Error.from_dict(response.json())
42+
43+
return response_503
44+
45+
if client.raise_on_unexpected_status:
46+
raise errors.UnexpectedStatus(response.status_code, response.content)
47+
else:
48+
return None
49+
50+
51+
def _build_response(
52+
*, client: AuthenticatedClient | Client, response: httpx.Response
53+
) -> Response[Error | MoqToken]:
54+
return Response(
55+
status_code=HTTPStatus(response.status_code),
56+
content=response.content,
57+
headers=response.headers,
58+
parsed=_parse_response(client=client, response=response),
59+
)
60+
61+
62+
def sync_detailed(
63+
stream_id: str,
64+
*,
65+
client: AuthenticatedClient,
66+
) -> Response[Error | MoqToken]:
67+
"""Creates a MoQ subscriber token for the given stream
68+
69+
Args:
70+
stream_id (str):
71+
72+
Raises:
73+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
74+
httpx.TimeoutException: If the request takes longer than Client.timeout.
75+
76+
Returns:
77+
Response[Error | MoqToken]
78+
"""
79+
80+
kwargs = _get_kwargs(
81+
stream_id=stream_id,
82+
)
83+
84+
response = client.get_httpx_client().request(
85+
**kwargs,
86+
)
87+
88+
return _build_response(client=client, response=response)
89+
90+
91+
def sync(
92+
stream_id: str,
93+
*,
94+
client: AuthenticatedClient,
95+
) -> Error | MoqToken | None:
96+
"""Creates a MoQ subscriber token for the given stream
97+
98+
Args:
99+
stream_id (str):
100+
101+
Raises:
102+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
103+
httpx.TimeoutException: If the request takes longer than Client.timeout.
104+
105+
Returns:
106+
Error | MoqToken
107+
"""
108+
109+
return sync_detailed(
110+
stream_id=stream_id,
111+
client=client,
112+
).parsed
113+
114+
115+
async def asyncio_detailed(
116+
stream_id: str,
117+
*,
118+
client: AuthenticatedClient,
119+
) -> Response[Error | MoqToken]:
120+
"""Creates a MoQ subscriber token for the given stream
121+
122+
Args:
123+
stream_id (str):
124+
125+
Raises:
126+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
127+
httpx.TimeoutException: If the request takes longer than Client.timeout.
128+
129+
Returns:
130+
Response[Error | MoqToken]
131+
"""
132+
133+
kwargs = _get_kwargs(
134+
stream_id=stream_id,
135+
)
136+
137+
response = await client.get_async_httpx_client().request(**kwargs)
138+
139+
return _build_response(client=client, response=response)
140+
141+
142+
async def asyncio(
143+
stream_id: str,
144+
*,
145+
client: AuthenticatedClient,
146+
) -> Error | MoqToken | None:
147+
"""Creates a MoQ subscriber token for the given stream
148+
149+
Args:
150+
stream_id (str):
151+
152+
Raises:
153+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
154+
httpx.TimeoutException: If the request takes longer than Client.timeout.
155+
156+
Returns:
157+
Error | MoqToken
158+
"""
159+
160+
return (
161+
await asyncio_detailed(
162+
stream_id=stream_id,
163+
client=client,
164+
)
165+
).parsed

fishjam/_openapi_client/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .audio_sample_rate import AudioSampleRate
66
from .composition_info import CompositionInfo
77
from .error import Error
8+
from .moq_token import MoqToken
89
from .peer import Peer
910
from .peer_config import PeerConfig
1011
from .peer_details_response import PeerDetailsResponse
@@ -52,6 +53,7 @@
5253
"AudioSampleRate",
5354
"CompositionInfo",
5455
"Error",
56+
"MoqToken",
5557
"Peer",
5658
"PeerConfig",
5759
"PeerDetailsResponse",

0 commit comments

Comments
 (0)