|
| 1 | +from http import HTTPStatus |
| 2 | +from typing import Any, 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 UNSET, Response, Unset |
| 10 | + |
| 11 | + |
| 12 | +def _get_kwargs( |
| 13 | + room_id: str, |
| 14 | + id: str, |
| 15 | + *, |
| 16 | + peer_id: Union[Unset, str] = UNSET, |
| 17 | +) -> dict[str, Any]: |
| 18 | + params: dict[str, Any] = {} |
| 19 | + |
| 20 | + params["peer_id"] = peer_id |
| 21 | + |
| 22 | + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} |
| 23 | + |
| 24 | + _kwargs: dict[str, Any] = { |
| 25 | + "method": "post", |
| 26 | + "url": "/room/{room_id}/peer/{id}/subscribe_peer".format( |
| 27 | + room_id=room_id, |
| 28 | + id=id, |
| 29 | + ), |
| 30 | + "params": params, |
| 31 | + } |
| 32 | + |
| 33 | + return _kwargs |
| 34 | + |
| 35 | + |
| 36 | +def _parse_response( |
| 37 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 38 | +) -> Optional[Union[Any, Error]]: |
| 39 | + if response.status_code == 200: |
| 40 | + response_200 = cast(Any, None) |
| 41 | + return response_200 |
| 42 | + if response.status_code == 400: |
| 43 | + response_400 = Error.from_dict(response.json()) |
| 44 | + |
| 45 | + return response_400 |
| 46 | + if response.status_code == 401: |
| 47 | + response_401 = Error.from_dict(response.json()) |
| 48 | + |
| 49 | + return response_401 |
| 50 | + if response.status_code == 404: |
| 51 | + response_404 = Error.from_dict(response.json()) |
| 52 | + |
| 53 | + return response_404 |
| 54 | + if response.status_code == 503: |
| 55 | + response_503 = Error.from_dict(response.json()) |
| 56 | + |
| 57 | + return response_503 |
| 58 | + if client.raise_on_unexpected_status: |
| 59 | + raise errors.UnexpectedStatus(response.status_code, response.content) |
| 60 | + else: |
| 61 | + return None |
| 62 | + |
| 63 | + |
| 64 | +def _build_response( |
| 65 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 66 | +) -> Response[Union[Any, Error]]: |
| 67 | + return Response( |
| 68 | + status_code=HTTPStatus(response.status_code), |
| 69 | + content=response.content, |
| 70 | + headers=response.headers, |
| 71 | + parsed=_parse_response(client=client, response=response), |
| 72 | + ) |
| 73 | + |
| 74 | + |
| 75 | +def sync_detailed( |
| 76 | + room_id: str, |
| 77 | + id: str, |
| 78 | + *, |
| 79 | + client: AuthenticatedClient, |
| 80 | + peer_id: Union[Unset, str] = UNSET, |
| 81 | +) -> Response[Union[Any, Error]]: |
| 82 | + """Subscribe peer to another peer's tracks |
| 83 | +
|
| 84 | + Args: |
| 85 | + room_id (str): |
| 86 | + id (str): |
| 87 | + peer_id (Union[Unset, str]): |
| 88 | +
|
| 89 | + Raises: |
| 90 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 91 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 92 | +
|
| 93 | + Returns: |
| 94 | + Response[Union[Any, Error]] |
| 95 | + """ |
| 96 | + |
| 97 | + kwargs = _get_kwargs( |
| 98 | + room_id=room_id, |
| 99 | + id=id, |
| 100 | + peer_id=peer_id, |
| 101 | + ) |
| 102 | + |
| 103 | + response = client.get_httpx_client().request( |
| 104 | + **kwargs, |
| 105 | + ) |
| 106 | + |
| 107 | + return _build_response(client=client, response=response) |
| 108 | + |
| 109 | + |
| 110 | +def sync( |
| 111 | + room_id: str, |
| 112 | + id: str, |
| 113 | + *, |
| 114 | + client: AuthenticatedClient, |
| 115 | + peer_id: Union[Unset, str] = UNSET, |
| 116 | +) -> Optional[Union[Any, Error]]: |
| 117 | + """Subscribe peer to another peer's tracks |
| 118 | +
|
| 119 | + Args: |
| 120 | + room_id (str): |
| 121 | + id (str): |
| 122 | + peer_id (Union[Unset, str]): |
| 123 | +
|
| 124 | + Raises: |
| 125 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 126 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 127 | +
|
| 128 | + Returns: |
| 129 | + Union[Any, Error] |
| 130 | + """ |
| 131 | + |
| 132 | + return sync_detailed( |
| 133 | + room_id=room_id, |
| 134 | + id=id, |
| 135 | + client=client, |
| 136 | + peer_id=peer_id, |
| 137 | + ).parsed |
| 138 | + |
| 139 | + |
| 140 | +async def asyncio_detailed( |
| 141 | + room_id: str, |
| 142 | + id: str, |
| 143 | + *, |
| 144 | + client: AuthenticatedClient, |
| 145 | + peer_id: Union[Unset, str] = UNSET, |
| 146 | +) -> Response[Union[Any, Error]]: |
| 147 | + """Subscribe peer to another peer's tracks |
| 148 | +
|
| 149 | + Args: |
| 150 | + room_id (str): |
| 151 | + id (str): |
| 152 | + peer_id (Union[Unset, 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 | + Response[Union[Any, Error]] |
| 160 | + """ |
| 161 | + |
| 162 | + kwargs = _get_kwargs( |
| 163 | + room_id=room_id, |
| 164 | + id=id, |
| 165 | + peer_id=peer_id, |
| 166 | + ) |
| 167 | + |
| 168 | + response = await client.get_async_httpx_client().request(**kwargs) |
| 169 | + |
| 170 | + return _build_response(client=client, response=response) |
| 171 | + |
| 172 | + |
| 173 | +async def asyncio( |
| 174 | + room_id: str, |
| 175 | + id: str, |
| 176 | + *, |
| 177 | + client: AuthenticatedClient, |
| 178 | + peer_id: Union[Unset, str] = UNSET, |
| 179 | +) -> Optional[Union[Any, Error]]: |
| 180 | + """Subscribe peer to another peer's tracks |
| 181 | +
|
| 182 | + Args: |
| 183 | + room_id (str): |
| 184 | + id (str): |
| 185 | + peer_id (Union[Unset, str]): |
| 186 | +
|
| 187 | + Raises: |
| 188 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 189 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 190 | +
|
| 191 | + Returns: |
| 192 | + Union[Any, Error] |
| 193 | + """ |
| 194 | + |
| 195 | + return ( |
| 196 | + await asyncio_detailed( |
| 197 | + room_id=room_id, |
| 198 | + id=id, |
| 199 | + client=client, |
| 200 | + peer_id=peer_id, |
| 201 | + ) |
| 202 | + ).parsed |
0 commit comments