| 1 |
|
| 2 |
|
| 3 |
import typing |
| 4 |
from json.decoder import JSONDecodeError |
| 5 |
|
| 6 |
from ..core.api_error import ApiError |
| 7 |
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper |
| 8 |
from ..core.http_response import AsyncHttpResponse, HttpResponse |
| 9 |
from ..core.jsonable_encoder import encode_path_param |
| 10 |
from ..core.pagination import AsyncPager, SyncPager |
| 11 |
from ..core.parse_error import ParsingError |
| 12 |
from ..core.pydantic_utilities import parse_obj_as |
| 13 |
from ..core.request_options import RequestOptions |
| 14 |
from ..core.serialization import convert_and_respect_annotation_metadata |
| 15 |
from ..errors.bad_request_error import BadRequestError |
| 16 |
from ..errors.forbidden_error import ForbiddenError |
| 17 |
from ..errors.not_found_error import NotFoundError |
| 18 |
from ..errors.too_many_requests_error import TooManyRequestsError |
| 19 |
from ..errors.unauthorized_error import UnauthorizedError |
| 20 |
from ..types.create_flow_response_content import CreateFlowResponseContent |
| 21 |
from ..types.flow_action import FlowAction |
| 22 |
from ..types.flow_summary import FlowSummary |
| 23 |
from ..types.get_flow_request_parameters_hydrate_enum import GetFlowRequestParametersHydrateEnum |
| 24 |
from ..types.get_flow_response_content import GetFlowResponseContent |
| 25 |
from ..types.list_flows_offset_paginated_response_content import ListFlowsOffsetPaginatedResponseContent |
| 26 |
from ..types.list_flows_request_parameters_hydrate_enum import ListFlowsRequestParametersHydrateEnum |
| 27 |
from ..types.update_flow_response_content import UpdateFlowResponseContent |
| 28 |
from pydantic import ValidationError |
| 29 |
|
| 30 |
|
| 31 |
OMIT = typing.cast(typing.Any, ...) |
| 32 |
|
| 33 |
|
| 34 |
class RawFlowsClient: |
| 35 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 36 |
self._client_wrapper = client_wrapper |
| 37 |
|
| 38 |
def list( |
| 39 |
self, |
| 40 |
*, |
| 41 |
page: typing.Optional[int] = 0, |
| 42 |
per_page: typing.Optional[int] = 50, |
| 43 |
include_totals: typing.Optional[bool] = True, |
| 44 |
hydrate: typing.Optional[ |
| 45 |
typing.Union[ListFlowsRequestParametersHydrateEnum, typing.Sequence[ListFlowsRequestParametersHydrateEnum]] |
| 46 |
] = None, |
| 47 |
synchronous: typing.Optional[bool] = None, |
| 48 |
request_options: typing.Optional[RequestOptions] = None, |
| 49 |
) -> SyncPager[FlowSummary, ListFlowsOffsetPaginatedResponseContent]: |
| 50 |
""" |
| 51 |
Parameters |
| 52 |
---------- |
| 53 |
page : typing.Optional[int] |
| 54 |
Page index of the results to return. First page is 0. |
| 55 |
|
| 56 |
per_page : typing.Optional[int] |
| 57 |
Number of results per page. Defaults to 50. |
| 58 |
|
| 59 |
include_totals : typing.Optional[bool] |
| 60 |
Return results inside an object that contains the total result count (true) or as a direct array of results (false, default). |
| 61 |
|
| 62 |
hydrate : typing.Optional[typing.Union[ListFlowsRequestParametersHydrateEnum, typing.Sequence[ListFlowsRequestParametersHydrateEnum]]] |
| 63 |
hydration param |
| 64 |
|
| 65 |
synchronous : typing.Optional[bool] |
| 66 |
flag to filter by sync/async flows |
| 67 |
|
| 68 |
request_options : typing.Optional[RequestOptions] |
| 69 |
Request-specific configuration. |
| 70 |
|
| 71 |
Returns |
| 72 |
------- |
| 73 |
SyncPager[FlowSummary, ListFlowsOffsetPaginatedResponseContent] |
| 74 |
Flows successfully retrieved. |
| 75 |
""" |
| 76 |
page = page if page is not None else 0 |
| 77 |
|
| 78 |
_response = self._client_wrapper.httpx_client.request( |
| 79 |
"flows", |
| 80 |
method="GET", |
| 81 |
params={ |
| 82 |
"page": page, |
| 83 |
"per_page": per_page, |
| 84 |
"include_totals": include_totals, |
| 85 |
"hydrate": hydrate, |
| 86 |
"synchronous": synchronous, |
| 87 |
}, |
| 88 |
request_options=request_options, |
| 89 |
) |
| 90 |
try: |
| 91 |
if 200 <= _response.status_code < 300: |
| 92 |
_parsed_response = typing.cast( |
| 93 |
ListFlowsOffsetPaginatedResponseContent, |
| 94 |
parse_obj_as( |
| 95 |
type_=ListFlowsOffsetPaginatedResponseContent, |
| 96 |
object_=_response.json(), |
| 97 |
), |
| 98 |
) |
| 99 |
_items = _parsed_response.flows |
| 100 |
_has_next = len(_items or []) > 0 |
| 101 |
_get_next = lambda: self.list( |
| 102 |
page=page + 1, |
| 103 |
per_page=per_page, |
| 104 |
include_totals=include_totals, |
| 105 |
hydrate=hydrate, |
| 106 |
synchronous=synchronous, |
| 107 |
request_options=request_options, |
| 108 |
) |
| 109 |
return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) |
| 110 |
if _response.status_code == 400: |
| 111 |
raise BadRequestError( |
| 112 |
headers=dict(_response.headers), |
| 113 |
body=typing.cast( |
| 114 |
typing.Any, |
| 115 |
parse_obj_as( |
| 116 |
type_=typing.Any, |
| 117 |
object_=_response.json(), |
| 118 |
), |
| 119 |
), |
| 120 |
) |
| 121 |
if _response.status_code == 401: |
| 122 |
raise UnauthorizedError( |
| 123 |
headers=dict(_response.headers), |
| 124 |
body=typing.cast( |
| 125 |
typing.Any, |
| 126 |
parse_obj_as( |
| 127 |
type_=typing.Any, |
| 128 |
object_=_response.json(), |
| 129 |
), |
| 130 |
), |
| 131 |
) |
| 132 |
if _response.status_code == 403: |
| 133 |
raise ForbiddenError( |
| 134 |
headers=dict(_response.headers), |
| 135 |
body=typing.cast( |
| 136 |
typing.Any, |
| 137 |
parse_obj_as( |
| 138 |
type_=typing.Any, |
| 139 |
object_=_response.json(), |
| 140 |
), |
| 141 |
), |
| 142 |
) |
| 143 |
if _response.status_code == 429: |
| 144 |
raise TooManyRequestsError( |
| 145 |
headers=dict(_response.headers), |
| 146 |
body=typing.cast( |
| 147 |
typing.Any, |
| 148 |
parse_obj_as( |
| 149 |
type_=typing.Any, |
| 150 |
object_=_response.json(), |
| 151 |
), |
| 152 |
), |
| 153 |
) |
| 154 |
_response_json = _response.json() |
| 155 |
except JSONDecodeError: |
| 156 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 157 |
except ValidationError as e: |
| 158 |
raise ParsingError( |
| 159 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 160 |
) |
| 161 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 162 |
|
| 163 |
def create( |
| 164 |
self, |
| 165 |
*, |
| 166 |
name: str, |
| 167 |
actions: typing.Optional[typing.Sequence[FlowAction]] = OMIT, |
| 168 |
request_options: typing.Optional[RequestOptions] = None, |
| 169 |
) -> HttpResponse[CreateFlowResponseContent]: |
| 170 |
""" |
| 171 |
Parameters |
| 172 |
---------- |
| 173 |
name : str |
| 174 |
|
| 175 |
actions : typing.Optional[typing.Sequence[FlowAction]] |
| 176 |
|
| 177 |
request_options : typing.Optional[RequestOptions] |
| 178 |
Request-specific configuration. |
| 179 |
|
| 180 |
Returns |
| 181 |
------- |
| 182 |
HttpResponse[CreateFlowResponseContent] |
| 183 |
Flow successfully created. |
| 184 |
""" |
| 185 |
_response = self._client_wrapper.httpx_client.request( |
| 186 |
"flows", |
| 187 |
method="POST", |
| 188 |
json={ |
| 189 |
"name": name, |
| 190 |
"actions": convert_and_respect_annotation_metadata( |
| 191 |
object_=actions, annotation=typing.Sequence[FlowAction], direction="write" |
| 192 |
), |
| 193 |
}, |
| 194 |
headers={ |
| 195 |
"content-type": "application/json", |
| 196 |
}, |
| 197 |
request_options=request_options, |
| 198 |
omit=OMIT, |
| 199 |
) |
| 200 |
try: |
| 201 |
if 200 <= _response.status_code < 300: |
| 202 |
_data = typing.cast( |
| 203 |
CreateFlowResponseContent, |
| 204 |
parse_obj_as( |
| 205 |
type_=CreateFlowResponseContent, |
| 206 |
object_=_response.json(), |
| 207 |
), |
| 208 |
) |
| 209 |
return HttpResponse(response=_response, data=_data) |
| 210 |
if _response.status_code == 400: |
| 211 |
raise BadRequestError( |
| 212 |
headers=dict(_response.headers), |
| 213 |
body=typing.cast( |
| 214 |
typing.Any, |
| 215 |
parse_obj_as( |
| 216 |
type_=typing.Any, |
| 217 |
object_=_response.json(), |
| 218 |
), |
| 219 |
), |
| 220 |
) |
| 221 |
if _response.status_code == 401: |
| 222 |
raise UnauthorizedError( |
| 223 |
headers=dict(_response.headers), |
| 224 |
body=typing.cast( |
| 225 |
typing.Any, |
| 226 |
parse_obj_as( |
| 227 |
type_=typing.Any, |
| 228 |
object_=_response.json(), |
| 229 |
), |
| 230 |
), |
| 231 |
) |
| 232 |
if _response.status_code == 403: |
| 233 |
raise ForbiddenError( |
| 234 |
headers=dict(_response.headers), |
| 235 |
body=typing.cast( |
| 236 |
typing.Any, |
| 237 |
parse_obj_as( |
| 238 |
type_=typing.Any, |
| 239 |
object_=_response.json(), |
| 240 |
), |
| 241 |
), |
| 242 |
) |
| 243 |
if _response.status_code == 429: |
| 244 |
raise TooManyRequestsError( |
| 245 |
headers=dict(_response.headers), |
| 246 |
body=typing.cast( |
| 247 |
typing.Any, |
| 248 |
parse_obj_as( |
| 249 |
type_=typing.Any, |
| 250 |
object_=_response.json(), |
| 251 |
), |
| 252 |
), |
| 253 |
) |
| 254 |
_response_json = _response.json() |
| 255 |
except JSONDecodeError: |
| 256 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 257 |
except ValidationError as e: |
| 258 |
raise ParsingError( |
| 259 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 260 |
) |
| 261 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 262 |
|
| 263 |
def get( |
| 264 |
self, |
| 265 |
id: str, |
| 266 |
*, |
| 267 |
hydrate: typing.Optional[ |
| 268 |
typing.Union[GetFlowRequestParametersHydrateEnum, typing.Sequence[GetFlowRequestParametersHydrateEnum]] |
| 269 |
] = None, |
| 270 |
request_options: typing.Optional[RequestOptions] = None, |
| 271 |
) -> HttpResponse[GetFlowResponseContent]: |
| 272 |
""" |
| 273 |
Parameters |
| 274 |
---------- |
| 275 |
id : str |
| 276 |
Flow identifier |
| 277 |
|
| 278 |
hydrate : typing.Optional[typing.Union[GetFlowRequestParametersHydrateEnum, typing.Sequence[GetFlowRequestParametersHydrateEnum]]] |
| 279 |
hydration param |
| 280 |
|
| 281 |
request_options : typing.Optional[RequestOptions] |
| 282 |
Request-specific configuration. |
| 283 |
|
| 284 |
Returns |
| 285 |
------- |
| 286 |
HttpResponse[GetFlowResponseContent] |
| 287 |
Flow successfully retrieved. |
| 288 |
""" |
| 289 |
_response = self._client_wrapper.httpx_client.request( |
| 290 |
f"flows/{encode_path_param(id)}", |
| 291 |
method="GET", |
| 292 |
params={ |
| 293 |
"hydrate": hydrate, |
| 294 |
}, |
| 295 |
request_options=request_options, |
| 296 |
) |
| 297 |
try: |
| 298 |
if 200 <= _response.status_code < 300: |
| 299 |
_data = typing.cast( |
| 300 |
GetFlowResponseContent, |
| 301 |
parse_obj_as( |
| 302 |
type_=GetFlowResponseContent, |
| 303 |
object_=_response.json(), |
| 304 |
), |
| 305 |
) |
| 306 |
return HttpResponse(response=_response, data=_data) |
| 307 |
if _response.status_code == 400: |
| 308 |
raise BadRequestError( |
| 309 |
headers=dict(_response.headers), |
| 310 |
body=typing.cast( |
| 311 |
typing.Any, |
| 312 |
parse_obj_as( |
| 313 |
type_=typing.Any, |
| 314 |
object_=_response.json(), |
| 315 |
), |
| 316 |
), |
| 317 |
) |
| 318 |
if _response.status_code == 401: |
| 319 |
raise UnauthorizedError( |
| 320 |
headers=dict(_response.headers), |
| 321 |
body=typing.cast( |
| 322 |
typing.Any, |
| 323 |
parse_obj_as( |
| 324 |
type_=typing.Any, |
| 325 |
object_=_response.json(), |
| 326 |
), |
| 327 |
), |
| 328 |
) |
| 329 |
if _response.status_code == 403: |
| 330 |
raise ForbiddenError( |
| 331 |
headers=dict(_response.headers), |
| 332 |
body=typing.cast( |
| 333 |
typing.Any, |
| 334 |
parse_obj_as( |
| 335 |
type_=typing.Any, |
| 336 |
object_=_response.json(), |
| 337 |
), |
| 338 |
), |
| 339 |
) |
| 340 |
if _response.status_code == 404: |
| 341 |
raise NotFoundError( |
| 342 |
headers=dict(_response.headers), |
| 343 |
body=typing.cast( |
| 344 |
typing.Any, |
| 345 |
parse_obj_as( |
| 346 |
type_=typing.Any, |
| 347 |
object_=_response.json(), |
| 348 |
), |
| 349 |
), |
| 350 |
) |
| 351 |
if _response.status_code == 429: |
| 352 |
raise TooManyRequestsError( |
| 353 |
headers=dict(_response.headers), |
| 354 |
body=typing.cast( |
| 355 |
typing.Any, |
| 356 |
parse_obj_as( |
| 357 |
type_=typing.Any, |
| 358 |
object_=_response.json(), |
| 359 |
), |
| 360 |
), |
| 361 |
) |
| 362 |
_response_json = _response.json() |
| 363 |
except JSONDecodeError: |
| 364 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 365 |
except ValidationError as e: |
| 366 |
raise ParsingError( |
| 367 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 368 |
) |
| 369 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 370 |
|
| 371 |
def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]: |
| 372 |
""" |
| 373 |
Parameters |
| 374 |
---------- |
| 375 |
id : str |
| 376 |
Flow id |
| 377 |
|
| 378 |
request_options : typing.Optional[RequestOptions] |
| 379 |
Request-specific configuration. |
| 380 |
|
| 381 |
Returns |
| 382 |
------- |
| 383 |
HttpResponse[None] |
| 384 |
""" |
| 385 |
_response = self._client_wrapper.httpx_client.request( |
| 386 |
f"flows/{encode_path_param(id)}", |
| 387 |
method="DELETE", |
| 388 |
request_options=request_options, |
| 389 |
) |
| 390 |
try: |
| 391 |
if 200 <= _response.status_code < 300: |
| 392 |
return HttpResponse(response=_response, data=None) |
| 393 |
if _response.status_code == 400: |
| 394 |
raise BadRequestError( |
| 395 |
headers=dict(_response.headers), |
| 396 |
body=typing.cast( |
| 397 |
typing.Any, |
| 398 |
parse_obj_as( |
| 399 |
type_=typing.Any, |
| 400 |
object_=_response.json(), |
| 401 |
), |
| 402 |
), |
| 403 |
) |
| 404 |
if _response.status_code == 401: |
| 405 |
raise UnauthorizedError( |
| 406 |
headers=dict(_response.headers), |
| 407 |
body=typing.cast( |
| 408 |
typing.Any, |
| 409 |
parse_obj_as( |
| 410 |
type_=typing.Any, |
| 411 |
object_=_response.json(), |
| 412 |
), |
| 413 |
), |
| 414 |
) |
| 415 |
if _response.status_code == 403: |
| 416 |
raise ForbiddenError( |
| 417 |
headers=dict(_response.headers), |
| 418 |
body=typing.cast( |
| 419 |
typing.Any, |
| 420 |
parse_obj_as( |
| 421 |
type_=typing.Any, |
| 422 |
object_=_response.json(), |
| 423 |
), |
| 424 |
), |
| 425 |
) |
| 426 |
if _response.status_code == 404: |
| 427 |
raise NotFoundError( |
| 428 |
headers=dict(_response.headers), |
| 429 |
body=typing.cast( |
| 430 |
typing.Any, |
| 431 |
parse_obj_as( |
| 432 |
type_=typing.Any, |
| 433 |
object_=_response.json(), |
| 434 |
), |
| 435 |
), |
| 436 |
) |
| 437 |
if _response.status_code == 429: |
| 438 |
raise TooManyRequestsError( |
| 439 |
headers=dict(_response.headers), |
| 440 |
body=typing.cast( |
| 441 |
typing.Any, |
| 442 |
parse_obj_as( |
| 443 |
type_=typing.Any, |
| 444 |
object_=_response.json(), |
| 445 |
), |
| 446 |
), |
| 447 |
) |
| 448 |
_response_json = _response.json() |
| 449 |
except JSONDecodeError: |
| 450 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 451 |
except ValidationError as e: |
| 452 |
raise ParsingError( |
| 453 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 454 |
) |
| 455 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 456 |
|
| 457 |
def update( |
| 458 |
self, |
| 459 |
id: str, |
| 460 |
*, |
| 461 |
name: typing.Optional[str] = OMIT, |
| 462 |
actions: typing.Optional[typing.Sequence[FlowAction]] = OMIT, |
| 463 |
request_options: typing.Optional[RequestOptions] = None, |
| 464 |
) -> HttpResponse[UpdateFlowResponseContent]: |
| 465 |
""" |
| 466 |
Parameters |
| 467 |
---------- |
| 468 |
id : str |
| 469 |
Flow identifier |
| 470 |
|
| 471 |
name : typing.Optional[str] |
| 472 |
|
| 473 |
actions : typing.Optional[typing.Sequence[FlowAction]] |
| 474 |
|
| 475 |
request_options : typing.Optional[RequestOptions] |
| 476 |
Request-specific configuration. |
| 477 |
|
| 478 |
Returns |
| 479 |
------- |
| 480 |
HttpResponse[UpdateFlowResponseContent] |
| 481 |
Flow successfully updated. |
| 482 |
""" |
| 483 |
_response = self._client_wrapper.httpx_client.request( |
| 484 |
f"flows/{encode_path_param(id)}", |
| 485 |
method="PATCH", |
| 486 |
json={ |
| 487 |
"name": name, |
| 488 |
"actions": convert_and_respect_annotation_metadata( |
| 489 |
object_=actions, annotation=typing.Optional[typing.Sequence[FlowAction]], direction="write" |
| 490 |
), |
| 491 |
}, |
| 492 |
headers={ |
| 493 |
"content-type": "application/json", |
| 494 |
}, |
| 495 |
request_options=request_options, |
| 496 |
omit=OMIT, |
| 497 |
) |
| 498 |
try: |
| 499 |
if 200 <= _response.status_code < 300: |
| 500 |
_data = typing.cast( |
| 501 |
UpdateFlowResponseContent, |
| 502 |
parse_obj_as( |
| 503 |
type_=UpdateFlowResponseContent, |
| 504 |
object_=_response.json(), |
| 505 |
), |
| 506 |
) |
| 507 |
return HttpResponse(response=_response, data=_data) |
| 508 |
if _response.status_code == 401: |
| 509 |
raise UnauthorizedError( |
| 510 |
headers=dict(_response.headers), |
| 511 |
body=typing.cast( |
| 512 |
typing.Any, |
| 513 |
parse_obj_as( |
| 514 |
type_=typing.Any, |
| 515 |
object_=_response.json(), |
| 516 |
), |
| 517 |
), |
| 518 |
) |
| 519 |
if _response.status_code == 403: |
| 520 |
raise ForbiddenError( |
| 521 |
headers=dict(_response.headers), |
| 522 |
body=typing.cast( |
| 523 |
typing.Any, |
| 524 |
parse_obj_as( |
| 525 |
type_=typing.Any, |
| 526 |
object_=_response.json(), |
| 527 |
), |
| 528 |
), |
| 529 |
) |
| 530 |
if _response.status_code == 404: |
| 531 |
raise NotFoundError( |
| 532 |
headers=dict(_response.headers), |
| 533 |
body=typing.cast( |
| 534 |
typing.Any, |
| 535 |
parse_obj_as( |
| 536 |
type_=typing.Any, |
| 537 |
object_=_response.json(), |
| 538 |
), |
| 539 |
), |
| 540 |
) |
| 541 |
if _response.status_code == 429: |
| 542 |
raise TooManyRequestsError( |
| 543 |
headers=dict(_response.headers), |
| 544 |
body=typing.cast( |
| 545 |
typing.Any, |
| 546 |
parse_obj_as( |
| 547 |
type_=typing.Any, |
| 548 |
object_=_response.json(), |
| 549 |
), |
| 550 |
), |
| 551 |
) |
| 552 |
_response_json = _response.json() |
| 553 |
except JSONDecodeError: |
| 554 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 555 |
except ValidationError as e: |
| 556 |
raise ParsingError( |
| 557 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 558 |
) |
| 559 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 560 |
|
| 561 |
|
| 562 |
class AsyncRawFlowsClient: |
| 563 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 564 |
self._client_wrapper = client_wrapper |
| 565 |
|
| 566 |
async def list( |
| 567 |
self, |
| 568 |
*, |
| 569 |
page: typing.Optional[int] = 0, |
| 570 |
per_page: typing.Optional[int] = 50, |
| 571 |
include_totals: typing.Optional[bool] = True, |
| 572 |
hydrate: typing.Optional[ |
| 573 |
typing.Union[ListFlowsRequestParametersHydrateEnum, typing.Sequence[ListFlowsRequestParametersHydrateEnum]] |
| 574 |
] = None, |
| 575 |
synchronous: typing.Optional[bool] = None, |
| 576 |
request_options: typing.Optional[RequestOptions] = None, |
| 577 |
) -> AsyncPager[FlowSummary, ListFlowsOffsetPaginatedResponseContent]: |
| 578 |
""" |
| 579 |
Parameters |
| 580 |
---------- |
| 581 |
page : typing.Optional[int] |
| 582 |
Page index of the results to return. First page is 0. |
| 583 |
|
| 584 |
per_page : typing.Optional[int] |
| 585 |
Number of results per page. Defaults to 50. |
| 586 |
|
| 587 |
include_totals : typing.Optional[bool] |
| 588 |
Return results inside an object that contains the total result count (true) or as a direct array of results (false, default). |
| 589 |
|
| 590 |
hydrate : typing.Optional[typing.Union[ListFlowsRequestParametersHydrateEnum, typing.Sequence[ListFlowsRequestParametersHydrateEnum]]] |
| 591 |
hydration param |
| 592 |
|
| 593 |
synchronous : typing.Optional[bool] |
| 594 |
flag to filter by sync/async flows |
| 595 |
|
| 596 |
request_options : typing.Optional[RequestOptions] |
| 597 |
Request-specific configuration. |
| 598 |
|
| 599 |
Returns |
| 600 |
------- |
| 601 |
AsyncPager[FlowSummary, ListFlowsOffsetPaginatedResponseContent] |
| 602 |
Flows successfully retrieved. |
| 603 |
""" |
| 604 |
page = page if page is not None else 0 |
| 605 |
|
| 606 |
_response = await self._client_wrapper.httpx_client.request( |
| 607 |
"flows", |
| 608 |
method="GET", |
| 609 |
params={ |
| 610 |
"page": page, |
| 611 |
"per_page": per_page, |
| 612 |
"include_totals": include_totals, |
| 613 |
"hydrate": hydrate, |
| 614 |
"synchronous": synchronous, |
| 615 |
}, |
| 616 |
request_options=request_options, |
| 617 |
) |
| 618 |
try: |
| 619 |
if 200 <= _response.status_code < 300: |
| 620 |
_parsed_response = typing.cast( |
| 621 |
ListFlowsOffsetPaginatedResponseContent, |
| 622 |
parse_obj_as( |
| 623 |
type_=ListFlowsOffsetPaginatedResponseContent, |
| 624 |
object_=_response.json(), |
| 625 |
), |
| 626 |
) |
| 627 |
_items = _parsed_response.flows |
| 628 |
_has_next = len(_items or []) > 0 |
| 629 |
|
| 630 |
async def _get_next(): |
| 631 |
return await self.list( |
| 632 |
page=page + 1, |
| 633 |
per_page=per_page, |
| 634 |
include_totals=include_totals, |
| 635 |
hydrate=hydrate, |
| 636 |
synchronous=synchronous, |
| 637 |
request_options=request_options, |
| 638 |
) |
| 639 |
|
| 640 |
return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) |
| 641 |
if _response.status_code == 400: |
| 642 |
raise BadRequestError( |
| 643 |
headers=dict(_response.headers), |
| 644 |
body=typing.cast( |
| 645 |
typing.Any, |
| 646 |
parse_obj_as( |
| 647 |
type_=typing.Any, |
| 648 |
object_=_response.json(), |
| 649 |
), |
| 650 |
), |
| 651 |
) |
| 652 |
if _response.status_code == 401: |
| 653 |
raise UnauthorizedError( |
| 654 |
headers=dict(_response.headers), |
| 655 |
body=typing.cast( |
| 656 |
typing.Any, |
| 657 |
parse_obj_as( |
| 658 |
type_=typing.Any, |
| 659 |
object_=_response.json(), |
| 660 |
), |
| 661 |
), |
| 662 |
) |
| 663 |
if _response.status_code == 403: |
| 664 |
raise ForbiddenError( |
| 665 |
headers=dict(_response.headers), |
| 666 |
body=typing.cast( |
| 667 |
typing.Any, |
| 668 |
parse_obj_as( |
| 669 |
type_=typing.Any, |
| 670 |
object_=_response.json(), |
| 671 |
), |
| 672 |
), |
| 673 |
) |
| 674 |
if _response.status_code == 429: |
| 675 |
raise TooManyRequestsError( |
| 676 |
headers=dict(_response.headers), |
| 677 |
body=typing.cast( |
| 678 |
typing.Any, |
| 679 |
parse_obj_as( |
| 680 |
type_=typing.Any, |
| 681 |
object_=_response.json(), |
| 682 |
), |
| 683 |
), |
| 684 |
) |
| 685 |
_response_json = _response.json() |
| 686 |
except JSONDecodeError: |
| 687 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 688 |
except ValidationError as e: |
| 689 |
raise ParsingError( |
| 690 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 691 |
) |
| 692 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 693 |
|
| 694 |
async def create( |
| 695 |
self, |
| 696 |
*, |
| 697 |
name: str, |
| 698 |
actions: typing.Optional[typing.Sequence[FlowAction]] = OMIT, |
| 699 |
request_options: typing.Optional[RequestOptions] = None, |
| 700 |
) -> AsyncHttpResponse[CreateFlowResponseContent]: |
| 701 |
""" |
| 702 |
Parameters |
| 703 |
---------- |
| 704 |
name : str |
| 705 |
|
| 706 |
actions : typing.Optional[typing.Sequence[FlowAction]] |
| 707 |
|
| 708 |
request_options : typing.Optional[RequestOptions] |
| 709 |
Request-specific configuration. |
| 710 |
|
| 711 |
Returns |
| 712 |
------- |
| 713 |
AsyncHttpResponse[CreateFlowResponseContent] |
| 714 |
Flow successfully created. |
| 715 |
""" |
| 716 |
_response = await self._client_wrapper.httpx_client.request( |
| 717 |
"flows", |
| 718 |
method="POST", |
| 719 |
json={ |
| 720 |
"name": name, |
| 721 |
"actions": convert_and_respect_annotation_metadata( |
| 722 |
object_=actions, annotation=typing.Sequence[FlowAction], direction="write" |
| 723 |
), |
| 724 |
}, |
| 725 |
headers={ |
| 726 |
"content-type": "application/json", |
| 727 |
}, |
| 728 |
request_options=request_options, |
| 729 |
omit=OMIT, |
| 730 |
) |
| 731 |
try: |
| 732 |
if 200 <= _response.status_code < 300: |
| 733 |
_data = typing.cast( |
| 734 |
CreateFlowResponseContent, |
| 735 |
parse_obj_as( |
| 736 |
type_=CreateFlowResponseContent, |
| 737 |
object_=_response.json(), |
| 738 |
), |
| 739 |
) |
| 740 |
return AsyncHttpResponse(response=_response, data=_data) |
| 741 |
if _response.status_code == 400: |
| 742 |
raise BadRequestError( |
| 743 |
headers=dict(_response.headers), |
| 744 |
body=typing.cast( |
| 745 |
typing.Any, |
| 746 |
parse_obj_as( |
| 747 |
type_=typing.Any, |
| 748 |
object_=_response.json(), |
| 749 |
), |
| 750 |
), |
| 751 |
) |
| 752 |
if _response.status_code == 401: |
| 753 |
raise UnauthorizedError( |
| 754 |
headers=dict(_response.headers), |
| 755 |
body=typing.cast( |
| 756 |
typing.Any, |
| 757 |
parse_obj_as( |
| 758 |
type_=typing.Any, |
| 759 |
object_=_response.json(), |
| 760 |
), |
| 761 |
), |
| 762 |
) |
| 763 |
if _response.status_code == 403: |
| 764 |
raise ForbiddenError( |
| 765 |
headers=dict(_response.headers), |
| 766 |
body=typing.cast( |
| 767 |
typing.Any, |
| 768 |
parse_obj_as( |
| 769 |
type_=typing.Any, |
| 770 |
object_=_response.json(), |
| 771 |
), |
| 772 |
), |
| 773 |
) |
| 774 |
if _response.status_code == 429: |
| 775 |
raise TooManyRequestsError( |
| 776 |
headers=dict(_response.headers), |
| 777 |
body=typing.cast( |
| 778 |
typing.Any, |
| 779 |
parse_obj_as( |
| 780 |
type_=typing.Any, |
| 781 |
object_=_response.json(), |
| 782 |
), |
| 783 |
), |
| 784 |
) |
| 785 |
_response_json = _response.json() |
| 786 |
except JSONDecodeError: |
| 787 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 788 |
except ValidationError as e: |
| 789 |
raise ParsingError( |
| 790 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 791 |
) |
| 792 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 793 |
|
| 794 |
async def get( |
| 795 |
self, |
| 796 |
id: str, |
| 797 |
*, |
| 798 |
hydrate: typing.Optional[ |
| 799 |
typing.Union[GetFlowRequestParametersHydrateEnum, typing.Sequence[GetFlowRequestParametersHydrateEnum]] |
| 800 |
] = None, |
| 801 |
request_options: typing.Optional[RequestOptions] = None, |
| 802 |
) -> AsyncHttpResponse[GetFlowResponseContent]: |
| 803 |
""" |
| 804 |
Parameters |
| 805 |
---------- |
| 806 |
id : str |
| 807 |
Flow identifier |
| 808 |
|
| 809 |
hydrate : typing.Optional[typing.Union[GetFlowRequestParametersHydrateEnum, typing.Sequence[GetFlowRequestParametersHydrateEnum]]] |
| 810 |
hydration param |
| 811 |
|
| 812 |
request_options : typing.Optional[RequestOptions] |
| 813 |
Request-specific configuration. |
| 814 |
|
| 815 |
Returns |
| 816 |
------- |
| 817 |
AsyncHttpResponse[GetFlowResponseContent] |
| 818 |
Flow successfully retrieved. |
| 819 |
""" |
| 820 |
_response = await self._client_wrapper.httpx_client.request( |
| 821 |
f"flows/{encode_path_param(id)}", |
| 822 |
method="GET", |
| 823 |
params={ |
| 824 |
"hydrate": hydrate, |
| 825 |
}, |
| 826 |
request_options=request_options, |
| 827 |
) |
| 828 |
try: |
| 829 |
if 200 <= _response.status_code < 300: |
| 830 |
_data = typing.cast( |
| 831 |
GetFlowResponseContent, |
| 832 |
parse_obj_as( |
| 833 |
type_=GetFlowResponseContent, |
| 834 |
object_=_response.json(), |
| 835 |
), |
| 836 |
) |
| 837 |
return AsyncHttpResponse(response=_response, data=_data) |
| 838 |
if _response.status_code == 400: |
| 839 |
raise BadRequestError( |
| 840 |
headers=dict(_response.headers), |
| 841 |
body=typing.cast( |
| 842 |
typing.Any, |
| 843 |
parse_obj_as( |
| 844 |
type_=typing.Any, |
| 845 |
object_=_response.json(), |
| 846 |
), |
| 847 |
), |
| 848 |
) |
| 849 |
if _response.status_code == 401: |
| 850 |
raise UnauthorizedError( |
| 851 |
headers=dict(_response.headers), |
| 852 |
body=typing.cast( |
| 853 |
typing.Any, |
| 854 |
parse_obj_as( |
| 855 |
type_=typing.Any, |
| 856 |
object_=_response.json(), |
| 857 |
), |
| 858 |
), |
| 859 |
) |
| 860 |
if _response.status_code == 403: |
| 861 |
raise ForbiddenError( |
| 862 |
headers=dict(_response.headers), |
| 863 |
body=typing.cast( |
| 864 |
typing.Any, |
| 865 |
parse_obj_as( |
| 866 |
type_=typing.Any, |
| 867 |
object_=_response.json(), |
| 868 |
), |
| 869 |
), |
| 870 |
) |
| 871 |
if _response.status_code == 404: |
| 872 |
raise NotFoundError( |
| 873 |
headers=dict(_response.headers), |
| 874 |
body=typing.cast( |
| 875 |
typing.Any, |
| 876 |
parse_obj_as( |
| 877 |
type_=typing.Any, |
| 878 |
object_=_response.json(), |
| 879 |
), |
| 880 |
), |
| 881 |
) |
| 882 |
if _response.status_code == 429: |
| 883 |
raise TooManyRequestsError( |
| 884 |
headers=dict(_response.headers), |
| 885 |
body=typing.cast( |
| 886 |
typing.Any, |
| 887 |
parse_obj_as( |
| 888 |
type_=typing.Any, |
| 889 |
object_=_response.json(), |
| 890 |
), |
| 891 |
), |
| 892 |
) |
| 893 |
_response_json = _response.json() |
| 894 |
except JSONDecodeError: |
| 895 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 896 |
except ValidationError as e: |
| 897 |
raise ParsingError( |
| 898 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 899 |
) |
| 900 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 901 |
|
| 902 |
async def delete( |
| 903 |
self, id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 904 |
) -> AsyncHttpResponse[None]: |
| 905 |
""" |
| 906 |
Parameters |
| 907 |
---------- |
| 908 |
id : str |
| 909 |
Flow id |
| 910 |
|
| 911 |
request_options : typing.Optional[RequestOptions] |
| 912 |
Request-specific configuration. |
| 913 |
|
| 914 |
Returns |
| 915 |
------- |
| 916 |
AsyncHttpResponse[None] |
| 917 |
""" |
| 918 |
_response = await self._client_wrapper.httpx_client.request( |
| 919 |
f"flows/{encode_path_param(id)}", |
| 920 |
method="DELETE", |
| 921 |
request_options=request_options, |
| 922 |
) |
| 923 |
try: |
| 924 |
if 200 <= _response.status_code < 300: |
| 925 |
return AsyncHttpResponse(response=_response, data=None) |
| 926 |
if _response.status_code == 400: |
| 927 |
raise BadRequestError( |
| 928 |
headers=dict(_response.headers), |
| 929 |
body=typing.cast( |
| 930 |
typing.Any, |
| 931 |
parse_obj_as( |
| 932 |
type_=typing.Any, |
| 933 |
object_=_response.json(), |
| 934 |
), |
| 935 |
), |
| 936 |
) |
| 937 |
if _response.status_code == 401: |
| 938 |
raise UnauthorizedError( |
| 939 |
headers=dict(_response.headers), |
| 940 |
body=typing.cast( |
| 941 |
typing.Any, |
| 942 |
parse_obj_as( |
| 943 |
type_=typing.Any, |
| 944 |
object_=_response.json(), |
| 945 |
), |
| 946 |
), |
| 947 |
) |
| 948 |
if _response.status_code == 403: |
| 949 |
raise ForbiddenError( |
| 950 |
headers=dict(_response.headers), |
| 951 |
body=typing.cast( |
| 952 |
typing.Any, |
| 953 |
parse_obj_as( |
| 954 |
type_=typing.Any, |
| 955 |
object_=_response.json(), |
| 956 |
), |
| 957 |
), |
| 958 |
) |
| 959 |
if _response.status_code == 404: |
| 960 |
raise NotFoundError( |
| 961 |
headers=dict(_response.headers), |
| 962 |
body=typing.cast( |
| 963 |
typing.Any, |
| 964 |
parse_obj_as( |
| 965 |
type_=typing.Any, |
| 966 |
object_=_response.json(), |
| 967 |
), |
| 968 |
), |
| 969 |
) |
| 970 |
if _response.status_code == 429: |
| 971 |
raise TooManyRequestsError( |
| 972 |
headers=dict(_response.headers), |
| 973 |
body=typing.cast( |
| 974 |
typing.Any, |
| 975 |
parse_obj_as( |
| 976 |
type_=typing.Any, |
| 977 |
object_=_response.json(), |
| 978 |
), |
| 979 |
), |
| 980 |
) |
| 981 |
_response_json = _response.json() |
| 982 |
except JSONDecodeError: |
| 983 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 984 |
except ValidationError as e: |
| 985 |
raise ParsingError( |
| 986 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 987 |
) |
| 988 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 989 |
|
| 990 |
async def update( |
| 991 |
self, |
| 992 |
id: str, |
| 993 |
*, |
| 994 |
name: typing.Optional[str] = OMIT, |
| 995 |
actions: typing.Optional[typing.Sequence[FlowAction]] = OMIT, |
| 996 |
request_options: typing.Optional[RequestOptions] = None, |
| 997 |
) -> AsyncHttpResponse[UpdateFlowResponseContent]: |
| 998 |
""" |
| 999 |
Parameters |
| 1000 |
---------- |
| 1001 |
id : str |
| 1002 |
Flow identifier |
| 1003 |
|
| 1004 |
name : typing.Optional[str] |
| 1005 |
|
| 1006 |
actions : typing.Optional[typing.Sequence[FlowAction]] |
| 1007 |
|
| 1008 |
request_options : typing.Optional[RequestOptions] |
| 1009 |
Request-specific configuration. |
| 1010 |
|
| 1011 |
Returns |
| 1012 |
------- |
| 1013 |
AsyncHttpResponse[UpdateFlowResponseContent] |
| 1014 |
Flow successfully updated. |
| 1015 |
""" |
| 1016 |
_response = await self._client_wrapper.httpx_client.request( |
| 1017 |
f"flows/{encode_path_param(id)}", |
| 1018 |
method="PATCH", |
| 1019 |
json={ |
| 1020 |
"name": name, |
| 1021 |
"actions": convert_and_respect_annotation_metadata( |
| 1022 |
object_=actions, annotation=typing.Optional[typing.Sequence[FlowAction]], direction="write" |
| 1023 |
), |
| 1024 |
}, |
| 1025 |
headers={ |
| 1026 |
"content-type": "application/json", |
| 1027 |
}, |
| 1028 |
request_options=request_options, |
| 1029 |
omit=OMIT, |
| 1030 |
) |
| 1031 |
try: |
| 1032 |
if 200 <= _response.status_code < 300: |
| 1033 |
_data = typing.cast( |
| 1034 |
UpdateFlowResponseContent, |
| 1035 |
parse_obj_as( |
| 1036 |
type_=UpdateFlowResponseContent, |
| 1037 |
object_=_response.json(), |
| 1038 |
), |
| 1039 |
) |
| 1040 |
return AsyncHttpResponse(response=_response, data=_data) |
| 1041 |
if _response.status_code == 401: |
| 1042 |
raise UnauthorizedError( |
| 1043 |
headers=dict(_response.headers), |
| 1044 |
body=typing.cast( |
| 1045 |
typing.Any, |
| 1046 |
parse_obj_as( |
| 1047 |
type_=typing.Any, |
| 1048 |
object_=_response.json(), |
| 1049 |
), |
| 1050 |
), |
| 1051 |
) |
| 1052 |
if _response.status_code == 403: |
| 1053 |
raise ForbiddenError( |
| 1054 |
headers=dict(_response.headers), |
| 1055 |
body=typing.cast( |
| 1056 |
typing.Any, |
| 1057 |
parse_obj_as( |
| 1058 |
type_=typing.Any, |
| 1059 |
object_=_response.json(), |
| 1060 |
), |
| 1061 |
), |
| 1062 |
) |
| 1063 |
if _response.status_code == 404: |
| 1064 |
raise NotFoundError( |
| 1065 |
headers=dict(_response.headers), |
| 1066 |
body=typing.cast( |
| 1067 |
typing.Any, |
| 1068 |
parse_obj_as( |
| 1069 |
type_=typing.Any, |
| 1070 |
object_=_response.json(), |
| 1071 |
), |
| 1072 |
), |
| 1073 |
) |
| 1074 |
if _response.status_code == 429: |
| 1075 |
raise TooManyRequestsError( |
| 1076 |
headers=dict(_response.headers), |
| 1077 |
body=typing.cast( |
| 1078 |
typing.Any, |
| 1079 |
parse_obj_as( |
| 1080 |
type_=typing.Any, |
| 1081 |
object_=_response.json(), |
| 1082 |
), |
| 1083 |
), |
| 1084 |
) |
| 1085 |
_response_json = _response.json() |
| 1086 |
except JSONDecodeError: |
| 1087 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1088 |
except ValidationError as e: |
| 1089 |
raise ParsingError( |
| 1090 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1091 |
) |
| 1092 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |