Skip to content

Commit 7604b08

Browse files
Streamer tokens in sdk (#32)
* Update protos * Add streamer tokens
1 parent 6043052 commit 7604b08

File tree

11 files changed

+401
-10
lines changed

11 files changed

+401
-10
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ Documentation is generated via openapi-python-client.
141141

142142
To update documentation you need to:
143143

144-
- in `poetry_scripts.py` change branch from which openapi.yaml should be downloaded
145-
- run `poetry run update-client`
144+
- Go to https://github.com/fishjam-cloud/fishjam/blob/main/openapi.yaml and open the raw file.
145+
- Copy the URL.
146+
- Run `poetry run update_client <copied-url>`
146147

147148
## License
148149

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
from http import HTTPStatus
2+
from typing import Any, Dict, Optional, Union, cast
3+
4+
import httpx
5+
6+
from ... import errors
7+
from ...client import AuthenticatedClient, Client
8+
from ...models.error import Error
9+
from ...types import Response
10+
11+
12+
def _get_kwargs() -> Dict[str, Any]:
13+
return {
14+
"method": "post",
15+
"url": "/notifications",
16+
}
17+
18+
19+
def _parse_response(
20+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
21+
) -> Optional[Union[Any, Error]]:
22+
if response.status_code == HTTPStatus.NO_CONTENT:
23+
response_204 = cast(Any, None)
24+
return response_204
25+
if response.status_code == HTTPStatus.UNAUTHORIZED:
26+
response_401 = Error.from_dict(response.json())
27+
28+
return response_401
29+
if response.status_code == HTTPStatus.NOT_FOUND:
30+
response_404 = Error.from_dict(response.json())
31+
32+
return response_404
33+
if client.raise_on_unexpected_status:
34+
raise errors.UnexpectedStatus(response.status_code, response.content)
35+
else:
36+
return None
37+
38+
39+
def _build_response(
40+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
41+
) -> Response[Union[Any, Error]]:
42+
return Response(
43+
status_code=HTTPStatus(response.status_code),
44+
content=response.content,
45+
headers=response.headers,
46+
parsed=_parse_response(client=client, response=response),
47+
)
48+
49+
50+
def sync_detailed(
51+
*,
52+
client: Union[AuthenticatedClient, Client],
53+
) -> Response[Union[Any, Error]]:
54+
"""Handle notification from broadcaster
55+
56+
Raises:
57+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
58+
httpx.TimeoutException: If the request takes longer than Client.timeout.
59+
60+
Returns:
61+
Response[Union[Any, Error]]
62+
"""
63+
64+
kwargs = _get_kwargs()
65+
66+
response = client.get_httpx_client().request(
67+
**kwargs,
68+
)
69+
70+
return _build_response(client=client, response=response)
71+
72+
73+
def sync(
74+
*,
75+
client: Union[AuthenticatedClient, Client],
76+
) -> Optional[Union[Any, Error]]:
77+
"""Handle notification from broadcaster
78+
79+
Raises:
80+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
81+
httpx.TimeoutException: If the request takes longer than Client.timeout.
82+
83+
Returns:
84+
Union[Any, Error]
85+
"""
86+
87+
return sync_detailed(
88+
client=client,
89+
).parsed
90+
91+
92+
async def asyncio_detailed(
93+
*,
94+
client: Union[AuthenticatedClient, Client],
95+
) -> Response[Union[Any, Error]]:
96+
"""Handle notification from broadcaster
97+
98+
Raises:
99+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
100+
httpx.TimeoutException: If the request takes longer than Client.timeout.
101+
102+
Returns:
103+
Response[Union[Any, Error]]
104+
"""
105+
106+
kwargs = _get_kwargs()
107+
108+
response = await client.get_async_httpx_client().request(**kwargs)
109+
110+
return _build_response(client=client, response=response)
111+
112+
113+
async def asyncio(
114+
*,
115+
client: Union[AuthenticatedClient, Client],
116+
) -> Optional[Union[Any, Error]]:
117+
"""Handle notification from broadcaster
118+
119+
Raises:
120+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
121+
httpx.TimeoutException: If the request takes longer than Client.timeout.
122+
123+
Returns:
124+
Union[Any, Error]
125+
"""
126+
127+
return (
128+
await asyncio_detailed(
129+
client=client,
130+
)
131+
).parsed

fishjam/_openapi_client/api/streamer/__init__.py

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

fishjam/_openapi_client/api/viewer/generate_token.py renamed to fishjam/_openapi_client/api/viewer/generate_viewer_token.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def sync_detailed(
6666
*,
6767
client: Union[AuthenticatedClient, Client],
6868
) -> Response[Union[Error, ViewerToken]]:
69-
"""Generate single livestream access token
69+
"""Generates token that a viewer can use to watch a livestream
7070
7171
Args:
7272
room_id (str):
@@ -95,7 +95,7 @@ def sync(
9595
*,
9696
client: Union[AuthenticatedClient, Client],
9797
) -> Optional[Union[Error, ViewerToken]]:
98-
"""Generate single livestream access token
98+
"""Generates token that a viewer can use to watch a livestream
9999
100100
Args:
101101
room_id (str):
@@ -119,7 +119,7 @@ async def asyncio_detailed(
119119
*,
120120
client: Union[AuthenticatedClient, Client],
121121
) -> Response[Union[Error, ViewerToken]]:
122-
"""Generate single livestream access token
122+
"""Generates token that a viewer can use to watch a livestream
123123
124124
Args:
125125
room_id (str):
@@ -146,7 +146,7 @@ async def asyncio(
146146
*,
147147
client: Union[AuthenticatedClient, Client],
148148
) -> Optional[Union[Error, ViewerToken]]:
149-
"""Generate single livestream access token
149+
"""Generates token that a viewer can use to watch a livestream
150150
151151
Args:
152152
room_id (str):

fishjam/_openapi_client/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
from .shutdown_status import ShutdownStatus
6464
from .shutdown_status_response import ShutdownStatusResponse
6565
from .sip_credentials import SIPCredentials
66+
from .streamer_token import StreamerToken
6667
from .subscription_config import SubscriptionConfig
6768
from .track import Track
6869
from .track_type import TrackType
@@ -126,6 +127,7 @@
126127
"ShutdownStatus",
127128
"ShutdownStatusResponse",
128129
"SIPCredentials",
130+
"StreamerToken",
129131
"SubscriptionConfig",
130132
"Track",
131133
"TrackType",

0 commit comments

Comments
 (0)