Debian Codegraph @

src/auth0/management/event_streams/raw_client.py

raw symbols SCIP
1 # This file was auto-generated by Fern from our API Definition.
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.conflict_error import ConflictError
17 from ..errors.forbidden_error import ForbiddenError
18 from ..errors.not_found_error import NotFoundError
19 from ..errors.too_many_requests_error import TooManyRequestsError
20 from ..errors.unauthorized_error import UnauthorizedError
21 from ..types.create_event_stream_response_content import CreateEventStreamResponseContent
22 from ..types.create_event_stream_test_event_response_content import CreateEventStreamTestEventResponseContent
23 from ..types.event_stream_destination_patch import EventStreamDestinationPatch
24 from ..types.event_stream_response_content import EventStreamResponseContent
25 from ..types.event_stream_status_enum import EventStreamStatusEnum
26 from ..types.event_stream_subscription import EventStreamSubscription
27 from ..types.event_stream_test_event_type_enum import EventStreamTestEventTypeEnum
28 from ..types.get_event_stream_response_content import GetEventStreamResponseContent
29 from ..types.list_event_streams_response_content import ListEventStreamsResponseContent
30 from ..types.test_event_data_content import TestEventDataContent
31 from ..types.update_event_stream_response_content import UpdateEventStreamResponseContent
32 from .types.event_streams_create_request import EventStreamsCreateRequest
33 from pydantic import ValidationError
34
35 # this is used as the default value for optional parameters
36 OMIT = typing.cast(typing.Any, ...)
37
38
39 class RawEventStreamsClient:
40 def __init__(self, *, client_wrapper: SyncClientWrapper):
41 self._client_wrapper = client_wrapper
42
43 def list(
44 self,
45 *,
46 from_: typing.Optional[str] = None,
47 take: typing.Optional[int] = 50,
48 request_options: typing.Optional[RequestOptions] = None,
49 ) -> SyncPager[EventStreamResponseContent, ListEventStreamsResponseContent]:
50 """
51 Parameters
52 ----------
53 from_ : typing.Optional[str]
54 Optional Id from which to start selection.
55
56 take : typing.Optional[int]
57 Number of results per page. Defaults to 50.
58
59 request_options : typing.Optional[RequestOptions]
60 Request-specific configuration.
61
62 Returns
63 -------
64 SyncPager[EventStreamResponseContent, ListEventStreamsResponseContent]
65 Event streams successfully retrieved.
66 """
67 _response = self._client_wrapper.httpx_client.request(
68 "event-streams",
69 method="GET",
70 params={
71 "from": from_,
72 "take": take,
73 },
74 request_options=request_options,
75 )
76 try:
77 if 200 <= _response.status_code < 300:
78 _parsed_response = typing.cast(
79 ListEventStreamsResponseContent,
80 parse_obj_as(
81 type_=ListEventStreamsResponseContent, # type: ignore
82 object_=_response.json(),
83 ),
84 )
85 _items = _parsed_response.event_streams
86 _parsed_next = _parsed_response.next
87 _has_next = _parsed_next is not None and _parsed_next != ""
88 _get_next = lambda: self.list(
89 from_=_parsed_next,
90 take=take,
91 request_options=request_options,
92 )
93 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
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, # type: ignore
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, # type: ignore
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, # type: ignore
123 object_=_response.json(),
124 ),
125 ),
126 )
127 if _response.status_code == 429:
128 raise TooManyRequestsError(
129 headers=dict(_response.headers),
130 body=typing.cast(
131 typing.Any,
132 parse_obj_as(
133 type_=typing.Any, # type: ignore
134 object_=_response.json(),
135 ),
136 ),
137 )
138 _response_json = _response.json()
139 except JSONDecodeError:
140 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
141 except ValidationError as e:
142 raise ParsingError(
143 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
144 )
145 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
146
147 def create(
148 self, *, request: EventStreamsCreateRequest, request_options: typing.Optional[RequestOptions] = None
149 ) -> HttpResponse[CreateEventStreamResponseContent]:
150 """
151 Parameters
152 ----------
153 request : EventStreamsCreateRequest
154
155 request_options : typing.Optional[RequestOptions]
156 Request-specific configuration.
157
158 Returns
159 -------
160 HttpResponse[CreateEventStreamResponseContent]
161 Event Stream stream created successfully.
162 """
163 _response = self._client_wrapper.httpx_client.request(
164 "event-streams",
165 method="POST",
166 json=convert_and_respect_annotation_metadata(
167 object_=request, annotation=EventStreamsCreateRequest, direction="write"
168 ),
169 request_options=request_options,
170 omit=OMIT,
171 )
172 try:
173 if 200 <= _response.status_code < 300:
174 _data = typing.cast(
175 CreateEventStreamResponseContent,
176 parse_obj_as(
177 type_=CreateEventStreamResponseContent, # type: ignore
178 object_=_response.json(),
179 ),
180 )
181 return HttpResponse(response=_response, data=_data)
182 if _response.status_code == 400:
183 raise BadRequestError(
184 headers=dict(_response.headers),
185 body=typing.cast(
186 typing.Any,
187 parse_obj_as(
188 type_=typing.Any, # type: ignore
189 object_=_response.json(),
190 ),
191 ),
192 )
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, # type: ignore
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, # type: ignore
211 object_=_response.json(),
212 ),
213 ),
214 )
215 if _response.status_code == 409:
216 raise ConflictError(
217 headers=dict(_response.headers),
218 body=typing.cast(
219 typing.Any,
220 parse_obj_as(
221 type_=typing.Any, # type: ignore
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, # type: ignore
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 def get(
247 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
248 ) -> HttpResponse[GetEventStreamResponseContent]:
249 """
250 Parameters
251 ----------
252 id : str
253 Unique identifier for the event stream.
254
255 request_options : typing.Optional[RequestOptions]
256 Request-specific configuration.
257
258 Returns
259 -------
260 HttpResponse[GetEventStreamResponseContent]
261 Event stream successfully retrieved.
262 """
263 _response = self._client_wrapper.httpx_client.request(
264 f"event-streams/{encode_path_param(id)}",
265 method="GET",
266 request_options=request_options,
267 )
268 try:
269 if 200 <= _response.status_code < 300:
270 _data = typing.cast(
271 GetEventStreamResponseContent,
272 parse_obj_as(
273 type_=GetEventStreamResponseContent, # type: ignore
274 object_=_response.json(),
275 ),
276 )
277 return HttpResponse(response=_response, data=_data)
278 if _response.status_code == 401:
279 raise UnauthorizedError(
280 headers=dict(_response.headers),
281 body=typing.cast(
282 typing.Any,
283 parse_obj_as(
284 type_=typing.Any, # type: ignore
285 object_=_response.json(),
286 ),
287 ),
288 )
289 if _response.status_code == 403:
290 raise ForbiddenError(
291 headers=dict(_response.headers),
292 body=typing.cast(
293 typing.Any,
294 parse_obj_as(
295 type_=typing.Any, # type: ignore
296 object_=_response.json(),
297 ),
298 ),
299 )
300 if _response.status_code == 404:
301 raise NotFoundError(
302 headers=dict(_response.headers),
303 body=typing.cast(
304 typing.Any,
305 parse_obj_as(
306 type_=typing.Any, # type: ignore
307 object_=_response.json(),
308 ),
309 ),
310 )
311 if _response.status_code == 429:
312 raise TooManyRequestsError(
313 headers=dict(_response.headers),
314 body=typing.cast(
315 typing.Any,
316 parse_obj_as(
317 type_=typing.Any, # type: ignore
318 object_=_response.json(),
319 ),
320 ),
321 )
322 _response_json = _response.json()
323 except JSONDecodeError:
324 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
325 except ValidationError as e:
326 raise ParsingError(
327 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
328 )
329 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
330
331 def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
332 """
333 Parameters
334 ----------
335 id : str
336 Unique identifier for the event stream.
337
338 request_options : typing.Optional[RequestOptions]
339 Request-specific configuration.
340
341 Returns
342 -------
343 HttpResponse[None]
344 """
345 _response = self._client_wrapper.httpx_client.request(
346 f"event-streams/{encode_path_param(id)}",
347 method="DELETE",
348 request_options=request_options,
349 )
350 try:
351 if 200 <= _response.status_code < 300:
352 return HttpResponse(response=_response, data=None)
353 if _response.status_code == 400:
354 raise BadRequestError(
355 headers=dict(_response.headers),
356 body=typing.cast(
357 typing.Any,
358 parse_obj_as(
359 type_=typing.Any, # type: ignore
360 object_=_response.json(),
361 ),
362 ),
363 )
364 if _response.status_code == 401:
365 raise UnauthorizedError(
366 headers=dict(_response.headers),
367 body=typing.cast(
368 typing.Any,
369 parse_obj_as(
370 type_=typing.Any, # type: ignore
371 object_=_response.json(),
372 ),
373 ),
374 )
375 if _response.status_code == 403:
376 raise ForbiddenError(
377 headers=dict(_response.headers),
378 body=typing.cast(
379 typing.Any,
380 parse_obj_as(
381 type_=typing.Any, # type: ignore
382 object_=_response.json(),
383 ),
384 ),
385 )
386 if _response.status_code == 429:
387 raise TooManyRequestsError(
388 headers=dict(_response.headers),
389 body=typing.cast(
390 typing.Any,
391 parse_obj_as(
392 type_=typing.Any, # type: ignore
393 object_=_response.json(),
394 ),
395 ),
396 )
397 _response_json = _response.json()
398 except JSONDecodeError:
399 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
400 except ValidationError as e:
401 raise ParsingError(
402 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
403 )
404 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
405
406 def update(
407 self,
408 id: str,
409 *,
410 name: typing.Optional[str] = OMIT,
411 subscriptions: typing.Optional[typing.Sequence[EventStreamSubscription]] = OMIT,
412 destination: typing.Optional[EventStreamDestinationPatch] = OMIT,
413 status: typing.Optional[EventStreamStatusEnum] = OMIT,
414 request_options: typing.Optional[RequestOptions] = None,
415 ) -> HttpResponse[UpdateEventStreamResponseContent]:
416 """
417 Parameters
418 ----------
419 id : str
420 Unique identifier for the event stream.
421
422 name : typing.Optional[str]
423 Name of the event stream.
424
425 subscriptions : typing.Optional[typing.Sequence[EventStreamSubscription]]
426 List of event types subscribed to in this stream.
427
428 destination : typing.Optional[EventStreamDestinationPatch]
429
430 status : typing.Optional[EventStreamStatusEnum]
431
432 request_options : typing.Optional[RequestOptions]
433 Request-specific configuration.
434
435 Returns
436 -------
437 HttpResponse[UpdateEventStreamResponseContent]
438 Event stream successfully updated.
439 """
440 _response = self._client_wrapper.httpx_client.request(
441 f"event-streams/{encode_path_param(id)}",
442 method="PATCH",
443 json={
444 "name": name,
445 "subscriptions": convert_and_respect_annotation_metadata(
446 object_=subscriptions, annotation=typing.Sequence[EventStreamSubscription], direction="write"
447 ),
448 "destination": convert_and_respect_annotation_metadata(
449 object_=destination, annotation=EventStreamDestinationPatch, direction="write"
450 ),
451 "status": status,
452 },
453 headers={
454 "content-type": "application/json",
455 },
456 request_options=request_options,
457 omit=OMIT,
458 )
459 try:
460 if 200 <= _response.status_code < 300:
461 _data = typing.cast(
462 UpdateEventStreamResponseContent,
463 parse_obj_as(
464 type_=UpdateEventStreamResponseContent, # type: ignore
465 object_=_response.json(),
466 ),
467 )
468 return HttpResponse(response=_response, data=_data)
469 if _response.status_code == 400:
470 raise BadRequestError(
471 headers=dict(_response.headers),
472 body=typing.cast(
473 typing.Any,
474 parse_obj_as(
475 type_=typing.Any, # type: ignore
476 object_=_response.json(),
477 ),
478 ),
479 )
480 if _response.status_code == 401:
481 raise UnauthorizedError(
482 headers=dict(_response.headers),
483 body=typing.cast(
484 typing.Any,
485 parse_obj_as(
486 type_=typing.Any, # type: ignore
487 object_=_response.json(),
488 ),
489 ),
490 )
491 if _response.status_code == 403:
492 raise ForbiddenError(
493 headers=dict(_response.headers),
494 body=typing.cast(
495 typing.Any,
496 parse_obj_as(
497 type_=typing.Any, # type: ignore
498 object_=_response.json(),
499 ),
500 ),
501 )
502 if _response.status_code == 429:
503 raise TooManyRequestsError(
504 headers=dict(_response.headers),
505 body=typing.cast(
506 typing.Any,
507 parse_obj_as(
508 type_=typing.Any, # type: ignore
509 object_=_response.json(),
510 ),
511 ),
512 )
513 _response_json = _response.json()
514 except JSONDecodeError:
515 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
516 except ValidationError as e:
517 raise ParsingError(
518 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
519 )
520 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
521
522 def test(
523 self,
524 id: str,
525 *,
526 event_type: EventStreamTestEventTypeEnum,
527 data: typing.Optional[TestEventDataContent] = OMIT,
528 request_options: typing.Optional[RequestOptions] = None,
529 ) -> HttpResponse[CreateEventStreamTestEventResponseContent]:
530 """
531 Parameters
532 ----------
533 id : str
534 Unique identifier for the event stream.
535
536 event_type : EventStreamTestEventTypeEnum
537
538 data : typing.Optional[TestEventDataContent]
539
540 request_options : typing.Optional[RequestOptions]
541 Request-specific configuration.
542
543 Returns
544 -------
545 HttpResponse[CreateEventStreamTestEventResponseContent]
546 Test event successfully submitted.
547 """
548 _response = self._client_wrapper.httpx_client.request(
549 f"event-streams/{encode_path_param(id)}/test",
550 method="POST",
551 json={
552 "event_type": event_type,
553 "data": data,
554 },
555 headers={
556 "content-type": "application/json",
557 },
558 request_options=request_options,
559 omit=OMIT,
560 )
561 try:
562 if 200 <= _response.status_code < 300:
563 _data = typing.cast(
564 CreateEventStreamTestEventResponseContent,
565 parse_obj_as(
566 type_=CreateEventStreamTestEventResponseContent, # type: ignore
567 object_=_response.json(),
568 ),
569 )
570 return HttpResponse(response=_response, data=_data)
571 if _response.status_code == 401:
572 raise UnauthorizedError(
573 headers=dict(_response.headers),
574 body=typing.cast(
575 typing.Any,
576 parse_obj_as(
577 type_=typing.Any, # type: ignore
578 object_=_response.json(),
579 ),
580 ),
581 )
582 if _response.status_code == 403:
583 raise ForbiddenError(
584 headers=dict(_response.headers),
585 body=typing.cast(
586 typing.Any,
587 parse_obj_as(
588 type_=typing.Any, # type: ignore
589 object_=_response.json(),
590 ),
591 ),
592 )
593 if _response.status_code == 429:
594 raise TooManyRequestsError(
595 headers=dict(_response.headers),
596 body=typing.cast(
597 typing.Any,
598 parse_obj_as(
599 type_=typing.Any, # type: ignore
600 object_=_response.json(),
601 ),
602 ),
603 )
604 _response_json = _response.json()
605 except JSONDecodeError:
606 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
607 except ValidationError as e:
608 raise ParsingError(
609 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
610 )
611 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
612
613
614 class AsyncRawEventStreamsClient:
615 def __init__(self, *, client_wrapper: AsyncClientWrapper):
616 self._client_wrapper = client_wrapper
617
618 async def list(
619 self,
620 *,
621 from_: typing.Optional[str] = None,
622 take: typing.Optional[int] = 50,
623 request_options: typing.Optional[RequestOptions] = None,
624 ) -> AsyncPager[EventStreamResponseContent, ListEventStreamsResponseContent]:
625 """
626 Parameters
627 ----------
628 from_ : typing.Optional[str]
629 Optional Id from which to start selection.
630
631 take : typing.Optional[int]
632 Number of results per page. Defaults to 50.
633
634 request_options : typing.Optional[RequestOptions]
635 Request-specific configuration.
636
637 Returns
638 -------
639 AsyncPager[EventStreamResponseContent, ListEventStreamsResponseContent]
640 Event streams successfully retrieved.
641 """
642 _response = await self._client_wrapper.httpx_client.request(
643 "event-streams",
644 method="GET",
645 params={
646 "from": from_,
647 "take": take,
648 },
649 request_options=request_options,
650 )
651 try:
652 if 200 <= _response.status_code < 300:
653 _parsed_response = typing.cast(
654 ListEventStreamsResponseContent,
655 parse_obj_as(
656 type_=ListEventStreamsResponseContent, # type: ignore
657 object_=_response.json(),
658 ),
659 )
660 _items = _parsed_response.event_streams
661 _parsed_next = _parsed_response.next
662 _has_next = _parsed_next is not None and _parsed_next != ""
663
664 async def _get_next():
665 return await self.list(
666 from_=_parsed_next,
667 take=take,
668 request_options=request_options,
669 )
670
671 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
672 if _response.status_code == 400:
673 raise BadRequestError(
674 headers=dict(_response.headers),
675 body=typing.cast(
676 typing.Any,
677 parse_obj_as(
678 type_=typing.Any, # type: ignore
679 object_=_response.json(),
680 ),
681 ),
682 )
683 if _response.status_code == 401:
684 raise UnauthorizedError(
685 headers=dict(_response.headers),
686 body=typing.cast(
687 typing.Any,
688 parse_obj_as(
689 type_=typing.Any, # type: ignore
690 object_=_response.json(),
691 ),
692 ),
693 )
694 if _response.status_code == 403:
695 raise ForbiddenError(
696 headers=dict(_response.headers),
697 body=typing.cast(
698 typing.Any,
699 parse_obj_as(
700 type_=typing.Any, # type: ignore
701 object_=_response.json(),
702 ),
703 ),
704 )
705 if _response.status_code == 429:
706 raise TooManyRequestsError(
707 headers=dict(_response.headers),
708 body=typing.cast(
709 typing.Any,
710 parse_obj_as(
711 type_=typing.Any, # type: ignore
712 object_=_response.json(),
713 ),
714 ),
715 )
716 _response_json = _response.json()
717 except JSONDecodeError:
718 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
719 except ValidationError as e:
720 raise ParsingError(
721 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
722 )
723 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
724
725 async def create(
726 self, *, request: EventStreamsCreateRequest, request_options: typing.Optional[RequestOptions] = None
727 ) -> AsyncHttpResponse[CreateEventStreamResponseContent]:
728 """
729 Parameters
730 ----------
731 request : EventStreamsCreateRequest
732
733 request_options : typing.Optional[RequestOptions]
734 Request-specific configuration.
735
736 Returns
737 -------
738 AsyncHttpResponse[CreateEventStreamResponseContent]
739 Event Stream stream created successfully.
740 """
741 _response = await self._client_wrapper.httpx_client.request(
742 "event-streams",
743 method="POST",
744 json=convert_and_respect_annotation_metadata(
745 object_=request, annotation=EventStreamsCreateRequest, direction="write"
746 ),
747 request_options=request_options,
748 omit=OMIT,
749 )
750 try:
751 if 200 <= _response.status_code < 300:
752 _data = typing.cast(
753 CreateEventStreamResponseContent,
754 parse_obj_as(
755 type_=CreateEventStreamResponseContent, # type: ignore
756 object_=_response.json(),
757 ),
758 )
759 return AsyncHttpResponse(response=_response, data=_data)
760 if _response.status_code == 400:
761 raise BadRequestError(
762 headers=dict(_response.headers),
763 body=typing.cast(
764 typing.Any,
765 parse_obj_as(
766 type_=typing.Any, # type: ignore
767 object_=_response.json(),
768 ),
769 ),
770 )
771 if _response.status_code == 401:
772 raise UnauthorizedError(
773 headers=dict(_response.headers),
774 body=typing.cast(
775 typing.Any,
776 parse_obj_as(
777 type_=typing.Any, # type: ignore
778 object_=_response.json(),
779 ),
780 ),
781 )
782 if _response.status_code == 403:
783 raise ForbiddenError(
784 headers=dict(_response.headers),
785 body=typing.cast(
786 typing.Any,
787 parse_obj_as(
788 type_=typing.Any, # type: ignore
789 object_=_response.json(),
790 ),
791 ),
792 )
793 if _response.status_code == 409:
794 raise ConflictError(
795 headers=dict(_response.headers),
796 body=typing.cast(
797 typing.Any,
798 parse_obj_as(
799 type_=typing.Any, # type: ignore
800 object_=_response.json(),
801 ),
802 ),
803 )
804 if _response.status_code == 429:
805 raise TooManyRequestsError(
806 headers=dict(_response.headers),
807 body=typing.cast(
808 typing.Any,
809 parse_obj_as(
810 type_=typing.Any, # type: ignore
811 object_=_response.json(),
812 ),
813 ),
814 )
815 _response_json = _response.json()
816 except JSONDecodeError:
817 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
818 except ValidationError as e:
819 raise ParsingError(
820 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
821 )
822 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
823
824 async def get(
825 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
826 ) -> AsyncHttpResponse[GetEventStreamResponseContent]:
827 """
828 Parameters
829 ----------
830 id : str
831 Unique identifier for the event stream.
832
833 request_options : typing.Optional[RequestOptions]
834 Request-specific configuration.
835
836 Returns
837 -------
838 AsyncHttpResponse[GetEventStreamResponseContent]
839 Event stream successfully retrieved.
840 """
841 _response = await self._client_wrapper.httpx_client.request(
842 f"event-streams/{encode_path_param(id)}",
843 method="GET",
844 request_options=request_options,
845 )
846 try:
847 if 200 <= _response.status_code < 300:
848 _data = typing.cast(
849 GetEventStreamResponseContent,
850 parse_obj_as(
851 type_=GetEventStreamResponseContent, # type: ignore
852 object_=_response.json(),
853 ),
854 )
855 return AsyncHttpResponse(response=_response, data=_data)
856 if _response.status_code == 401:
857 raise UnauthorizedError(
858 headers=dict(_response.headers),
859 body=typing.cast(
860 typing.Any,
861 parse_obj_as(
862 type_=typing.Any, # type: ignore
863 object_=_response.json(),
864 ),
865 ),
866 )
867 if _response.status_code == 403:
868 raise ForbiddenError(
869 headers=dict(_response.headers),
870 body=typing.cast(
871 typing.Any,
872 parse_obj_as(
873 type_=typing.Any, # type: ignore
874 object_=_response.json(),
875 ),
876 ),
877 )
878 if _response.status_code == 404:
879 raise NotFoundError(
880 headers=dict(_response.headers),
881 body=typing.cast(
882 typing.Any,
883 parse_obj_as(
884 type_=typing.Any, # type: ignore
885 object_=_response.json(),
886 ),
887 ),
888 )
889 if _response.status_code == 429:
890 raise TooManyRequestsError(
891 headers=dict(_response.headers),
892 body=typing.cast(
893 typing.Any,
894 parse_obj_as(
895 type_=typing.Any, # type: ignore
896 object_=_response.json(),
897 ),
898 ),
899 )
900 _response_json = _response.json()
901 except JSONDecodeError:
902 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
903 except ValidationError as e:
904 raise ParsingError(
905 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
906 )
907 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
908
909 async def delete(
910 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
911 ) -> AsyncHttpResponse[None]:
912 """
913 Parameters
914 ----------
915 id : str
916 Unique identifier for the event stream.
917
918 request_options : typing.Optional[RequestOptions]
919 Request-specific configuration.
920
921 Returns
922 -------
923 AsyncHttpResponse[None]
924 """
925 _response = await self._client_wrapper.httpx_client.request(
926 f"event-streams/{encode_path_param(id)}",
927 method="DELETE",
928 request_options=request_options,
929 )
930 try:
931 if 200 <= _response.status_code < 300:
932 return AsyncHttpResponse(response=_response, data=None)
933 if _response.status_code == 400:
934 raise BadRequestError(
935 headers=dict(_response.headers),
936 body=typing.cast(
937 typing.Any,
938 parse_obj_as(
939 type_=typing.Any, # type: ignore
940 object_=_response.json(),
941 ),
942 ),
943 )
944 if _response.status_code == 401:
945 raise UnauthorizedError(
946 headers=dict(_response.headers),
947 body=typing.cast(
948 typing.Any,
949 parse_obj_as(
950 type_=typing.Any, # type: ignore
951 object_=_response.json(),
952 ),
953 ),
954 )
955 if _response.status_code == 403:
956 raise ForbiddenError(
957 headers=dict(_response.headers),
958 body=typing.cast(
959 typing.Any,
960 parse_obj_as(
961 type_=typing.Any, # type: ignore
962 object_=_response.json(),
963 ),
964 ),
965 )
966 if _response.status_code == 429:
967 raise TooManyRequestsError(
968 headers=dict(_response.headers),
969 body=typing.cast(
970 typing.Any,
971 parse_obj_as(
972 type_=typing.Any, # type: ignore
973 object_=_response.json(),
974 ),
975 ),
976 )
977 _response_json = _response.json()
978 except JSONDecodeError:
979 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
980 except ValidationError as e:
981 raise ParsingError(
982 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
983 )
984 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
985
986 async def update(
987 self,
988 id: str,
989 *,
990 name: typing.Optional[str] = OMIT,
991 subscriptions: typing.Optional[typing.Sequence[EventStreamSubscription]] = OMIT,
992 destination: typing.Optional[EventStreamDestinationPatch] = OMIT,
993 status: typing.Optional[EventStreamStatusEnum] = OMIT,
994 request_options: typing.Optional[RequestOptions] = None,
995 ) -> AsyncHttpResponse[UpdateEventStreamResponseContent]:
996 """
997 Parameters
998 ----------
999 id : str
1000 Unique identifier for the event stream.
1001
1002 name : typing.Optional[str]
1003 Name of the event stream.
1004
1005 subscriptions : typing.Optional[typing.Sequence[EventStreamSubscription]]
1006 List of event types subscribed to in this stream.
1007
1008 destination : typing.Optional[EventStreamDestinationPatch]
1009
1010 status : typing.Optional[EventStreamStatusEnum]
1011
1012 request_options : typing.Optional[RequestOptions]
1013 Request-specific configuration.
1014
1015 Returns
1016 -------
1017 AsyncHttpResponse[UpdateEventStreamResponseContent]
1018 Event stream successfully updated.
1019 """
1020 _response = await self._client_wrapper.httpx_client.request(
1021 f"event-streams/{encode_path_param(id)}",
1022 method="PATCH",
1023 json={
1024 "name": name,
1025 "subscriptions": convert_and_respect_annotation_metadata(
1026 object_=subscriptions, annotation=typing.Sequence[EventStreamSubscription], direction="write"
1027 ),
1028 "destination": convert_and_respect_annotation_metadata(
1029 object_=destination, annotation=EventStreamDestinationPatch, direction="write"
1030 ),
1031 "status": status,
1032 },
1033 headers={
1034 "content-type": "application/json",
1035 },
1036 request_options=request_options,
1037 omit=OMIT,
1038 )
1039 try:
1040 if 200 <= _response.status_code < 300:
1041 _data = typing.cast(
1042 UpdateEventStreamResponseContent,
1043 parse_obj_as(
1044 type_=UpdateEventStreamResponseContent, # type: ignore
1045 object_=_response.json(),
1046 ),
1047 )
1048 return AsyncHttpResponse(response=_response, data=_data)
1049 if _response.status_code == 400:
1050 raise BadRequestError(
1051 headers=dict(_response.headers),
1052 body=typing.cast(
1053 typing.Any,
1054 parse_obj_as(
1055 type_=typing.Any, # type: ignore
1056 object_=_response.json(),
1057 ),
1058 ),
1059 )
1060 if _response.status_code == 401:
1061 raise UnauthorizedError(
1062 headers=dict(_response.headers),
1063 body=typing.cast(
1064 typing.Any,
1065 parse_obj_as(
1066 type_=typing.Any, # type: ignore
1067 object_=_response.json(),
1068 ),
1069 ),
1070 )
1071 if _response.status_code == 403:
1072 raise ForbiddenError(
1073 headers=dict(_response.headers),
1074 body=typing.cast(
1075 typing.Any,
1076 parse_obj_as(
1077 type_=typing.Any, # type: ignore
1078 object_=_response.json(),
1079 ),
1080 ),
1081 )
1082 if _response.status_code == 429:
1083 raise TooManyRequestsError(
1084 headers=dict(_response.headers),
1085 body=typing.cast(
1086 typing.Any,
1087 parse_obj_as(
1088 type_=typing.Any, # type: ignore
1089 object_=_response.json(),
1090 ),
1091 ),
1092 )
1093 _response_json = _response.json()
1094 except JSONDecodeError:
1095 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1096 except ValidationError as e:
1097 raise ParsingError(
1098 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1099 )
1100 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1101
1102 async def test(
1103 self,
1104 id: str,
1105 *,
1106 event_type: EventStreamTestEventTypeEnum,
1107 data: typing.Optional[TestEventDataContent] = OMIT,
1108 request_options: typing.Optional[RequestOptions] = None,
1109 ) -> AsyncHttpResponse[CreateEventStreamTestEventResponseContent]:
1110 """
1111 Parameters
1112 ----------
1113 id : str
1114 Unique identifier for the event stream.
1115
1116 event_type : EventStreamTestEventTypeEnum
1117
1118 data : typing.Optional[TestEventDataContent]
1119
1120 request_options : typing.Optional[RequestOptions]
1121 Request-specific configuration.
1122
1123 Returns
1124 -------
1125 AsyncHttpResponse[CreateEventStreamTestEventResponseContent]
1126 Test event successfully submitted.
1127 """
1128 _response = await self._client_wrapper.httpx_client.request(
1129 f"event-streams/{encode_path_param(id)}/test",
1130 method="POST",
1131 json={
1132 "event_type": event_type,
1133 "data": data,
1134 },
1135 headers={
1136 "content-type": "application/json",
1137 },
1138 request_options=request_options,
1139 omit=OMIT,
1140 )
1141 try:
1142 if 200 <= _response.status_code < 300:
1143 _data = typing.cast(
1144 CreateEventStreamTestEventResponseContent,
1145 parse_obj_as(
1146 type_=CreateEventStreamTestEventResponseContent, # type: ignore
1147 object_=_response.json(),
1148 ),
1149 )
1150 return AsyncHttpResponse(response=_response, data=_data)
1151 if _response.status_code == 401:
1152 raise UnauthorizedError(
1153 headers=dict(_response.headers),
1154 body=typing.cast(
1155 typing.Any,
1156 parse_obj_as(
1157 type_=typing.Any, # type: ignore
1158 object_=_response.json(),
1159 ),
1160 ),
1161 )
1162 if _response.status_code == 403:
1163 raise ForbiddenError(
1164 headers=dict(_response.headers),
1165 body=typing.cast(
1166 typing.Any,
1167 parse_obj_as(
1168 type_=typing.Any, # type: ignore
1169 object_=_response.json(),
1170 ),
1171 ),
1172 )
1173 if _response.status_code == 429:
1174 raise TooManyRequestsError(
1175 headers=dict(_response.headers),
1176 body=typing.cast(
1177 typing.Any,
1178 parse_obj_as(
1179 type_=typing.Any, # type: ignore
1180 object_=_response.json(),
1181 ),
1182 ),
1183 )
1184 _response_json = _response.json()
1185 except JSONDecodeError:
1186 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1187 except ValidationError as e:
1188 raise ParsingError(
1189 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1190 )
1191 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)