|
| 1 | +from http import HTTPStatus |
| 2 | +from typing import Any, Dict, List, Optional, Union |
| 3 | + |
| 4 | +import httpx |
| 5 | + |
| 6 | +from ... import errors |
| 7 | +from ...client import Client |
| 8 | +from ...models.error import Error |
| 9 | +from ...models.get_jobs_order import GetJobsOrder |
| 10 | +from ...models.get_jobs_response_200 import GetJobsResponse200 |
| 11 | +from ...types import UNSET, Response, Unset |
| 12 | + |
| 13 | + |
| 14 | +def _get_kwargs( |
| 15 | + *, |
| 16 | + client: Client, |
| 17 | + page: Union[Unset, None, int] = 1, |
| 18 | + per_page: Union[Unset, None, int] = 50, |
| 19 | + with_total: Union[Unset, None, bool] = True, |
| 20 | + order: Union[Unset, None, GetJobsOrder] = UNSET, |
| 21 | + types: Union[Unset, None, List[str]] = UNSET, |
| 22 | + states: Union[Unset, None, List[str]] = UNSET, |
| 23 | +) -> Dict[str, Any]: |
| 24 | + url = "{}/jobs".format(client.base_url) |
| 25 | + |
| 26 | + headers: Dict[str, str] = client.get_headers() |
| 27 | + cookies: Dict[str, Any] = client.get_cookies() |
| 28 | + |
| 29 | + params: Dict[str, Any] = {} |
| 30 | + params["page"] = page |
| 31 | + |
| 32 | + params["perPage"] = per_page |
| 33 | + |
| 34 | + params["withTotal"] = with_total |
| 35 | + |
| 36 | + json_order: Union[Unset, None, str] = UNSET |
| 37 | + if not isinstance(order, Unset): |
| 38 | + json_order = order.value if order else None |
| 39 | + |
| 40 | + params["order"] = json_order |
| 41 | + |
| 42 | + json_types: Union[Unset, None, List[str]] = UNSET |
| 43 | + if not isinstance(types, Unset): |
| 44 | + if types is None: |
| 45 | + json_types = None |
| 46 | + else: |
| 47 | + json_types = types |
| 48 | + |
| 49 | + params["types"] = json_types |
| 50 | + |
| 51 | + json_states: Union[Unset, None, List[str]] = UNSET |
| 52 | + if not isinstance(states, Unset): |
| 53 | + if states is None: |
| 54 | + json_states = None |
| 55 | + else: |
| 56 | + json_states = states |
| 57 | + |
| 58 | + params["states"] = json_states |
| 59 | + |
| 60 | + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} |
| 61 | + |
| 62 | + # Set the proxies if the client has proxies set. |
| 63 | + proxies = None |
| 64 | + if hasattr(client, "proxies") and client.proxies is not None: |
| 65 | + https_proxy = client.proxies.get("https://") |
| 66 | + if https_proxy: |
| 67 | + proxies = https_proxy |
| 68 | + else: |
| 69 | + http_proxy = client.proxies.get("http://") |
| 70 | + if http_proxy: |
| 71 | + proxies = http_proxy |
| 72 | + |
| 73 | + return { |
| 74 | + "method": "get", |
| 75 | + "url": url, |
| 76 | + "headers": headers, |
| 77 | + "cookies": cookies, |
| 78 | + "timeout": client.get_timeout(), |
| 79 | + "proxies": proxies, |
| 80 | + "params": params, |
| 81 | + } |
| 82 | + |
| 83 | + |
| 84 | +def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Error, GetJobsResponse200]]: |
| 85 | + if response.status_code == HTTPStatus.OK: |
| 86 | + response_200 = GetJobsResponse200.from_dict(response.json()) |
| 87 | + |
| 88 | + return response_200 |
| 89 | + if response.status_code == HTTPStatus.BAD_REQUEST: |
| 90 | + response_400 = Error.from_dict(response.json()) |
| 91 | + |
| 92 | + return response_400 |
| 93 | + if response.status_code == HTTPStatus.UNAUTHORIZED: |
| 94 | + response_401 = Error.from_dict(response.json()) |
| 95 | + |
| 96 | + return response_401 |
| 97 | + if response.status_code == HTTPStatus.FORBIDDEN: |
| 98 | + response_403 = Error.from_dict(response.json()) |
| 99 | + |
| 100 | + return response_403 |
| 101 | + if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: |
| 102 | + response_422 = Error.from_dict(response.json()) |
| 103 | + |
| 104 | + return response_422 |
| 105 | + if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR: |
| 106 | + response_500 = Error.from_dict(response.json()) |
| 107 | + |
| 108 | + return response_500 |
| 109 | + if client.raise_on_unexpected_status: |
| 110 | + raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code} ({response})") |
| 111 | + else: |
| 112 | + return None |
| 113 | + |
| 114 | + |
| 115 | +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Error, GetJobsResponse200]]: |
| 116 | + return Response( |
| 117 | + status_code=HTTPStatus(response.status_code), |
| 118 | + content=response.content, |
| 119 | + headers=response.headers, |
| 120 | + parsed=_parse_response(client=client, response=response), |
| 121 | + ) |
| 122 | + |
| 123 | + |
| 124 | +def sync_detailed( |
| 125 | + *, |
| 126 | + client: Client, |
| 127 | + page: Union[Unset, None, int] = 1, |
| 128 | + per_page: Union[Unset, None, int] = 50, |
| 129 | + with_total: Union[Unset, None, bool] = True, |
| 130 | + order: Union[Unset, None, GetJobsOrder] = UNSET, |
| 131 | + types: Union[Unset, None, List[str]] = UNSET, |
| 132 | + states: Union[Unset, None, List[str]] = UNSET, |
| 133 | +) -> Response[Union[Error, GetJobsResponse200]]: |
| 134 | + """retrieve the list of background jobs running on the instance. |
| 135 | +
|
| 136 | + Args: |
| 137 | + page (Union[Unset, None, int]): Default: 1. |
| 138 | + per_page (Union[Unset, None, int]): Default: 50. |
| 139 | + with_total (Union[Unset, None, bool]): Default: True. |
| 140 | + order (Union[Unset, None, GetJobsOrder]): |
| 141 | + types (Union[Unset, None, List[str]]): |
| 142 | + states (Union[Unset, None, List[str]]): |
| 143 | +
|
| 144 | + Raises: |
| 145 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 146 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 147 | +
|
| 148 | + Returns: |
| 149 | + Response[Union[Error, GetJobsResponse200]] |
| 150 | + """ |
| 151 | + |
| 152 | + kwargs = _get_kwargs( |
| 153 | + client=client, |
| 154 | + page=page, |
| 155 | + per_page=per_page, |
| 156 | + with_total=with_total, |
| 157 | + order=order, |
| 158 | + types=types, |
| 159 | + states=states, |
| 160 | + ) |
| 161 | + |
| 162 | + response = httpx.request( |
| 163 | + verify=client.verify_ssl, |
| 164 | + **kwargs, |
| 165 | + ) |
| 166 | + |
| 167 | + return _build_response(client=client, response=response) |
| 168 | + |
| 169 | + |
| 170 | +def sync( |
| 171 | + *, |
| 172 | + client: Client, |
| 173 | + page: Union[Unset, None, int] = 1, |
| 174 | + per_page: Union[Unset, None, int] = 50, |
| 175 | + with_total: Union[Unset, None, bool] = True, |
| 176 | + order: Union[Unset, None, GetJobsOrder] = UNSET, |
| 177 | + types: Union[Unset, None, List[str]] = UNSET, |
| 178 | + states: Union[Unset, None, List[str]] = UNSET, |
| 179 | +) -> Optional[Union[Error, GetJobsResponse200]]: |
| 180 | + """retrieve the list of background jobs running on the instance. |
| 181 | +
|
| 182 | + Args: |
| 183 | + page (Union[Unset, None, int]): Default: 1. |
| 184 | + per_page (Union[Unset, None, int]): Default: 50. |
| 185 | + with_total (Union[Unset, None, bool]): Default: True. |
| 186 | + order (Union[Unset, None, GetJobsOrder]): |
| 187 | + types (Union[Unset, None, List[str]]): |
| 188 | + states (Union[Unset, None, List[str]]): |
| 189 | +
|
| 190 | + Raises: |
| 191 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 192 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 193 | +
|
| 194 | + Returns: |
| 195 | + Response[Union[Error, GetJobsResponse200]] |
| 196 | + """ |
| 197 | + |
| 198 | + return sync_detailed( |
| 199 | + client=client, |
| 200 | + page=page, |
| 201 | + per_page=per_page, |
| 202 | + with_total=with_total, |
| 203 | + order=order, |
| 204 | + types=types, |
| 205 | + states=states, |
| 206 | + ).parsed |
| 207 | + |
| 208 | + |
| 209 | +async def asyncio_detailed( |
| 210 | + *, |
| 211 | + client: Client, |
| 212 | + page: Union[Unset, None, int] = 1, |
| 213 | + per_page: Union[Unset, None, int] = 50, |
| 214 | + with_total: Union[Unset, None, bool] = True, |
| 215 | + order: Union[Unset, None, GetJobsOrder] = UNSET, |
| 216 | + types: Union[Unset, None, List[str]] = UNSET, |
| 217 | + states: Union[Unset, None, List[str]] = UNSET, |
| 218 | +) -> Response[Union[Error, GetJobsResponse200]]: |
| 219 | + """retrieve the list of background jobs running on the instance. |
| 220 | +
|
| 221 | + Args: |
| 222 | + page (Union[Unset, None, int]): Default: 1. |
| 223 | + per_page (Union[Unset, None, int]): Default: 50. |
| 224 | + with_total (Union[Unset, None, bool]): Default: True. |
| 225 | + order (Union[Unset, None, GetJobsOrder]): |
| 226 | + types (Union[Unset, None, List[str]]): |
| 227 | + states (Union[Unset, None, List[str]]): |
| 228 | +
|
| 229 | + Raises: |
| 230 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 231 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 232 | +
|
| 233 | + Returns: |
| 234 | + Response[Union[Error, GetJobsResponse200]] |
| 235 | + """ |
| 236 | + |
| 237 | + kwargs = _get_kwargs( |
| 238 | + client=client, |
| 239 | + page=page, |
| 240 | + per_page=per_page, |
| 241 | + with_total=with_total, |
| 242 | + order=order, |
| 243 | + types=types, |
| 244 | + states=states, |
| 245 | + ) |
| 246 | + |
| 247 | + async with httpx.AsyncClient(verify=client.verify_ssl) as _client: |
| 248 | + response = await _client.request(**kwargs) |
| 249 | + |
| 250 | + return _build_response(client=client, response=response) |
| 251 | + |
| 252 | + |
| 253 | +async def asyncio( |
| 254 | + *, |
| 255 | + client: Client, |
| 256 | + page: Union[Unset, None, int] = 1, |
| 257 | + per_page: Union[Unset, None, int] = 50, |
| 258 | + with_total: Union[Unset, None, bool] = True, |
| 259 | + order: Union[Unset, None, GetJobsOrder] = UNSET, |
| 260 | + types: Union[Unset, None, List[str]] = UNSET, |
| 261 | + states: Union[Unset, None, List[str]] = UNSET, |
| 262 | +) -> Optional[Union[Error, GetJobsResponse200]]: |
| 263 | + """retrieve the list of background jobs running on the instance. |
| 264 | +
|
| 265 | + Args: |
| 266 | + page (Union[Unset, None, int]): Default: 1. |
| 267 | + per_page (Union[Unset, None, int]): Default: 50. |
| 268 | + with_total (Union[Unset, None, bool]): Default: True. |
| 269 | + order (Union[Unset, None, GetJobsOrder]): |
| 270 | + types (Union[Unset, None, List[str]]): |
| 271 | + states (Union[Unset, None, List[str]]): |
| 272 | +
|
| 273 | + Raises: |
| 274 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 275 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 276 | +
|
| 277 | + Returns: |
| 278 | + Response[Union[Error, GetJobsResponse200]] |
| 279 | + """ |
| 280 | + |
| 281 | + return ( |
| 282 | + await asyncio_detailed( |
| 283 | + client=client, |
| 284 | + page=page, |
| 285 | + per_page=per_page, |
| 286 | + with_total=with_total, |
| 287 | + order=order, |
| 288 | + types=types, |
| 289 | + states=states, |
| 290 | + ) |
| 291 | + ).parsed |
0 commit comments