Debian Codegraph @

src/auth0/management/connections/users/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.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 pydantic import ValidationError
19
20
21 class RawUsersClient:
22 def __init__(self, *, client_wrapper: SyncClientWrapper):
23 self._client_wrapper = client_wrapper
24
25 def delete_by_email(
26 self, id: str, *, email: str, request_options: typing.Optional[RequestOptions] = None
27 ) -> HttpResponse[None]:
28 """
29 Deletes a specified connection user by its email (you cannot delete all users from specific connection). Currently, only Database Connections are supported.
30
31 Parameters
32 ----------
33 id : str
34 The id of the connection (currently only database connections are supported)
35
36 email : str
37 The email of the user to delete
38
39 request_options : typing.Optional[RequestOptions]
40 Request-specific configuration.
41
42 Returns
43 -------
44 HttpResponse[None]
45 """
46 _response = self._client_wrapper.httpx_client.request(
47 f"connections/{encode_path_param(id)}/users",
48 method="DELETE",
49 params={
50 "email": email,
51 },
52 request_options=request_options,
53 )
54 try:
55 if 200 <= _response.status_code < 300:
56 return HttpResponse(response=_response, data=None)
57 if _response.status_code == 400:
58 raise BadRequestError(
59 headers=dict(_response.headers),
60 body=typing.cast(
61 typing.Any,
62 parse_obj_as(
63 type_=typing.Any, # type: ignore
64 object_=_response.json(),
65 ),
66 ),
67 )
68 if _response.status_code == 401:
69 raise UnauthorizedError(
70 headers=dict(_response.headers),
71 body=typing.cast(
72 typing.Any,
73 parse_obj_as(
74 type_=typing.Any, # type: ignore
75 object_=_response.json(),
76 ),
77 ),
78 )
79 if _response.status_code == 403:
80 raise ForbiddenError(
81 headers=dict(_response.headers),
82 body=typing.cast(
83 typing.Any,
84 parse_obj_as(
85 type_=typing.Any, # type: ignore
86 object_=_response.json(),
87 ),
88 ),
89 )
90 if _response.status_code == 404:
91 raise NotFoundError(
92 headers=dict(_response.headers),
93 body=typing.cast(
94 typing.Any,
95 parse_obj_as(
96 type_=typing.Any, # type: ignore
97 object_=_response.json(),
98 ),
99 ),
100 )
101 if _response.status_code == 429:
102 raise TooManyRequestsError(
103 headers=dict(_response.headers),
104 body=typing.cast(
105 typing.Any,
106 parse_obj_as(
107 type_=typing.Any, # type: ignore
108 object_=_response.json(),
109 ),
110 ),
111 )
112 _response_json = _response.json()
113 except JSONDecodeError:
114 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
115 except ValidationError as e:
116 raise ParsingError(
117 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
118 )
119 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
120
121
122 class AsyncRawUsersClient:
123 def __init__(self, *, client_wrapper: AsyncClientWrapper):
124 self._client_wrapper = client_wrapper
125
126 async def delete_by_email(
127 self, id: str, *, email: str, request_options: typing.Optional[RequestOptions] = None
128 ) -> AsyncHttpResponse[None]:
129 """
130 Deletes a specified connection user by its email (you cannot delete all users from specific connection). Currently, only Database Connections are supported.
131
132 Parameters
133 ----------
134 id : str
135 The id of the connection (currently only database connections are supported)
136
137 email : str
138 The email of the user to delete
139
140 request_options : typing.Optional[RequestOptions]
141 Request-specific configuration.
142
143 Returns
144 -------
145 AsyncHttpResponse[None]
146 """
147 _response = await self._client_wrapper.httpx_client.request(
148 f"connections/{encode_path_param(id)}/users",
149 method="DELETE",
150 params={
151 "email": email,
152 },
153 request_options=request_options,
154 )
155 try:
156 if 200 <= _response.status_code < 300:
157 return AsyncHttpResponse(response=_response, data=None)
158 if _response.status_code == 400:
159 raise BadRequestError(
160 headers=dict(_response.headers),
161 body=typing.cast(
162 typing.Any,
163 parse_obj_as(
164 type_=typing.Any, # type: ignore
165 object_=_response.json(),
166 ),
167 ),
168 )
169 if _response.status_code == 401:
170 raise UnauthorizedError(
171 headers=dict(_response.headers),
172 body=typing.cast(
173 typing.Any,
174 parse_obj_as(
175 type_=typing.Any, # type: ignore
176 object_=_response.json(),
177 ),
178 ),
179 )
180 if _response.status_code == 403:
181 raise ForbiddenError(
182 headers=dict(_response.headers),
183 body=typing.cast(
184 typing.Any,
185 parse_obj_as(
186 type_=typing.Any, # type: ignore
187 object_=_response.json(),
188 ),
189 ),
190 )
191 if _response.status_code == 404:
192 raise NotFoundError(
193 headers=dict(_response.headers),
194 body=typing.cast(
195 typing.Any,
196 parse_obj_as(
197 type_=typing.Any, # type: ignore
198 object_=_response.json(),
199 ),
200 ),
201 )
202 if _response.status_code == 429:
203 raise TooManyRequestsError(
204 headers=dict(_response.headers),
205 body=typing.cast(
206 typing.Any,
207 parse_obj_as(
208 type_=typing.Any, # type: ignore
209 object_=_response.json(),
210 ),
211 ),
212 )
213 _response_json = _response.json()
214 except JSONDecodeError:
215 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
216 except ValidationError as e:
217 raise ParsingError(
218 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
219 )
220 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)