Debian Codegraph @

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