|
| 1 | +from http import HTTPStatus |
| 2 | +from typing import Any |
| 3 | +from urllib.parse import quote |
| 4 | +from uuid import UUID |
| 5 | + |
| 6 | +import httpx |
| 7 | + |
| 8 | +from ... import errors |
| 9 | +from ...client import AuthenticatedClient, Client |
| 10 | +from ...models.application import Application |
| 11 | +from ...models.error import Error |
| 12 | +from ...models.new_application import NewApplication |
| 13 | +from ...types import Response |
| 14 | + |
| 15 | + |
| 16 | +def _get_kwargs( |
| 17 | + id: UUID, |
| 18 | + *, |
| 19 | + body: NewApplication, |
| 20 | +) -> dict[str, Any]: |
| 21 | + headers: dict[str, Any] = {} |
| 22 | + |
| 23 | + _kwargs: dict[str, Any] = { |
| 24 | + "method": "post", |
| 25 | + "url": "/organisation/id/{id}/applications".format( |
| 26 | + id=quote(str(id), safe=""), |
| 27 | + ), |
| 28 | + } |
| 29 | + |
| 30 | + _kwargs["json"] = body.to_dict() |
| 31 | + |
| 32 | + headers["Content-Type"] = "application/json" |
| 33 | + |
| 34 | + _kwargs["headers"] = headers |
| 35 | + return _kwargs |
| 36 | + |
| 37 | + |
| 38 | +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Application | Error | None: |
| 39 | + if response.status_code == 201: |
| 40 | + response_201 = Application.from_dict(response.json()) |
| 41 | + |
| 42 | + return response_201 |
| 43 | + |
| 44 | + if response.status_code == 400: |
| 45 | + response_400 = Error.from_dict(response.json()) |
| 46 | + |
| 47 | + return response_400 |
| 48 | + |
| 49 | + if response.status_code == 403: |
| 50 | + response_403 = Error.from_dict(response.json()) |
| 51 | + |
| 52 | + return response_403 |
| 53 | + |
| 54 | + if response.status_code == 409: |
| 55 | + response_409 = Error.from_dict(response.json()) |
| 56 | + |
| 57 | + return response_409 |
| 58 | + |
| 59 | + if response.status_code == 422: |
| 60 | + response_422 = Error.from_dict(response.json()) |
| 61 | + |
| 62 | + return response_422 |
| 63 | + |
| 64 | + if client.raise_on_unexpected_status: |
| 65 | + raise errors.UnexpectedStatus(response.status_code, response.content) |
| 66 | + else: |
| 67 | + return None |
| 68 | + |
| 69 | + |
| 70 | +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Application | Error]: |
| 71 | + return Response( |
| 72 | + status_code=HTTPStatus(response.status_code), |
| 73 | + content=response.content, |
| 74 | + headers=response.headers, |
| 75 | + parsed=_parse_response(client=client, response=response), |
| 76 | + ) |
| 77 | + |
| 78 | + |
| 79 | +def sync_detailed( |
| 80 | + id: UUID, |
| 81 | + *, |
| 82 | + client: AuthenticatedClient | Client, |
| 83 | + body: NewApplication, |
| 84 | +) -> Response[Application | Error]: |
| 85 | + """Create a new application in an organisation |
| 86 | +
|
| 87 | + Args: |
| 88 | + id (UUID): |
| 89 | + body (NewApplication): |
| 90 | +
|
| 91 | + Raises: |
| 92 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 93 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 94 | +
|
| 95 | + Returns: |
| 96 | + Response[Application | Error] |
| 97 | + """ |
| 98 | + |
| 99 | + kwargs = _get_kwargs( |
| 100 | + id=id, |
| 101 | + body=body, |
| 102 | + ) |
| 103 | + |
| 104 | + response = client.get_httpx_client().request( |
| 105 | + **kwargs, |
| 106 | + ) |
| 107 | + |
| 108 | + return _build_response(client=client, response=response) |
| 109 | + |
| 110 | + |
| 111 | +def sync( |
| 112 | + id: UUID, |
| 113 | + *, |
| 114 | + client: AuthenticatedClient | Client, |
| 115 | + body: NewApplication, |
| 116 | +) -> Application | Error | None: |
| 117 | + """Create a new application in an organisation |
| 118 | +
|
| 119 | + Args: |
| 120 | + id (UUID): |
| 121 | + body (NewApplication): |
| 122 | +
|
| 123 | + Raises: |
| 124 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 125 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 126 | +
|
| 127 | + Returns: |
| 128 | + Application | Error |
| 129 | + """ |
| 130 | + |
| 131 | + return sync_detailed( |
| 132 | + id=id, |
| 133 | + client=client, |
| 134 | + body=body, |
| 135 | + ).parsed |
| 136 | + |
| 137 | + |
| 138 | +async def asyncio_detailed( |
| 139 | + id: UUID, |
| 140 | + *, |
| 141 | + client: AuthenticatedClient | Client, |
| 142 | + body: NewApplication, |
| 143 | +) -> Response[Application | Error]: |
| 144 | + """Create a new application in an organisation |
| 145 | +
|
| 146 | + Args: |
| 147 | + id (UUID): |
| 148 | + body (NewApplication): |
| 149 | +
|
| 150 | + Raises: |
| 151 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 152 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 153 | +
|
| 154 | + Returns: |
| 155 | + Response[Application | Error] |
| 156 | + """ |
| 157 | + |
| 158 | + kwargs = _get_kwargs( |
| 159 | + id=id, |
| 160 | + body=body, |
| 161 | + ) |
| 162 | + |
| 163 | + response = await client.get_async_httpx_client().request(**kwargs) |
| 164 | + |
| 165 | + return _build_response(client=client, response=response) |
| 166 | + |
| 167 | + |
| 168 | +async def asyncio( |
| 169 | + id: UUID, |
| 170 | + *, |
| 171 | + client: AuthenticatedClient | Client, |
| 172 | + body: NewApplication, |
| 173 | +) -> Application | Error | None: |
| 174 | + """Create a new application in an organisation |
| 175 | +
|
| 176 | + Args: |
| 177 | + id (UUID): |
| 178 | + body (NewApplication): |
| 179 | +
|
| 180 | + Raises: |
| 181 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 182 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 183 | +
|
| 184 | + Returns: |
| 185 | + Application | Error |
| 186 | + """ |
| 187 | + |
| 188 | + return ( |
| 189 | + await asyncio_detailed( |
| 190 | + id=id, |
| 191 | + client=client, |
| 192 | + body=body, |
| 193 | + ) |
| 194 | + ).parsed |
0 commit comments