|
| 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.geoteknisk_borehull import GeotekniskBorehull |
| 9 | +from ...types import Response |
| 10 | + |
| 11 | + |
| 12 | +def _get_kwargs( |
| 13 | + geoteknisk_unders_id: str, |
| 14 | + geoteknisk_borehull_id: str, |
| 15 | +) -> dict[str, Any]: |
| 16 | + _kwargs: dict[str, Any] = { |
| 17 | + "method": "get", |
| 18 | + "url": f"/nadag/innmelding/v1/GeotekniskUnders/{geoteknisk_unders_id}/undersPkt/{geoteknisk_borehull_id}", |
| 19 | + } |
| 20 | + |
| 21 | + return _kwargs |
| 22 | + |
| 23 | + |
| 24 | +def _parse_response( |
| 25 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 26 | +) -> Optional[Union[Any, GeotekniskBorehull]]: |
| 27 | + if response.status_code == 200: |
| 28 | + response_200 = GeotekniskBorehull.from_dict(response.json()) |
| 29 | + |
| 30 | + return response_200 |
| 31 | + |
| 32 | + if response.status_code == 401: |
| 33 | + response_401 = cast(Any, None) |
| 34 | + return response_401 |
| 35 | + |
| 36 | + if response.status_code == 404: |
| 37 | + response_404 = cast(Any, None) |
| 38 | + return response_404 |
| 39 | + |
| 40 | + if client.raise_on_unexpected_status: |
| 41 | + raise errors.UnexpectedStatus(response.status_code, response.content) |
| 42 | + else: |
| 43 | + return None |
| 44 | + |
| 45 | + |
| 46 | +def _build_response( |
| 47 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 48 | +) -> Response[Union[Any, GeotekniskBorehull]]: |
| 49 | + return Response( |
| 50 | + status_code=HTTPStatus(response.status_code), |
| 51 | + content=response.content, |
| 52 | + headers=response.headers, |
| 53 | + parsed=_parse_response(client=client, response=response), |
| 54 | + ) |
| 55 | + |
| 56 | + |
| 57 | +def sync_detailed( |
| 58 | + geoteknisk_unders_id: str, |
| 59 | + geoteknisk_borehull_id: str, |
| 60 | + *, |
| 61 | + client: AuthenticatedClient, |
| 62 | +) -> Response[Union[Any, GeotekniskBorehull]]: |
| 63 | + """Gets a GeotekniskBorehull owned by the latest versjon of a GeotekniskUnders. |
| 64 | +
|
| 65 | + Gets a GeotekniskBorehull. |
| 66 | +
|
| 67 | + Args: |
| 68 | + geoteknisk_unders_id (str): |
| 69 | + geoteknisk_borehull_id (str): |
| 70 | +
|
| 71 | + Raises: |
| 72 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 73 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 74 | +
|
| 75 | + Returns: |
| 76 | + Response[Union[Any, GeotekniskBorehull]] |
| 77 | + """ |
| 78 | + |
| 79 | + kwargs = _get_kwargs( |
| 80 | + geoteknisk_unders_id=geoteknisk_unders_id, |
| 81 | + geoteknisk_borehull_id=geoteknisk_borehull_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 | + geoteknisk_unders_id: str, |
| 93 | + geoteknisk_borehull_id: str, |
| 94 | + *, |
| 95 | + client: AuthenticatedClient, |
| 96 | +) -> Optional[Union[Any, GeotekniskBorehull]]: |
| 97 | + """Gets a GeotekniskBorehull owned by the latest versjon of a GeotekniskUnders. |
| 98 | +
|
| 99 | + Gets a GeotekniskBorehull. |
| 100 | +
|
| 101 | + Args: |
| 102 | + geoteknisk_unders_id (str): |
| 103 | + geoteknisk_borehull_id (str): |
| 104 | +
|
| 105 | + Raises: |
| 106 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 107 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 108 | +
|
| 109 | + Returns: |
| 110 | + Union[Any, GeotekniskBorehull] |
| 111 | + """ |
| 112 | + |
| 113 | + return sync_detailed( |
| 114 | + geoteknisk_unders_id=geoteknisk_unders_id, |
| 115 | + geoteknisk_borehull_id=geoteknisk_borehull_id, |
| 116 | + client=client, |
| 117 | + ).parsed |
| 118 | + |
| 119 | + |
| 120 | +async def asyncio_detailed( |
| 121 | + geoteknisk_unders_id: str, |
| 122 | + geoteknisk_borehull_id: str, |
| 123 | + *, |
| 124 | + client: AuthenticatedClient, |
| 125 | +) -> Response[Union[Any, GeotekniskBorehull]]: |
| 126 | + """Gets a GeotekniskBorehull owned by the latest versjon of a GeotekniskUnders. |
| 127 | +
|
| 128 | + Gets a GeotekniskBorehull. |
| 129 | +
|
| 130 | + Args: |
| 131 | + geoteknisk_unders_id (str): |
| 132 | + geoteknisk_borehull_id (str): |
| 133 | +
|
| 134 | + Raises: |
| 135 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 136 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 137 | +
|
| 138 | + Returns: |
| 139 | + Response[Union[Any, GeotekniskBorehull]] |
| 140 | + """ |
| 141 | + |
| 142 | + kwargs = _get_kwargs( |
| 143 | + geoteknisk_unders_id=geoteknisk_unders_id, |
| 144 | + geoteknisk_borehull_id=geoteknisk_borehull_id, |
| 145 | + ) |
| 146 | + |
| 147 | + response = await client.get_async_httpx_client().request(**kwargs) |
| 148 | + |
| 149 | + return _build_response(client=client, response=response) |
| 150 | + |
| 151 | + |
| 152 | +async def asyncio( |
| 153 | + geoteknisk_unders_id: str, |
| 154 | + geoteknisk_borehull_id: str, |
| 155 | + *, |
| 156 | + client: AuthenticatedClient, |
| 157 | +) -> Optional[Union[Any, GeotekniskBorehull]]: |
| 158 | + """Gets a GeotekniskBorehull owned by the latest versjon of a GeotekniskUnders. |
| 159 | +
|
| 160 | + Gets a GeotekniskBorehull. |
| 161 | +
|
| 162 | + Args: |
| 163 | + geoteknisk_unders_id (str): |
| 164 | + geoteknisk_borehull_id (str): |
| 165 | +
|
| 166 | + Raises: |
| 167 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 168 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 169 | +
|
| 170 | + Returns: |
| 171 | + Union[Any, GeotekniskBorehull] |
| 172 | + """ |
| 173 | + |
| 174 | + return ( |
| 175 | + await asyncio_detailed( |
| 176 | + geoteknisk_unders_id=geoteknisk_unders_id, |
| 177 | + geoteknisk_borehull_id=geoteknisk_borehull_id, |
| 178 | + client=client, |
| 179 | + ) |
| 180 | + ).parsed |
0 commit comments