|
| 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.alert_route_response import AlertRouteResponse |
| 9 | +from ...models.errors_list import ErrorsList |
| 10 | +from ...models.patch_alert_route import PatchAlertRoute |
| 11 | +from ...types import Response |
| 12 | + |
| 13 | + |
| 14 | +def _get_kwargs( |
| 15 | + id: str, |
| 16 | + *, |
| 17 | + body: PatchAlertRoute, |
| 18 | +) -> dict[str, Any]: |
| 19 | + headers: dict[str, Any] = {} |
| 20 | + |
| 21 | + _kwargs: dict[str, Any] = { |
| 22 | + "method": "patch", |
| 23 | + "url": f"/v1/alert_routes/{id}", |
| 24 | + } |
| 25 | + |
| 26 | + _kwargs["json"] = body.to_dict() |
| 27 | + |
| 28 | + headers["Content-Type"] = "application/vnd.api+json" |
| 29 | + |
| 30 | + _kwargs["headers"] = headers |
| 31 | + return _kwargs |
| 32 | + |
| 33 | + |
| 34 | +def _parse_response( |
| 35 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 36 | +) -> Optional[Union[AlertRouteResponse, ErrorsList]]: |
| 37 | + if response.status_code == 200: |
| 38 | + response_200 = AlertRouteResponse.from_dict(response.json()) |
| 39 | + |
| 40 | + return response_200 |
| 41 | + |
| 42 | + if response.status_code == 401: |
| 43 | + response_401 = ErrorsList.from_dict(response.json()) |
| 44 | + |
| 45 | + return response_401 |
| 46 | + |
| 47 | + if response.status_code == 404: |
| 48 | + response_404 = ErrorsList.from_dict(response.json()) |
| 49 | + |
| 50 | + return response_404 |
| 51 | + |
| 52 | + if response.status_code == 422: |
| 53 | + response_422 = ErrorsList.from_dict(response.json()) |
| 54 | + |
| 55 | + return response_422 |
| 56 | + |
| 57 | + if client.raise_on_unexpected_status: |
| 58 | + raise errors.UnexpectedStatus(response.status_code, response.content) |
| 59 | + else: |
| 60 | + return None |
| 61 | + |
| 62 | + |
| 63 | +def _build_response( |
| 64 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 65 | +) -> Response[Union[AlertRouteResponse, ErrorsList]]: |
| 66 | + return Response( |
| 67 | + status_code=HTTPStatus(response.status_code), |
| 68 | + content=response.content, |
| 69 | + headers=response.headers, |
| 70 | + parsed=_parse_response(client=client, response=response), |
| 71 | + ) |
| 72 | + |
| 73 | + |
| 74 | +def sync_detailed( |
| 75 | + id: str, |
| 76 | + *, |
| 77 | + client: AuthenticatedClient, |
| 78 | + body: PatchAlertRoute, |
| 79 | +) -> Response[Union[AlertRouteResponse, ErrorsList]]: |
| 80 | + """Update an alert route |
| 81 | +
|
| 82 | + Updates an alert route. **Note: This endpoint requires access to Advanced Alert Routing. If you're |
| 83 | + unsure whether you have access to this feature, please contact Rootly customer support.** |
| 84 | +
|
| 85 | + Args: |
| 86 | + id (str): |
| 87 | + body (PatchAlertRoute): |
| 88 | +
|
| 89 | + Raises: |
| 90 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 91 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 92 | +
|
| 93 | + Returns: |
| 94 | + Response[Union[AlertRouteResponse, ErrorsList]] |
| 95 | + """ |
| 96 | + |
| 97 | + kwargs = _get_kwargs( |
| 98 | + id=id, |
| 99 | + body=body, |
| 100 | + ) |
| 101 | + |
| 102 | + response = client.get_httpx_client().request( |
| 103 | + **kwargs, |
| 104 | + ) |
| 105 | + |
| 106 | + return _build_response(client=client, response=response) |
| 107 | + |
| 108 | + |
| 109 | +def sync( |
| 110 | + id: str, |
| 111 | + *, |
| 112 | + client: AuthenticatedClient, |
| 113 | + body: PatchAlertRoute, |
| 114 | +) -> Optional[Union[AlertRouteResponse, ErrorsList]]: |
| 115 | + """Update an alert route |
| 116 | +
|
| 117 | + Updates an alert route. **Note: This endpoint requires access to Advanced Alert Routing. If you're |
| 118 | + unsure whether you have access to this feature, please contact Rootly customer support.** |
| 119 | +
|
| 120 | + Args: |
| 121 | + id (str): |
| 122 | + body (PatchAlertRoute): |
| 123 | +
|
| 124 | + Raises: |
| 125 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 126 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 127 | +
|
| 128 | + Returns: |
| 129 | + Union[AlertRouteResponse, ErrorsList] |
| 130 | + """ |
| 131 | + |
| 132 | + return sync_detailed( |
| 133 | + id=id, |
| 134 | + client=client, |
| 135 | + body=body, |
| 136 | + ).parsed |
| 137 | + |
| 138 | + |
| 139 | +async def asyncio_detailed( |
| 140 | + id: str, |
| 141 | + *, |
| 142 | + client: AuthenticatedClient, |
| 143 | + body: PatchAlertRoute, |
| 144 | +) -> Response[Union[AlertRouteResponse, ErrorsList]]: |
| 145 | + """Update an alert route |
| 146 | +
|
| 147 | + Updates an alert route. **Note: This endpoint requires access to Advanced Alert Routing. If you're |
| 148 | + unsure whether you have access to this feature, please contact Rootly customer support.** |
| 149 | +
|
| 150 | + Args: |
| 151 | + id (str): |
| 152 | + body (PatchAlertRoute): |
| 153 | +
|
| 154 | + Raises: |
| 155 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 156 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 157 | +
|
| 158 | + Returns: |
| 159 | + Response[Union[AlertRouteResponse, ErrorsList]] |
| 160 | + """ |
| 161 | + |
| 162 | + kwargs = _get_kwargs( |
| 163 | + id=id, |
| 164 | + body=body, |
| 165 | + ) |
| 166 | + |
| 167 | + response = await client.get_async_httpx_client().request(**kwargs) |
| 168 | + |
| 169 | + return _build_response(client=client, response=response) |
| 170 | + |
| 171 | + |
| 172 | +async def asyncio( |
| 173 | + id: str, |
| 174 | + *, |
| 175 | + client: AuthenticatedClient, |
| 176 | + body: PatchAlertRoute, |
| 177 | +) -> Optional[Union[AlertRouteResponse, ErrorsList]]: |
| 178 | + """Update an alert route |
| 179 | +
|
| 180 | + Updates an alert route. **Note: This endpoint requires access to Advanced Alert Routing. If you're |
| 181 | + unsure whether you have access to this feature, please contact Rootly customer support.** |
| 182 | +
|
| 183 | + Args: |
| 184 | + id (str): |
| 185 | + body (PatchAlertRoute): |
| 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 | + Union[AlertRouteResponse, ErrorsList] |
| 193 | + """ |
| 194 | + |
| 195 | + return ( |
| 196 | + await asyncio_detailed( |
| 197 | + id=id, |
| 198 | + client=client, |
| 199 | + body=body, |
| 200 | + ) |
| 201 | + ).parsed |
0 commit comments