|
| 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.a_model import AModel |
| 9 | +from ...types import Response |
| 10 | + |
| 11 | + |
| 12 | +def _get_kwargs() -> Dict[str, Any]: |
| 13 | + _kwargs: Dict[str, Any] = { |
| 14 | + "method": "get", |
| 15 | + "url": "/responses/reference", |
| 16 | + } |
| 17 | + |
| 18 | + return _kwargs |
| 19 | + |
| 20 | + |
| 21 | +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[AModel]: |
| 22 | + if response.status_code == 200: |
| 23 | + response_200 = AModel.from_dict(response.json()) |
| 24 | + |
| 25 | + return response_200 |
| 26 | + if client.raise_on_unexpected_status: |
| 27 | + raise errors.UnexpectedStatus(response.status_code, response.content) |
| 28 | + else: |
| 29 | + return None |
| 30 | + |
| 31 | + |
| 32 | +def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[AModel]: |
| 33 | + return Response( |
| 34 | + status_code=HTTPStatus(response.status_code), |
| 35 | + content=response.content, |
| 36 | + headers=response.headers, |
| 37 | + parsed=_parse_response(client=client, response=response), |
| 38 | + ) |
| 39 | + |
| 40 | + |
| 41 | +def sync_detailed( |
| 42 | + *, |
| 43 | + client: Union[AuthenticatedClient, Client], |
| 44 | +) -> Response[AModel]: |
| 45 | + """Endpoint using predefined response |
| 46 | +
|
| 47 | + Raises: |
| 48 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 49 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 50 | +
|
| 51 | + Returns: |
| 52 | + Response[AModel] |
| 53 | + """ |
| 54 | + |
| 55 | + kwargs = _get_kwargs() |
| 56 | + |
| 57 | + response = client.get_httpx_client().request( |
| 58 | + **kwargs, |
| 59 | + ) |
| 60 | + |
| 61 | + return _build_response(client=client, response=response) |
| 62 | + |
| 63 | + |
| 64 | +def sync( |
| 65 | + *, |
| 66 | + client: Union[AuthenticatedClient, Client], |
| 67 | +) -> Optional[AModel]: |
| 68 | + """Endpoint using predefined response |
| 69 | +
|
| 70 | + Raises: |
| 71 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 72 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 73 | +
|
| 74 | + Returns: |
| 75 | + AModel |
| 76 | + """ |
| 77 | + |
| 78 | + return sync_detailed( |
| 79 | + client=client, |
| 80 | + ).parsed |
| 81 | + |
| 82 | + |
| 83 | +async def asyncio_detailed( |
| 84 | + *, |
| 85 | + client: Union[AuthenticatedClient, Client], |
| 86 | +) -> Response[AModel]: |
| 87 | + """Endpoint using predefined response |
| 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[AModel] |
| 95 | + """ |
| 96 | + |
| 97 | + kwargs = _get_kwargs() |
| 98 | + |
| 99 | + response = await client.get_async_httpx_client().request(**kwargs) |
| 100 | + |
| 101 | + return _build_response(client=client, response=response) |
| 102 | + |
| 103 | + |
| 104 | +async def asyncio( |
| 105 | + *, |
| 106 | + client: Union[AuthenticatedClient, Client], |
| 107 | +) -> Optional[AModel]: |
| 108 | + """Endpoint using predefined response |
| 109 | +
|
| 110 | + Raises: |
| 111 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 112 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 113 | +
|
| 114 | + Returns: |
| 115 | + AModel |
| 116 | + """ |
| 117 | + |
| 118 | + return ( |
| 119 | + await asyncio_detailed( |
| 120 | + client=client, |
| 121 | + ) |
| 122 | + ).parsed |
0 commit comments