|
| 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.create_dimension_request import CreateDimensionRequest |
| 10 | +from ...models.error_response import ErrorResponse |
| 11 | +from ...models.operation_envelope_dimension_response import ( |
| 12 | + OperationEnvelopeDimensionResponse, |
| 13 | +) |
| 14 | +from ...types import UNSET, Response, Unset |
| 15 | + |
| 16 | + |
| 17 | +def _get_kwargs( |
| 18 | + graph_id: str, |
| 19 | + *, |
| 20 | + body: CreateDimensionRequest, |
| 21 | + idempotency_key: None | str | Unset = UNSET, |
| 22 | +) -> dict[str, Any]: |
| 23 | + headers: dict[str, Any] = {} |
| 24 | + if not isinstance(idempotency_key, Unset): |
| 25 | + headers["Idempotency-Key"] = idempotency_key |
| 26 | + |
| 27 | + _kwargs: dict[str, Any] = { |
| 28 | + "method": "post", |
| 29 | + "url": "/extensions/roboledger/{graph_id}/operations/create-dimension".format( |
| 30 | + graph_id=quote(str(graph_id), safe=""), |
| 31 | + ), |
| 32 | + } |
| 33 | + |
| 34 | + _kwargs["json"] = body.to_dict() |
| 35 | + |
| 36 | + headers["Content-Type"] = "application/json" |
| 37 | + |
| 38 | + _kwargs["headers"] = headers |
| 39 | + return _kwargs |
| 40 | + |
| 41 | + |
| 42 | +def _parse_response( |
| 43 | + *, client: AuthenticatedClient | Client, response: httpx.Response |
| 44 | +) -> ErrorResponse | OperationEnvelopeDimensionResponse | None: |
| 45 | + if response.status_code == 200: |
| 46 | + response_200 = OperationEnvelopeDimensionResponse.from_dict(response.json()) |
| 47 | + |
| 48 | + return response_200 |
| 49 | + |
| 50 | + if response.status_code == 400: |
| 51 | + response_400 = ErrorResponse.from_dict(response.json()) |
| 52 | + |
| 53 | + return response_400 |
| 54 | + |
| 55 | + if response.status_code == 401: |
| 56 | + response_401 = ErrorResponse.from_dict(response.json()) |
| 57 | + |
| 58 | + return response_401 |
| 59 | + |
| 60 | + if response.status_code == 403: |
| 61 | + response_403 = ErrorResponse.from_dict(response.json()) |
| 62 | + |
| 63 | + return response_403 |
| 64 | + |
| 65 | + if response.status_code == 404: |
| 66 | + response_404 = ErrorResponse.from_dict(response.json()) |
| 67 | + |
| 68 | + return response_404 |
| 69 | + |
| 70 | + if response.status_code == 409: |
| 71 | + response_409 = ErrorResponse.from_dict(response.json()) |
| 72 | + |
| 73 | + return response_409 |
| 74 | + |
| 75 | + if response.status_code == 422: |
| 76 | + response_422 = ErrorResponse.from_dict(response.json()) |
| 77 | + |
| 78 | + return response_422 |
| 79 | + |
| 80 | + if response.status_code == 429: |
| 81 | + response_429 = ErrorResponse.from_dict(response.json()) |
| 82 | + |
| 83 | + return response_429 |
| 84 | + |
| 85 | + if response.status_code == 500: |
| 86 | + response_500 = ErrorResponse.from_dict(response.json()) |
| 87 | + |
| 88 | + return response_500 |
| 89 | + |
| 90 | + if client.raise_on_unexpected_status: |
| 91 | + raise errors.UnexpectedStatus(response.status_code, response.content) |
| 92 | + else: |
| 93 | + return None |
| 94 | + |
| 95 | + |
| 96 | +def _build_response( |
| 97 | + *, client: AuthenticatedClient | Client, response: httpx.Response |
| 98 | +) -> Response[ErrorResponse | OperationEnvelopeDimensionResponse]: |
| 99 | + return Response( |
| 100 | + status_code=HTTPStatus(response.status_code), |
| 101 | + content=response.content, |
| 102 | + headers=response.headers, |
| 103 | + parsed=_parse_response(client=client, response=response), |
| 104 | + ) |
| 105 | + |
| 106 | + |
| 107 | +def sync_detailed( |
| 108 | + graph_id: str, |
| 109 | + *, |
| 110 | + client: AuthenticatedClient, |
| 111 | + body: CreateDimensionRequest, |
| 112 | + idempotency_key: None | str | Unset = UNSET, |
| 113 | +) -> Response[ErrorResponse | OperationEnvelopeDimensionResponse]: |
| 114 | + """Create Dimension |
| 115 | +
|
| 116 | + Add a member to a management dimension: a department, class, location or project (or an axis of your |
| 117 | + own) that ledger lines can carry, one member per axis per line. `value` is the member's stable key |
| 118 | + within its axis, a slug of the name when omitted; a second member with the same key returns 409. Tag |
| 119 | + lines with its id through `dimension_ids` on a journal line, and read the income statement by it |
| 120 | + with `live-financial-statement`'s `dimension`. |
| 121 | +
|
| 122 | + **Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours |
| 123 | + return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict. |
| 124 | +
|
| 125 | + Args: |
| 126 | + graph_id (str): |
| 127 | + idempotency_key (None | str | Unset): |
| 128 | + body (CreateDimensionRequest): Add a member to a management dimension. |
| 129 | +
|
| 130 | + Raises: |
| 131 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 132 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 133 | +
|
| 134 | + Returns: |
| 135 | + Response[ErrorResponse | OperationEnvelopeDimensionResponse] |
| 136 | + """ |
| 137 | + |
| 138 | + kwargs = _get_kwargs( |
| 139 | + graph_id=graph_id, |
| 140 | + body=body, |
| 141 | + idempotency_key=idempotency_key, |
| 142 | + ) |
| 143 | + |
| 144 | + response = client.get_httpx_client().request( |
| 145 | + **kwargs, |
| 146 | + ) |
| 147 | + |
| 148 | + return _build_response(client=client, response=response) |
| 149 | + |
| 150 | + |
| 151 | +def sync( |
| 152 | + graph_id: str, |
| 153 | + *, |
| 154 | + client: AuthenticatedClient, |
| 155 | + body: CreateDimensionRequest, |
| 156 | + idempotency_key: None | str | Unset = UNSET, |
| 157 | +) -> ErrorResponse | OperationEnvelopeDimensionResponse | None: |
| 158 | + """Create Dimension |
| 159 | +
|
| 160 | + Add a member to a management dimension: a department, class, location or project (or an axis of your |
| 161 | + own) that ledger lines can carry, one member per axis per line. `value` is the member's stable key |
| 162 | + within its axis, a slug of the name when omitted; a second member with the same key returns 409. Tag |
| 163 | + lines with its id through `dimension_ids` on a journal line, and read the income statement by it |
| 164 | + with `live-financial-statement`'s `dimension`. |
| 165 | +
|
| 166 | + **Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours |
| 167 | + return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict. |
| 168 | +
|
| 169 | + Args: |
| 170 | + graph_id (str): |
| 171 | + idempotency_key (None | str | Unset): |
| 172 | + body (CreateDimensionRequest): Add a member to a management dimension. |
| 173 | +
|
| 174 | + Raises: |
| 175 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 176 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 177 | +
|
| 178 | + Returns: |
| 179 | + ErrorResponse | OperationEnvelopeDimensionResponse |
| 180 | + """ |
| 181 | + |
| 182 | + return sync_detailed( |
| 183 | + graph_id=graph_id, |
| 184 | + client=client, |
| 185 | + body=body, |
| 186 | + idempotency_key=idempotency_key, |
| 187 | + ).parsed |
| 188 | + |
| 189 | + |
| 190 | +async def asyncio_detailed( |
| 191 | + graph_id: str, |
| 192 | + *, |
| 193 | + client: AuthenticatedClient, |
| 194 | + body: CreateDimensionRequest, |
| 195 | + idempotency_key: None | str | Unset = UNSET, |
| 196 | +) -> Response[ErrorResponse | OperationEnvelopeDimensionResponse]: |
| 197 | + """Create Dimension |
| 198 | +
|
| 199 | + Add a member to a management dimension: a department, class, location or project (or an axis of your |
| 200 | + own) that ledger lines can carry, one member per axis per line. `value` is the member's stable key |
| 201 | + within its axis, a slug of the name when omitted; a second member with the same key returns 409. Tag |
| 202 | + lines with its id through `dimension_ids` on a journal line, and read the income statement by it |
| 203 | + with `live-financial-statement`'s `dimension`. |
| 204 | +
|
| 205 | + **Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours |
| 206 | + return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict. |
| 207 | +
|
| 208 | + Args: |
| 209 | + graph_id (str): |
| 210 | + idempotency_key (None | str | Unset): |
| 211 | + body (CreateDimensionRequest): Add a member to a management dimension. |
| 212 | +
|
| 213 | + Raises: |
| 214 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 215 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 216 | +
|
| 217 | + Returns: |
| 218 | + Response[ErrorResponse | OperationEnvelopeDimensionResponse] |
| 219 | + """ |
| 220 | + |
| 221 | + kwargs = _get_kwargs( |
| 222 | + graph_id=graph_id, |
| 223 | + body=body, |
| 224 | + idempotency_key=idempotency_key, |
| 225 | + ) |
| 226 | + |
| 227 | + response = await client.get_async_httpx_client().request(**kwargs) |
| 228 | + |
| 229 | + return _build_response(client=client, response=response) |
| 230 | + |
| 231 | + |
| 232 | +async def asyncio( |
| 233 | + graph_id: str, |
| 234 | + *, |
| 235 | + client: AuthenticatedClient, |
| 236 | + body: CreateDimensionRequest, |
| 237 | + idempotency_key: None | str | Unset = UNSET, |
| 238 | +) -> ErrorResponse | OperationEnvelopeDimensionResponse | None: |
| 239 | + """Create Dimension |
| 240 | +
|
| 241 | + Add a member to a management dimension: a department, class, location or project (or an axis of your |
| 242 | + own) that ledger lines can carry, one member per axis per line. `value` is the member's stable key |
| 243 | + within its axis, a slug of the name when omitted; a second member with the same key returns 409. Tag |
| 244 | + lines with its id through `dimension_ids` on a journal line, and read the income statement by it |
| 245 | + with `live-financial-statement`'s `dimension`. |
| 246 | +
|
| 247 | + **Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours |
| 248 | + return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict. |
| 249 | +
|
| 250 | + Args: |
| 251 | + graph_id (str): |
| 252 | + idempotency_key (None | str | Unset): |
| 253 | + body (CreateDimensionRequest): Add a member to a management dimension. |
| 254 | +
|
| 255 | + Raises: |
| 256 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 257 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 258 | +
|
| 259 | + Returns: |
| 260 | + ErrorResponse | OperationEnvelopeDimensionResponse |
| 261 | + """ |
| 262 | + |
| 263 | + return ( |
| 264 | + await asyncio_detailed( |
| 265 | + graph_id=graph_id, |
| 266 | + client=client, |
| 267 | + body=body, |
| 268 | + idempotency_key=idempotency_key, |
| 269 | + ) |
| 270 | + ).parsed |
0 commit comments