|
| 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.http_validation_error import HTTPValidationError |
| 9 | +from ...models.web_map_service import WebMapService |
| 10 | +from ...models.web_map_service_create import WebMapServiceCreate |
| 11 | +from ...types import Response |
| 12 | + |
| 13 | + |
| 14 | +def _get_kwargs( |
| 15 | + project_id: str, |
| 16 | + *, |
| 17 | + body: WebMapServiceCreate, |
| 18 | +) -> dict[str, Any]: |
| 19 | + headers: dict[str, Any] = {} |
| 20 | + |
| 21 | + _kwargs: dict[str, Any] = { |
| 22 | + "method": "post", |
| 23 | + "url": f"/projects/{project_id}/web_map_services", |
| 24 | + } |
| 25 | + |
| 26 | + _body = body.to_dict() |
| 27 | + |
| 28 | + _kwargs["json"] = _body |
| 29 | + headers["Content-Type"] = "application/json" |
| 30 | + |
| 31 | + _kwargs["headers"] = headers |
| 32 | + return _kwargs |
| 33 | + |
| 34 | + |
| 35 | +def _parse_response( |
| 36 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 37 | +) -> Optional[Union[HTTPValidationError, WebMapService]]: |
| 38 | + if response.status_code == 201: |
| 39 | + response_201 = WebMapService.from_dict(response.json()) |
| 40 | + |
| 41 | + return response_201 |
| 42 | + if response.status_code == 422: |
| 43 | + response_422 = HTTPValidationError.from_dict(response.json()) |
| 44 | + |
| 45 | + return response_422 |
| 46 | + if client.raise_on_unexpected_status: |
| 47 | + raise errors.UnexpectedStatus(response.status_code, response.content) |
| 48 | + else: |
| 49 | + return None |
| 50 | + |
| 51 | + |
| 52 | +def _build_response( |
| 53 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 54 | +) -> Response[Union[HTTPValidationError, WebMapService]]: |
| 55 | + return Response( |
| 56 | + status_code=HTTPStatus(response.status_code), |
| 57 | + content=response.content, |
| 58 | + headers=response.headers, |
| 59 | + parsed=_parse_response(client=client, response=response), |
| 60 | + ) |
| 61 | + |
| 62 | + |
| 63 | +def sync_detailed( |
| 64 | + project_id: str, |
| 65 | + *, |
| 66 | + client: AuthenticatedClient, |
| 67 | + body: WebMapServiceCreate, |
| 68 | +) -> Response[Union[HTTPValidationError, WebMapService]]: |
| 69 | + """Create a Web Map Service for a Project |
| 70 | +
|
| 71 | + Create a Web Map Service. |
| 72 | +
|
| 73 | + Args: |
| 74 | + project_id (str): |
| 75 | + body (WebMapServiceCreate): |
| 76 | +
|
| 77 | + Raises: |
| 78 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 79 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 80 | +
|
| 81 | + Returns: |
| 82 | + Response[Union[HTTPValidationError, WebMapService]] |
| 83 | + """ |
| 84 | + |
| 85 | + kwargs = _get_kwargs( |
| 86 | + project_id=project_id, |
| 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 | + project_id: str, |
| 99 | + *, |
| 100 | + client: AuthenticatedClient, |
| 101 | + body: WebMapServiceCreate, |
| 102 | +) -> Optional[Union[HTTPValidationError, WebMapService]]: |
| 103 | + """Create a Web Map Service for a Project |
| 104 | +
|
| 105 | + Create a Web Map Service. |
| 106 | +
|
| 107 | + Args: |
| 108 | + project_id (str): |
| 109 | + body (WebMapServiceCreate): |
| 110 | +
|
| 111 | + Raises: |
| 112 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 113 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 114 | +
|
| 115 | + Returns: |
| 116 | + Union[HTTPValidationError, WebMapService] |
| 117 | + """ |
| 118 | + |
| 119 | + return sync_detailed( |
| 120 | + project_id=project_id, |
| 121 | + client=client, |
| 122 | + body=body, |
| 123 | + ).parsed |
| 124 | + |
| 125 | + |
| 126 | +async def asyncio_detailed( |
| 127 | + project_id: str, |
| 128 | + *, |
| 129 | + client: AuthenticatedClient, |
| 130 | + body: WebMapServiceCreate, |
| 131 | +) -> Response[Union[HTTPValidationError, WebMapService]]: |
| 132 | + """Create a Web Map Service for a Project |
| 133 | +
|
| 134 | + Create a Web Map Service. |
| 135 | +
|
| 136 | + Args: |
| 137 | + project_id (str): |
| 138 | + body (WebMapServiceCreate): |
| 139 | +
|
| 140 | + Raises: |
| 141 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 142 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 143 | +
|
| 144 | + Returns: |
| 145 | + Response[Union[HTTPValidationError, WebMapService]] |
| 146 | + """ |
| 147 | + |
| 148 | + kwargs = _get_kwargs( |
| 149 | + project_id=project_id, |
| 150 | + body=body, |
| 151 | + ) |
| 152 | + |
| 153 | + response = await client.get_async_httpx_client().request(**kwargs) |
| 154 | + |
| 155 | + return _build_response(client=client, response=response) |
| 156 | + |
| 157 | + |
| 158 | +async def asyncio( |
| 159 | + project_id: str, |
| 160 | + *, |
| 161 | + client: AuthenticatedClient, |
| 162 | + body: WebMapServiceCreate, |
| 163 | +) -> Optional[Union[HTTPValidationError, WebMapService]]: |
| 164 | + """Create a Web Map Service for a Project |
| 165 | +
|
| 166 | + Create a Web Map Service. |
| 167 | +
|
| 168 | + Args: |
| 169 | + project_id (str): |
| 170 | + body (WebMapServiceCreate): |
| 171 | +
|
| 172 | + Raises: |
| 173 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 174 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 175 | +
|
| 176 | + Returns: |
| 177 | + Union[HTTPValidationError, WebMapService] |
| 178 | + """ |
| 179 | + |
| 180 | + return ( |
| 181 | + await asyncio_detailed( |
| 182 | + project_id=project_id, |
| 183 | + client=client, |
| 184 | + body=body, |
| 185 | + ) |
| 186 | + ).parsed |
0 commit comments