|
| 1 | +from http import HTTPStatus |
| 2 | +from typing import Any |
| 3 | +from urllib.parse import quote |
| 4 | + |
| 5 | +import httpx |
| 6 | + |
| 7 | +from ... import errors |
| 8 | +from ...client import AuthenticatedClient, Client |
| 9 | +from ...models.get_endpoint_period_failure_rates_response_200 import ( |
| 10 | + GetEndpointPeriodFailureRatesResponse200, |
| 11 | +) |
| 12 | +from ...models.get_endpoint_period_failure_rates_response_400 import ( |
| 13 | + GetEndpointPeriodFailureRatesResponse400, |
| 14 | +) |
| 15 | +from ...models.get_endpoint_period_failure_rates_response_401 import ( |
| 16 | + GetEndpointPeriodFailureRatesResponse401, |
| 17 | +) |
| 18 | +from ...models.get_endpoint_period_failure_rates_response_404 import ( |
| 19 | + GetEndpointPeriodFailureRatesResponse404, |
| 20 | +) |
| 21 | +from ...types import UNSET, Response, Unset |
| 22 | + |
| 23 | + |
| 24 | +def _get_kwargs( |
| 25 | + project_id: str, |
| 26 | + *, |
| 27 | + endpoint_id: list[str] | Unset = UNSET, |
| 28 | + start_date: str | Unset = UNSET, |
| 29 | + end_date: str | Unset = UNSET, |
| 30 | +) -> dict[str, Any]: |
| 31 | + |
| 32 | + params: dict[str, Any] = {} |
| 33 | + |
| 34 | + json_endpoint_id: list[str] | Unset = UNSET |
| 35 | + if not isinstance(endpoint_id, Unset): |
| 36 | + json_endpoint_id = endpoint_id |
| 37 | + |
| 38 | + params["endpointId"] = json_endpoint_id |
| 39 | + |
| 40 | + params["startDate"] = start_date |
| 41 | + |
| 42 | + params["endDate"] = end_date |
| 43 | + |
| 44 | + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} |
| 45 | + |
| 46 | + _kwargs: dict[str, Any] = { |
| 47 | + "method": "get", |
| 48 | + "url": "/v1/projects/{project_id}/endpoints/period-failure-rates".format( |
| 49 | + project_id=quote(str(project_id), safe=""), |
| 50 | + ), |
| 51 | + "params": params, |
| 52 | + } |
| 53 | + |
| 54 | + return _kwargs |
| 55 | + |
| 56 | + |
| 57 | +def _parse_response( |
| 58 | + *, client: AuthenticatedClient | Client, response: httpx.Response |
| 59 | +) -> ( |
| 60 | + GetEndpointPeriodFailureRatesResponse200 |
| 61 | + | GetEndpointPeriodFailureRatesResponse400 |
| 62 | + | GetEndpointPeriodFailureRatesResponse401 |
| 63 | + | GetEndpointPeriodFailureRatesResponse404 |
| 64 | + | None |
| 65 | +): |
| 66 | + if response.status_code == 200: |
| 67 | + response_200 = GetEndpointPeriodFailureRatesResponse200.from_dict( |
| 68 | + response.json() |
| 69 | + ) |
| 70 | + |
| 71 | + return response_200 |
| 72 | + |
| 73 | + if response.status_code == 400: |
| 74 | + response_400 = GetEndpointPeriodFailureRatesResponse400.from_dict( |
| 75 | + response.json() |
| 76 | + ) |
| 77 | + |
| 78 | + return response_400 |
| 79 | + |
| 80 | + if response.status_code == 401: |
| 81 | + response_401 = GetEndpointPeriodFailureRatesResponse401.from_dict( |
| 82 | + response.json() |
| 83 | + ) |
| 84 | + |
| 85 | + return response_401 |
| 86 | + |
| 87 | + if response.status_code == 404: |
| 88 | + response_404 = GetEndpointPeriodFailureRatesResponse404.from_dict( |
| 89 | + response.json() |
| 90 | + ) |
| 91 | + |
| 92 | + return response_404 |
| 93 | + |
| 94 | + if client.raise_on_unexpected_status: |
| 95 | + raise errors.UnexpectedStatus(response.status_code, response.content) |
| 96 | + else: |
| 97 | + return None |
| 98 | + |
| 99 | + |
| 100 | +def _build_response( |
| 101 | + *, client: AuthenticatedClient | Client, response: httpx.Response |
| 102 | +) -> Response[ |
| 103 | + GetEndpointPeriodFailureRatesResponse200 |
| 104 | + | GetEndpointPeriodFailureRatesResponse400 |
| 105 | + | GetEndpointPeriodFailureRatesResponse401 |
| 106 | + | GetEndpointPeriodFailureRatesResponse404 |
| 107 | +]: |
| 108 | + return Response( |
| 109 | + status_code=HTTPStatus(response.status_code), |
| 110 | + content=response.content, |
| 111 | + headers=response.headers, |
| 112 | + parsed=_parse_response(client=client, response=response), |
| 113 | + ) |
| 114 | + |
| 115 | + |
| 116 | +def sync_detailed( |
| 117 | + project_id: str, |
| 118 | + *, |
| 119 | + client: AuthenticatedClient, |
| 120 | + endpoint_id: list[str] | Unset = UNSET, |
| 121 | + start_date: str | Unset = UNSET, |
| 122 | + end_date: str | Unset = UNSET, |
| 123 | +) -> Response[ |
| 124 | + GetEndpointPeriodFailureRatesResponse200 |
| 125 | + | GetEndpointPeriodFailureRatesResponse400 |
| 126 | + | GetEndpointPeriodFailureRatesResponse401 |
| 127 | + | GetEndpointPeriodFailureRatesResponse404 |
| 128 | +]: |
| 129 | + """Endpoint period failure rates |
| 130 | +
|
| 131 | + Display-only delivery rates for the given endpoint ids over a date range (default last 7 days). |
| 132 | + Independent of the list so a slow COUNT cannot delay the table. |
| 133 | +
|
| 134 | + Args: |
| 135 | + project_id (str): |
| 136 | + endpoint_id (list[str] | Unset): |
| 137 | + start_date (str | Unset): |
| 138 | + end_date (str | Unset): |
| 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[GetEndpointPeriodFailureRatesResponse200 | GetEndpointPeriodFailureRatesResponse400 | GetEndpointPeriodFailureRatesResponse401 | GetEndpointPeriodFailureRatesResponse404] |
| 146 | + """ |
| 147 | + |
| 148 | + kwargs = _get_kwargs( |
| 149 | + project_id=project_id, |
| 150 | + endpoint_id=endpoint_id, |
| 151 | + start_date=start_date, |
| 152 | + end_date=end_date, |
| 153 | + ) |
| 154 | + |
| 155 | + response = client.get_httpx_client().request( |
| 156 | + **kwargs, |
| 157 | + ) |
| 158 | + |
| 159 | + return _build_response(client=client, response=response) |
| 160 | + |
| 161 | + |
| 162 | +def sync( |
| 163 | + project_id: str, |
| 164 | + *, |
| 165 | + client: AuthenticatedClient, |
| 166 | + endpoint_id: list[str] | Unset = UNSET, |
| 167 | + start_date: str | Unset = UNSET, |
| 168 | + end_date: str | Unset = UNSET, |
| 169 | +) -> ( |
| 170 | + GetEndpointPeriodFailureRatesResponse200 |
| 171 | + | GetEndpointPeriodFailureRatesResponse400 |
| 172 | + | GetEndpointPeriodFailureRatesResponse401 |
| 173 | + | GetEndpointPeriodFailureRatesResponse404 |
| 174 | + | None |
| 175 | +): |
| 176 | + """Endpoint period failure rates |
| 177 | +
|
| 178 | + Display-only delivery rates for the given endpoint ids over a date range (default last 7 days). |
| 179 | + Independent of the list so a slow COUNT cannot delay the table. |
| 180 | +
|
| 181 | + Args: |
| 182 | + project_id (str): |
| 183 | + endpoint_id (list[str] | Unset): |
| 184 | + start_date (str | Unset): |
| 185 | + end_date (str | Unset): |
| 186 | +
|
| 187 | + Raises: |
| 188 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 189 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 190 | +
|
| 191 | + Returns: |
| 192 | + GetEndpointPeriodFailureRatesResponse200 | GetEndpointPeriodFailureRatesResponse400 | GetEndpointPeriodFailureRatesResponse401 | GetEndpointPeriodFailureRatesResponse404 |
| 193 | + """ |
| 194 | + |
| 195 | + return sync_detailed( |
| 196 | + project_id=project_id, |
| 197 | + client=client, |
| 198 | + endpoint_id=endpoint_id, |
| 199 | + start_date=start_date, |
| 200 | + end_date=end_date, |
| 201 | + ).parsed |
| 202 | + |
| 203 | + |
| 204 | +async def asyncio_detailed( |
| 205 | + project_id: str, |
| 206 | + *, |
| 207 | + client: AuthenticatedClient, |
| 208 | + endpoint_id: list[str] | Unset = UNSET, |
| 209 | + start_date: str | Unset = UNSET, |
| 210 | + end_date: str | Unset = UNSET, |
| 211 | +) -> Response[ |
| 212 | + GetEndpointPeriodFailureRatesResponse200 |
| 213 | + | GetEndpointPeriodFailureRatesResponse400 |
| 214 | + | GetEndpointPeriodFailureRatesResponse401 |
| 215 | + | GetEndpointPeriodFailureRatesResponse404 |
| 216 | +]: |
| 217 | + """Endpoint period failure rates |
| 218 | +
|
| 219 | + Display-only delivery rates for the given endpoint ids over a date range (default last 7 days). |
| 220 | + Independent of the list so a slow COUNT cannot delay the table. |
| 221 | +
|
| 222 | + Args: |
| 223 | + project_id (str): |
| 224 | + endpoint_id (list[str] | Unset): |
| 225 | + start_date (str | Unset): |
| 226 | + end_date (str | Unset): |
| 227 | +
|
| 228 | + Raises: |
| 229 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 230 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 231 | +
|
| 232 | + Returns: |
| 233 | + Response[GetEndpointPeriodFailureRatesResponse200 | GetEndpointPeriodFailureRatesResponse400 | GetEndpointPeriodFailureRatesResponse401 | GetEndpointPeriodFailureRatesResponse404] |
| 234 | + """ |
| 235 | + |
| 236 | + kwargs = _get_kwargs( |
| 237 | + project_id=project_id, |
| 238 | + endpoint_id=endpoint_id, |
| 239 | + start_date=start_date, |
| 240 | + end_date=end_date, |
| 241 | + ) |
| 242 | + |
| 243 | + response = await client.get_async_httpx_client().request(**kwargs) |
| 244 | + |
| 245 | + return _build_response(client=client, response=response) |
| 246 | + |
| 247 | + |
| 248 | +async def asyncio( |
| 249 | + project_id: str, |
| 250 | + *, |
| 251 | + client: AuthenticatedClient, |
| 252 | + endpoint_id: list[str] | Unset = UNSET, |
| 253 | + start_date: str | Unset = UNSET, |
| 254 | + end_date: str | Unset = UNSET, |
| 255 | +) -> ( |
| 256 | + GetEndpointPeriodFailureRatesResponse200 |
| 257 | + | GetEndpointPeriodFailureRatesResponse400 |
| 258 | + | GetEndpointPeriodFailureRatesResponse401 |
| 259 | + | GetEndpointPeriodFailureRatesResponse404 |
| 260 | + | None |
| 261 | +): |
| 262 | + """Endpoint period failure rates |
| 263 | +
|
| 264 | + Display-only delivery rates for the given endpoint ids over a date range (default last 7 days). |
| 265 | + Independent of the list so a slow COUNT cannot delay the table. |
| 266 | +
|
| 267 | + Args: |
| 268 | + project_id (str): |
| 269 | + endpoint_id (list[str] | Unset): |
| 270 | + start_date (str | Unset): |
| 271 | + end_date (str | Unset): |
| 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 | + GetEndpointPeriodFailureRatesResponse200 | GetEndpointPeriodFailureRatesResponse400 | GetEndpointPeriodFailureRatesResponse401 | GetEndpointPeriodFailureRatesResponse404 |
| 279 | + """ |
| 280 | + |
| 281 | + return ( |
| 282 | + await asyncio_detailed( |
| 283 | + project_id=project_id, |
| 284 | + client=client, |
| 285 | + endpoint_id=endpoint_id, |
| 286 | + start_date=start_date, |
| 287 | + end_date=end_date, |
| 288 | + ) |
| 289 | + ).parsed |
0 commit comments