| 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.parse_error import ParsingError |
| 11 |
from ...core.pydantic_utilities import parse_obj_as |
| 12 |
from ...core.request_options import RequestOptions |
| 13 |
from ...errors.bad_request_error import BadRequestError |
| 14 |
from ...errors.forbidden_error import ForbiddenError |
| 15 |
from ...errors.not_found_error import NotFoundError |
| 16 |
from ...errors.too_many_requests_error import TooManyRequestsError |
| 17 |
from ...errors.unauthorized_error import UnauthorizedError |
| 18 |
from ...types.event_stream_delivery import EventStreamDelivery |
| 19 |
from ...types.get_event_stream_delivery_history_response_content import GetEventStreamDeliveryHistoryResponseContent |
| 20 |
from pydantic import ValidationError |
| 21 |
|
| 22 |
|
| 23 |
class RawDeliveriesClient: |
| 24 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 25 |
self._client_wrapper = client_wrapper |
| 26 |
|
| 27 |
def list( |
| 28 |
self, |
| 29 |
id: str, |
| 30 |
*, |
| 31 |
statuses: typing.Optional[str] = None, |
| 32 |
event_types: typing.Optional[str] = None, |
| 33 |
date_from: typing.Optional[str] = None, |
| 34 |
date_to: typing.Optional[str] = None, |
| 35 |
from_: typing.Optional[str] = None, |
| 36 |
take: typing.Optional[int] = 50, |
| 37 |
request_options: typing.Optional[RequestOptions] = None, |
| 38 |
) -> HttpResponse[typing.List[EventStreamDelivery]]: |
| 39 |
""" |
| 40 |
Parameters |
| 41 |
---------- |
| 42 |
id : str |
| 43 |
Unique identifier for the event stream. |
| 44 |
|
| 45 |
statuses : typing.Optional[str] |
| 46 |
Comma-separated list of statuses by which to filter |
| 47 |
|
| 48 |
event_types : typing.Optional[str] |
| 49 |
Comma-separated list of event types by which to filter |
| 50 |
|
| 51 |
date_from : typing.Optional[str] |
| 52 |
An RFC-3339 date-time for redelivery start, inclusive. Does not allow sub-second precision. |
| 53 |
|
| 54 |
date_to : typing.Optional[str] |
| 55 |
An RFC-3339 date-time for redelivery end, exclusive. Does not allow sub-second precision. |
| 56 |
|
| 57 |
from_ : typing.Optional[str] |
| 58 |
Optional Id from which to start selection. |
| 59 |
|
| 60 |
take : typing.Optional[int] |
| 61 |
Number of results per page. Defaults to 50. |
| 62 |
|
| 63 |
request_options : typing.Optional[RequestOptions] |
| 64 |
Request-specific configuration. |
| 65 |
|
| 66 |
Returns |
| 67 |
------- |
| 68 |
HttpResponse[typing.List[EventStreamDelivery]] |
| 69 |
Event stream deliveries successfully retrieved. |
| 70 |
""" |
| 71 |
_response = self._client_wrapper.httpx_client.request( |
| 72 |
f"event-streams/{encode_path_param(id)}/deliveries", |
| 73 |
method="GET", |
| 74 |
params={ |
| 75 |
"statuses": statuses, |
| 76 |
"event_types": event_types, |
| 77 |
"date_from": date_from, |
| 78 |
"date_to": date_to, |
| 79 |
"from": from_, |
| 80 |
"take": take, |
| 81 |
}, |
| 82 |
request_options=request_options, |
| 83 |
) |
| 84 |
try: |
| 85 |
if 200 <= _response.status_code < 300: |
| 86 |
_data = typing.cast( |
| 87 |
typing.List[EventStreamDelivery], |
| 88 |
parse_obj_as( |
| 89 |
type_=typing.List[EventStreamDelivery], |
| 90 |
object_=_response.json(), |
| 91 |
), |
| 92 |
) |
| 93 |
return HttpResponse(response=_response, data=_data) |
| 94 |
if _response.status_code == 400: |
| 95 |
raise BadRequestError( |
| 96 |
headers=dict(_response.headers), |
| 97 |
body=typing.cast( |
| 98 |
typing.Any, |
| 99 |
parse_obj_as( |
| 100 |
type_=typing.Any, |
| 101 |
object_=_response.json(), |
| 102 |
), |
| 103 |
), |
| 104 |
) |
| 105 |
if _response.status_code == 401: |
| 106 |
raise UnauthorizedError( |
| 107 |
headers=dict(_response.headers), |
| 108 |
body=typing.cast( |
| 109 |
typing.Any, |
| 110 |
parse_obj_as( |
| 111 |
type_=typing.Any, |
| 112 |
object_=_response.json(), |
| 113 |
), |
| 114 |
), |
| 115 |
) |
| 116 |
if _response.status_code == 403: |
| 117 |
raise ForbiddenError( |
| 118 |
headers=dict(_response.headers), |
| 119 |
body=typing.cast( |
| 120 |
typing.Any, |
| 121 |
parse_obj_as( |
| 122 |
type_=typing.Any, |
| 123 |
object_=_response.json(), |
| 124 |
), |
| 125 |
), |
| 126 |
) |
| 127 |
if _response.status_code == 404: |
| 128 |
raise NotFoundError( |
| 129 |
headers=dict(_response.headers), |
| 130 |
body=typing.cast( |
| 131 |
typing.Any, |
| 132 |
parse_obj_as( |
| 133 |
type_=typing.Any, |
| 134 |
object_=_response.json(), |
| 135 |
), |
| 136 |
), |
| 137 |
) |
| 138 |
if _response.status_code == 429: |
| 139 |
raise TooManyRequestsError( |
| 140 |
headers=dict(_response.headers), |
| 141 |
body=typing.cast( |
| 142 |
typing.Any, |
| 143 |
parse_obj_as( |
| 144 |
type_=typing.Any, |
| 145 |
object_=_response.json(), |
| 146 |
), |
| 147 |
), |
| 148 |
) |
| 149 |
_response_json = _response.json() |
| 150 |
except JSONDecodeError: |
| 151 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 152 |
except ValidationError as e: |
| 153 |
raise ParsingError( |
| 154 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 155 |
) |
| 156 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 157 |
|
| 158 |
def get_history( |
| 159 |
self, id: str, event_id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 160 |
) -> HttpResponse[GetEventStreamDeliveryHistoryResponseContent]: |
| 161 |
""" |
| 162 |
Parameters |
| 163 |
---------- |
| 164 |
id : str |
| 165 |
Unique identifier for the event stream. |
| 166 |
|
| 167 |
event_id : str |
| 168 |
Unique identifier for the event |
| 169 |
|
| 170 |
request_options : typing.Optional[RequestOptions] |
| 171 |
Request-specific configuration. |
| 172 |
|
| 173 |
Returns |
| 174 |
------- |
| 175 |
HttpResponse[GetEventStreamDeliveryHistoryResponseContent] |
| 176 |
Delivery history for event successfully retrieved. |
| 177 |
""" |
| 178 |
_response = self._client_wrapper.httpx_client.request( |
| 179 |
f"event-streams/{encode_path_param(id)}/deliveries/{encode_path_param(event_id)}", |
| 180 |
method="GET", |
| 181 |
request_options=request_options, |
| 182 |
) |
| 183 |
try: |
| 184 |
if 200 <= _response.status_code < 300: |
| 185 |
_data = typing.cast( |
| 186 |
GetEventStreamDeliveryHistoryResponseContent, |
| 187 |
parse_obj_as( |
| 188 |
type_=GetEventStreamDeliveryHistoryResponseContent, |
| 189 |
object_=_response.json(), |
| 190 |
), |
| 191 |
) |
| 192 |
return HttpResponse(response=_response, data=_data) |
| 193 |
if _response.status_code == 401: |
| 194 |
raise UnauthorizedError( |
| 195 |
headers=dict(_response.headers), |
| 196 |
body=typing.cast( |
| 197 |
typing.Any, |
| 198 |
parse_obj_as( |
| 199 |
type_=typing.Any, |
| 200 |
object_=_response.json(), |
| 201 |
), |
| 202 |
), |
| 203 |
) |
| 204 |
if _response.status_code == 403: |
| 205 |
raise ForbiddenError( |
| 206 |
headers=dict(_response.headers), |
| 207 |
body=typing.cast( |
| 208 |
typing.Any, |
| 209 |
parse_obj_as( |
| 210 |
type_=typing.Any, |
| 211 |
object_=_response.json(), |
| 212 |
), |
| 213 |
), |
| 214 |
) |
| 215 |
if _response.status_code == 404: |
| 216 |
raise NotFoundError( |
| 217 |
headers=dict(_response.headers), |
| 218 |
body=typing.cast( |
| 219 |
typing.Any, |
| 220 |
parse_obj_as( |
| 221 |
type_=typing.Any, |
| 222 |
object_=_response.json(), |
| 223 |
), |
| 224 |
), |
| 225 |
) |
| 226 |
if _response.status_code == 429: |
| 227 |
raise TooManyRequestsError( |
| 228 |
headers=dict(_response.headers), |
| 229 |
body=typing.cast( |
| 230 |
typing.Any, |
| 231 |
parse_obj_as( |
| 232 |
type_=typing.Any, |
| 233 |
object_=_response.json(), |
| 234 |
), |
| 235 |
), |
| 236 |
) |
| 237 |
_response_json = _response.json() |
| 238 |
except JSONDecodeError: |
| 239 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 240 |
except ValidationError as e: |
| 241 |
raise ParsingError( |
| 242 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 243 |
) |
| 244 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 245 |
|
| 246 |
|
| 247 |
class AsyncRawDeliveriesClient: |
| 248 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 249 |
self._client_wrapper = client_wrapper |
| 250 |
|
| 251 |
async def list( |
| 252 |
self, |
| 253 |
id: str, |
| 254 |
*, |
| 255 |
statuses: typing.Optional[str] = None, |
| 256 |
event_types: typing.Optional[str] = None, |
| 257 |
date_from: typing.Optional[str] = None, |
| 258 |
date_to: typing.Optional[str] = None, |
| 259 |
from_: typing.Optional[str] = None, |
| 260 |
take: typing.Optional[int] = 50, |
| 261 |
request_options: typing.Optional[RequestOptions] = None, |
| 262 |
) -> AsyncHttpResponse[typing.List[EventStreamDelivery]]: |
| 263 |
""" |
| 264 |
Parameters |
| 265 |
---------- |
| 266 |
id : str |
| 267 |
Unique identifier for the event stream. |
| 268 |
|
| 269 |
statuses : typing.Optional[str] |
| 270 |
Comma-separated list of statuses by which to filter |
| 271 |
|
| 272 |
event_types : typing.Optional[str] |
| 273 |
Comma-separated list of event types by which to filter |
| 274 |
|
| 275 |
date_from : typing.Optional[str] |
| 276 |
An RFC-3339 date-time for redelivery start, inclusive. Does not allow sub-second precision. |
| 277 |
|
| 278 |
date_to : typing.Optional[str] |
| 279 |
An RFC-3339 date-time for redelivery end, exclusive. Does not allow sub-second precision. |
| 280 |
|
| 281 |
from_ : typing.Optional[str] |
| 282 |
Optional Id from which to start selection. |
| 283 |
|
| 284 |
take : typing.Optional[int] |
| 285 |
Number of results per page. Defaults to 50. |
| 286 |
|
| 287 |
request_options : typing.Optional[RequestOptions] |
| 288 |
Request-specific configuration. |
| 289 |
|
| 290 |
Returns |
| 291 |
------- |
| 292 |
AsyncHttpResponse[typing.List[EventStreamDelivery]] |
| 293 |
Event stream deliveries successfully retrieved. |
| 294 |
""" |
| 295 |
_response = await self._client_wrapper.httpx_client.request( |
| 296 |
f"event-streams/{encode_path_param(id)}/deliveries", |
| 297 |
method="GET", |
| 298 |
params={ |
| 299 |
"statuses": statuses, |
| 300 |
"event_types": event_types, |
| 301 |
"date_from": date_from, |
| 302 |
"date_to": date_to, |
| 303 |
"from": from_, |
| 304 |
"take": take, |
| 305 |
}, |
| 306 |
request_options=request_options, |
| 307 |
) |
| 308 |
try: |
| 309 |
if 200 <= _response.status_code < 300: |
| 310 |
_data = typing.cast( |
| 311 |
typing.List[EventStreamDelivery], |
| 312 |
parse_obj_as( |
| 313 |
type_=typing.List[EventStreamDelivery], |
| 314 |
object_=_response.json(), |
| 315 |
), |
| 316 |
) |
| 317 |
return AsyncHttpResponse(response=_response, data=_data) |
| 318 |
if _response.status_code == 400: |
| 319 |
raise BadRequestError( |
| 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 == 401: |
| 330 |
raise UnauthorizedError( |
| 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 == 403: |
| 341 |
raise ForbiddenError( |
| 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 == 404: |
| 352 |
raise NotFoundError( |
| 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 |
if _response.status_code == 429: |
| 363 |
raise TooManyRequestsError( |
| 364 |
headers=dict(_response.headers), |
| 365 |
body=typing.cast( |
| 366 |
typing.Any, |
| 367 |
parse_obj_as( |
| 368 |
type_=typing.Any, |
| 369 |
object_=_response.json(), |
| 370 |
), |
| 371 |
), |
| 372 |
) |
| 373 |
_response_json = _response.json() |
| 374 |
except JSONDecodeError: |
| 375 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 376 |
except ValidationError as e: |
| 377 |
raise ParsingError( |
| 378 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 379 |
) |
| 380 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 381 |
|
| 382 |
async def get_history( |
| 383 |
self, id: str, event_id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 384 |
) -> AsyncHttpResponse[GetEventStreamDeliveryHistoryResponseContent]: |
| 385 |
""" |
| 386 |
Parameters |
| 387 |
---------- |
| 388 |
id : str |
| 389 |
Unique identifier for the event stream. |
| 390 |
|
| 391 |
event_id : str |
| 392 |
Unique identifier for the event |
| 393 |
|
| 394 |
request_options : typing.Optional[RequestOptions] |
| 395 |
Request-specific configuration. |
| 396 |
|
| 397 |
Returns |
| 398 |
------- |
| 399 |
AsyncHttpResponse[GetEventStreamDeliveryHistoryResponseContent] |
| 400 |
Delivery history for event successfully retrieved. |
| 401 |
""" |
| 402 |
_response = await self._client_wrapper.httpx_client.request( |
| 403 |
f"event-streams/{encode_path_param(id)}/deliveries/{encode_path_param(event_id)}", |
| 404 |
method="GET", |
| 405 |
request_options=request_options, |
| 406 |
) |
| 407 |
try: |
| 408 |
if 200 <= _response.status_code < 300: |
| 409 |
_data = typing.cast( |
| 410 |
GetEventStreamDeliveryHistoryResponseContent, |
| 411 |
parse_obj_as( |
| 412 |
type_=GetEventStreamDeliveryHistoryResponseContent, |
| 413 |
object_=_response.json(), |
| 414 |
), |
| 415 |
) |
| 416 |
return AsyncHttpResponse(response=_response, data=_data) |
| 417 |
if _response.status_code == 401: |
| 418 |
raise UnauthorizedError( |
| 419 |
headers=dict(_response.headers), |
| 420 |
body=typing.cast( |
| 421 |
typing.Any, |
| 422 |
parse_obj_as( |
| 423 |
type_=typing.Any, |
| 424 |
object_=_response.json(), |
| 425 |
), |
| 426 |
), |
| 427 |
) |
| 428 |
if _response.status_code == 403: |
| 429 |
raise ForbiddenError( |
| 430 |
headers=dict(_response.headers), |
| 431 |
body=typing.cast( |
| 432 |
typing.Any, |
| 433 |
parse_obj_as( |
| 434 |
type_=typing.Any, |
| 435 |
object_=_response.json(), |
| 436 |
), |
| 437 |
), |
| 438 |
) |
| 439 |
if _response.status_code == 404: |
| 440 |
raise NotFoundError( |
| 441 |
headers=dict(_response.headers), |
| 442 |
body=typing.cast( |
| 443 |
typing.Any, |
| 444 |
parse_obj_as( |
| 445 |
type_=typing.Any, |
| 446 |
object_=_response.json(), |
| 447 |
), |
| 448 |
), |
| 449 |
) |
| 450 |
if _response.status_code == 429: |
| 451 |
raise TooManyRequestsError( |
| 452 |
headers=dict(_response.headers), |
| 453 |
body=typing.cast( |
| 454 |
typing.Any, |
| 455 |
parse_obj_as( |
| 456 |
type_=typing.Any, |
| 457 |
object_=_response.json(), |
| 458 |
), |
| 459 |
), |
| 460 |
) |
| 461 |
_response_json = _response.json() |
| 462 |
except JSONDecodeError: |
| 463 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 464 |
except ValidationError as e: |
| 465 |
raise ParsingError( |
| 466 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 467 |
) |
| 468 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |