Debian Codegraph @

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