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