Debian Codegraph @

src/auth0/management/client_grants/organizations/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.jsonable_encoder import encode_path_param
9 from ...core.pagination import AsyncPager, SyncPager
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.list_client_grant_organizations_paginated_response_content import (
19 ListClientGrantOrganizationsPaginatedResponseContent,
20 )
21 from ...types.organization import Organization
22 from pydantic import ValidationError
23
24
25 class RawOrganizationsClient:
26 def __init__(self, *, client_wrapper: SyncClientWrapper):
27 self._client_wrapper = client_wrapper
28
29 def list(
30 self,
31 id: str,
32 *,
33 from_: typing.Optional[str] = None,
34 take: typing.Optional[int] = 50,
35 request_options: typing.Optional[RequestOptions] = None,
36 ) -> SyncPager[Organization, ListClientGrantOrganizationsPaginatedResponseContent]:
37 """
38 Parameters
39 ----------
40 id : str
41 ID of the client grant
42
43 from_ : typing.Optional[str]
44 Optional Id from which to start selection.
45
46 take : typing.Optional[int]
47 Number of results per page. Defaults to 50.
48
49 request_options : typing.Optional[RequestOptions]
50 Request-specific configuration.
51
52 Returns
53 -------
54 SyncPager[Organization, ListClientGrantOrganizationsPaginatedResponseContent]
55 Organizations successfully retrieved.
56 """
57 _response = self._client_wrapper.httpx_client.request(
58 f"client-grants/{encode_path_param(id)}/organizations",
59 method="GET",
60 params={
61 "from": from_,
62 "take": take,
63 },
64 request_options=request_options,
65 )
66 try:
67 if 200 <= _response.status_code < 300:
68 _parsed_response = typing.cast(
69 ListClientGrantOrganizationsPaginatedResponseContent,
70 parse_obj_as(
71 type_=ListClientGrantOrganizationsPaginatedResponseContent, # type: ignore
72 object_=_response.json(),
73 ),
74 )
75 _items = _parsed_response.organizations
76 _parsed_next = _parsed_response.next
77 _has_next = _parsed_next is not None and _parsed_next != ""
78 _get_next = lambda: self.list(
79 id,
80 from_=_parsed_next,
81 take=take,
82 request_options=request_options,
83 )
84 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
85 if _response.status_code == 400:
86 raise BadRequestError(
87 headers=dict(_response.headers),
88 body=typing.cast(
89 typing.Any,
90 parse_obj_as(
91 type_=typing.Any, # type: ignore
92 object_=_response.json(),
93 ),
94 ),
95 )
96 if _response.status_code == 401:
97 raise UnauthorizedError(
98 headers=dict(_response.headers),
99 body=typing.cast(
100 typing.Any,
101 parse_obj_as(
102 type_=typing.Any, # type: ignore
103 object_=_response.json(),
104 ),
105 ),
106 )
107 if _response.status_code == 403:
108 raise ForbiddenError(
109 headers=dict(_response.headers),
110 body=typing.cast(
111 typing.Any,
112 parse_obj_as(
113 type_=typing.Any, # type: ignore
114 object_=_response.json(),
115 ),
116 ),
117 )
118 if _response.status_code == 404:
119 raise NotFoundError(
120 headers=dict(_response.headers),
121 body=typing.cast(
122 typing.Any,
123 parse_obj_as(
124 type_=typing.Any, # type: ignore
125 object_=_response.json(),
126 ),
127 ),
128 )
129 if _response.status_code == 429:
130 raise TooManyRequestsError(
131 headers=dict(_response.headers),
132 body=typing.cast(
133 typing.Any,
134 parse_obj_as(
135 type_=typing.Any, # type: ignore
136 object_=_response.json(),
137 ),
138 ),
139 )
140 _response_json = _response.json()
141 except JSONDecodeError:
142 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
143 except ValidationError as e:
144 raise ParsingError(
145 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
146 )
147 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
148
149
150 class AsyncRawOrganizationsClient:
151 def __init__(self, *, client_wrapper: AsyncClientWrapper):
152 self._client_wrapper = client_wrapper
153
154 async def list(
155 self,
156 id: str,
157 *,
158 from_: typing.Optional[str] = None,
159 take: typing.Optional[int] = 50,
160 request_options: typing.Optional[RequestOptions] = None,
161 ) -> AsyncPager[Organization, ListClientGrantOrganizationsPaginatedResponseContent]:
162 """
163 Parameters
164 ----------
165 id : str
166 ID of the client grant
167
168 from_ : typing.Optional[str]
169 Optional Id from which to start selection.
170
171 take : typing.Optional[int]
172 Number of results per page. Defaults to 50.
173
174 request_options : typing.Optional[RequestOptions]
175 Request-specific configuration.
176
177 Returns
178 -------
179 AsyncPager[Organization, ListClientGrantOrganizationsPaginatedResponseContent]
180 Organizations successfully retrieved.
181 """
182 _response = await self._client_wrapper.httpx_client.request(
183 f"client-grants/{encode_path_param(id)}/organizations",
184 method="GET",
185 params={
186 "from": from_,
187 "take": take,
188 },
189 request_options=request_options,
190 )
191 try:
192 if 200 <= _response.status_code < 300:
193 _parsed_response = typing.cast(
194 ListClientGrantOrganizationsPaginatedResponseContent,
195 parse_obj_as(
196 type_=ListClientGrantOrganizationsPaginatedResponseContent, # type: ignore
197 object_=_response.json(),
198 ),
199 )
200 _items = _parsed_response.organizations
201 _parsed_next = _parsed_response.next
202 _has_next = _parsed_next is not None and _parsed_next != ""
203
204 async def _get_next():
205 return await self.list(
206 id,
207 from_=_parsed_next,
208 take=take,
209 request_options=request_options,
210 )
211
212 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
213 if _response.status_code == 400:
214 raise BadRequestError(
215 headers=dict(_response.headers),
216 body=typing.cast(
217 typing.Any,
218 parse_obj_as(
219 type_=typing.Any, # type: ignore
220 object_=_response.json(),
221 ),
222 ),
223 )
224 if _response.status_code == 401:
225 raise UnauthorizedError(
226 headers=dict(_response.headers),
227 body=typing.cast(
228 typing.Any,
229 parse_obj_as(
230 type_=typing.Any, # type: ignore
231 object_=_response.json(),
232 ),
233 ),
234 )
235 if _response.status_code == 403:
236 raise ForbiddenError(
237 headers=dict(_response.headers),
238 body=typing.cast(
239 typing.Any,
240 parse_obj_as(
241 type_=typing.Any, # type: ignore
242 object_=_response.json(),
243 ),
244 ),
245 )
246 if _response.status_code == 404:
247 raise NotFoundError(
248 headers=dict(_response.headers),
249 body=typing.cast(
250 typing.Any,
251 parse_obj_as(
252 type_=typing.Any, # type: ignore
253 object_=_response.json(),
254 ),
255 ),
256 )
257 if _response.status_code == 429:
258 raise TooManyRequestsError(
259 headers=dict(_response.headers),
260 body=typing.cast(
261 typing.Any,
262 parse_obj_as(
263 type_=typing.Any, # type: ignore
264 object_=_response.json(),
265 ),
266 ),
267 )
268 _response_json = _response.json()
269 except JSONDecodeError:
270 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
271 except ValidationError as e:
272 raise ParsingError(
273 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
274 )
275 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)