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