Debian Codegraph @

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