|
| 1 | +from http import HTTPStatus |
| 2 | +from typing import Any, Optional, Union |
| 3 | +from uuid import UUID |
| 4 | + |
| 5 | +import httpx |
| 6 | + |
| 7 | +from ... import errors |
| 8 | +from ...client import AuthenticatedClient, Client |
| 9 | +from ...models.comment import Comment |
| 10 | +from ...models.http_validation_error import HTTPValidationError |
| 11 | +from ...types import Response |
| 12 | + |
| 13 | + |
| 14 | +def _get_kwargs( |
| 15 | + project_id: str, |
| 16 | + location_id: UUID, |
| 17 | +) -> dict[str, Any]: |
| 18 | + _kwargs: dict[str, Any] = { |
| 19 | + "method": "get", |
| 20 | + "url": f"/projects/{project_id}/locations/{location_id}/comments", |
| 21 | + } |
| 22 | + |
| 23 | + return _kwargs |
| 24 | + |
| 25 | + |
| 26 | +def _parse_response( |
| 27 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 28 | +) -> Optional[Union[HTTPValidationError, list["Comment"]]]: |
| 29 | + if response.status_code == 200: |
| 30 | + response_200 = [] |
| 31 | + _response_200 = response.json() |
| 32 | + for response_200_item_data in _response_200: |
| 33 | + response_200_item = Comment.from_dict(response_200_item_data) |
| 34 | + |
| 35 | + response_200.append(response_200_item) |
| 36 | + |
| 37 | + return response_200 |
| 38 | + if response.status_code == 422: |
| 39 | + response_422 = HTTPValidationError.from_dict(response.json()) |
| 40 | + |
| 41 | + return response_422 |
| 42 | + if client.raise_on_unexpected_status: |
| 43 | + raise errors.UnexpectedStatus(response.status_code, response.content) |
| 44 | + else: |
| 45 | + return None |
| 46 | + |
| 47 | + |
| 48 | +def _build_response( |
| 49 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 50 | +) -> Response[Union[HTTPValidationError, list["Comment"]]]: |
| 51 | + return Response( |
| 52 | + status_code=HTTPStatus(response.status_code), |
| 53 | + content=response.content, |
| 54 | + headers=response.headers, |
| 55 | + parsed=_parse_response(client=client, response=response), |
| 56 | + ) |
| 57 | + |
| 58 | + |
| 59 | +def sync_detailed( |
| 60 | + project_id: str, |
| 61 | + location_id: UUID, |
| 62 | + *, |
| 63 | + client: AuthenticatedClient, |
| 64 | +) -> Response[Union[HTTPValidationError, list["Comment"]]]: |
| 65 | + """Get Location Comments |
| 66 | +
|
| 67 | + Get all location comments, along with associated likes |
| 68 | +
|
| 69 | + Args: |
| 70 | + project_id (str): |
| 71 | + location_id (UUID): |
| 72 | +
|
| 73 | + Raises: |
| 74 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 75 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 76 | +
|
| 77 | + Returns: |
| 78 | + Response[Union[HTTPValidationError, list['Comment']]] |
| 79 | + """ |
| 80 | + |
| 81 | + kwargs = _get_kwargs( |
| 82 | + project_id=project_id, |
| 83 | + location_id=location_id, |
| 84 | + ) |
| 85 | + |
| 86 | + response = client.get_httpx_client().request( |
| 87 | + **kwargs, |
| 88 | + ) |
| 89 | + |
| 90 | + return _build_response(client=client, response=response) |
| 91 | + |
| 92 | + |
| 93 | +def sync( |
| 94 | + project_id: str, |
| 95 | + location_id: UUID, |
| 96 | + *, |
| 97 | + client: AuthenticatedClient, |
| 98 | +) -> Optional[Union[HTTPValidationError, list["Comment"]]]: |
| 99 | + """Get Location Comments |
| 100 | +
|
| 101 | + Get all location comments, along with associated likes |
| 102 | +
|
| 103 | + Args: |
| 104 | + project_id (str): |
| 105 | + location_id (UUID): |
| 106 | +
|
| 107 | + Raises: |
| 108 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 109 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 110 | +
|
| 111 | + Returns: |
| 112 | + Union[HTTPValidationError, list['Comment']] |
| 113 | + """ |
| 114 | + |
| 115 | + return sync_detailed( |
| 116 | + project_id=project_id, |
| 117 | + location_id=location_id, |
| 118 | + client=client, |
| 119 | + ).parsed |
| 120 | + |
| 121 | + |
| 122 | +async def asyncio_detailed( |
| 123 | + project_id: str, |
| 124 | + location_id: UUID, |
| 125 | + *, |
| 126 | + client: AuthenticatedClient, |
| 127 | +) -> Response[Union[HTTPValidationError, list["Comment"]]]: |
| 128 | + """Get Location Comments |
| 129 | +
|
| 130 | + Get all location comments, along with associated likes |
| 131 | +
|
| 132 | + Args: |
| 133 | + project_id (str): |
| 134 | + location_id (UUID): |
| 135 | +
|
| 136 | + Raises: |
| 137 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 138 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 139 | +
|
| 140 | + Returns: |
| 141 | + Response[Union[HTTPValidationError, list['Comment']]] |
| 142 | + """ |
| 143 | + |
| 144 | + kwargs = _get_kwargs( |
| 145 | + project_id=project_id, |
| 146 | + location_id=location_id, |
| 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 | + project_id: str, |
| 156 | + location_id: UUID, |
| 157 | + *, |
| 158 | + client: AuthenticatedClient, |
| 159 | +) -> Optional[Union[HTTPValidationError, list["Comment"]]]: |
| 160 | + """Get Location Comments |
| 161 | +
|
| 162 | + Get all location comments, along with associated likes |
| 163 | +
|
| 164 | + Args: |
| 165 | + project_id (str): |
| 166 | + location_id (UUID): |
| 167 | +
|
| 168 | + Raises: |
| 169 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 170 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 171 | +
|
| 172 | + Returns: |
| 173 | + Union[HTTPValidationError, list['Comment']] |
| 174 | + """ |
| 175 | + |
| 176 | + return ( |
| 177 | + await asyncio_detailed( |
| 178 | + project_id=project_id, |
| 179 | + location_id=location_id, |
| 180 | + client=client, |
| 181 | + ) |
| 182 | + ).parsed |
0 commit comments