Debian Codegraph @

src/auth0/management/jobs/verification_email/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.parse_error import ParsingError
10 from ...core.pydantic_utilities import parse_obj_as
11 from ...core.request_options import RequestOptions
12 from ...core.serialization import convert_and_respect_annotation_metadata
13 from ...errors.bad_request_error import BadRequestError
14 from ...errors.forbidden_error import ForbiddenError
15 from ...errors.too_many_requests_error import TooManyRequestsError
16 from ...errors.unauthorized_error import UnauthorizedError
17 from ...types.create_verification_email_response_content import CreateVerificationEmailResponseContent
18 from ...types.identity import Identity
19 from pydantic import ValidationError
20
21 # this is used as the default value for optional parameters
22 OMIT = typing.cast(typing.Any, ...)
23
24
25 class RawVerificationEmailClient:
26 def __init__(self, *, client_wrapper: SyncClientWrapper):
27 self._client_wrapper = client_wrapper
28
29 def create(
30 self,
31 *,
32 user_id: str,
33 client_id: typing.Optional[str] = OMIT,
34 identity: typing.Optional[Identity] = OMIT,
35 organization_id: typing.Optional[str] = OMIT,
36 request_options: typing.Optional[RequestOptions] = None,
37 ) -> HttpResponse[CreateVerificationEmailResponseContent]:
38 """
39 Send an email to the specified user that asks them to click a link to [verify their email address](https://auth0.com/docs/email/custom#verification-email).
40
41 Note: You must have the `Status` toggle enabled for the verification email template for the email to be sent.
42
43 Parameters
44 ----------
45 user_id : str
46 user_id of the user to send the verification email to.
47
48 client_id : typing.Optional[str]
49 client_id of the client (application). If no value provided, the global Client ID will be used.
50
51 identity : typing.Optional[Identity]
52
53 organization_id : typing.Optional[str]
54 (Optional) Organization ID – the ID of the Organization. If provided, organization parameters will be made available to the email template and organization branding will be applied to the prompt. In addition, the redirect link in the prompt will include organization_id and organization_name query string parameters.
55
56 request_options : typing.Optional[RequestOptions]
57 Request-specific configuration.
58
59 Returns
60 -------
61 HttpResponse[CreateVerificationEmailResponseContent]
62 Job successfully created.
63 """
64 _response = self._client_wrapper.httpx_client.request(
65 "jobs/verification-email",
66 method="POST",
67 json={
68 "user_id": user_id,
69 "client_id": client_id,
70 "identity": convert_and_respect_annotation_metadata(
71 object_=identity, annotation=Identity, direction="write"
72 ),
73 "organization_id": organization_id,
74 },
75 headers={
76 "content-type": "application/json",
77 },
78 request_options=request_options,
79 omit=OMIT,
80 )
81 try:
82 if 200 <= _response.status_code < 300:
83 _data = typing.cast(
84 CreateVerificationEmailResponseContent,
85 parse_obj_as(
86 type_=CreateVerificationEmailResponseContent, # type: ignore
87 object_=_response.json(),
88 ),
89 )
90 return HttpResponse(response=_response, data=_data)
91 if _response.status_code == 400:
92 raise BadRequestError(
93 headers=dict(_response.headers),
94 body=typing.cast(
95 typing.Any,
96 parse_obj_as(
97 type_=typing.Any, # type: ignore
98 object_=_response.json(),
99 ),
100 ),
101 )
102 if _response.status_code == 401:
103 raise UnauthorizedError(
104 headers=dict(_response.headers),
105 body=typing.cast(
106 typing.Any,
107 parse_obj_as(
108 type_=typing.Any, # type: ignore
109 object_=_response.json(),
110 ),
111 ),
112 )
113 if _response.status_code == 403:
114 raise ForbiddenError(
115 headers=dict(_response.headers),
116 body=typing.cast(
117 typing.Any,
118 parse_obj_as(
119 type_=typing.Any, # type: ignore
120 object_=_response.json(),
121 ),
122 ),
123 )
124 if _response.status_code == 429:
125 raise TooManyRequestsError(
126 headers=dict(_response.headers),
127 body=typing.cast(
128 typing.Any,
129 parse_obj_as(
130 type_=typing.Any, # type: ignore
131 object_=_response.json(),
132 ),
133 ),
134 )
135 _response_json = _response.json()
136 except JSONDecodeError:
137 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
138 except ValidationError as e:
139 raise ParsingError(
140 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
141 )
142 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
143
144
145 class AsyncRawVerificationEmailClient:
146 def __init__(self, *, client_wrapper: AsyncClientWrapper):
147 self._client_wrapper = client_wrapper
148
149 async def create(
150 self,
151 *,
152 user_id: str,
153 client_id: typing.Optional[str] = OMIT,
154 identity: typing.Optional[Identity] = OMIT,
155 organization_id: typing.Optional[str] = OMIT,
156 request_options: typing.Optional[RequestOptions] = None,
157 ) -> AsyncHttpResponse[CreateVerificationEmailResponseContent]:
158 """
159 Send an email to the specified user that asks them to click a link to [verify their email address](https://auth0.com/docs/email/custom#verification-email).
160
161 Note: You must have the `Status` toggle enabled for the verification email template for the email to be sent.
162
163 Parameters
164 ----------
165 user_id : str
166 user_id of the user to send the verification email to.
167
168 client_id : typing.Optional[str]
169 client_id of the client (application). If no value provided, the global Client ID will be used.
170
171 identity : typing.Optional[Identity]
172
173 organization_id : typing.Optional[str]
174 (Optional) Organization ID – the ID of the Organization. If provided, organization parameters will be made available to the email template and organization branding will be applied to the prompt. In addition, the redirect link in the prompt will include organization_id and organization_name query string parameters.
175
176 request_options : typing.Optional[RequestOptions]
177 Request-specific configuration.
178
179 Returns
180 -------
181 AsyncHttpResponse[CreateVerificationEmailResponseContent]
182 Job successfully created.
183 """
184 _response = await self._client_wrapper.httpx_client.request(
185 "jobs/verification-email",
186 method="POST",
187 json={
188 "user_id": user_id,
189 "client_id": client_id,
190 "identity": convert_and_respect_annotation_metadata(
191 object_=identity, annotation=Identity, direction="write"
192 ),
193 "organization_id": organization_id,
194 },
195 headers={
196 "content-type": "application/json",
197 },
198 request_options=request_options,
199 omit=OMIT,
200 )
201 try:
202 if 200 <= _response.status_code < 300:
203 _data = typing.cast(
204 CreateVerificationEmailResponseContent,
205 parse_obj_as(
206 type_=CreateVerificationEmailResponseContent, # type: ignore
207 object_=_response.json(),
208 ),
209 )
210 return AsyncHttpResponse(response=_response, data=_data)
211 if _response.status_code == 400:
212 raise BadRequestError(
213 headers=dict(_response.headers),
214 body=typing.cast(
215 typing.Any,
216 parse_obj_as(
217 type_=typing.Any, # type: ignore
218 object_=_response.json(),
219 ),
220 ),
221 )
222 if _response.status_code == 401:
223 raise UnauthorizedError(
224 headers=dict(_response.headers),
225 body=typing.cast(
226 typing.Any,
227 parse_obj_as(
228 type_=typing.Any, # type: ignore
229 object_=_response.json(),
230 ),
231 ),
232 )
233 if _response.status_code == 403:
234 raise ForbiddenError(
235 headers=dict(_response.headers),
236 body=typing.cast(
237 typing.Any,
238 parse_obj_as(
239 type_=typing.Any, # type: ignore
240 object_=_response.json(),
241 ),
242 ),
243 )
244 if _response.status_code == 429:
245 raise TooManyRequestsError(
246 headers=dict(_response.headers),
247 body=typing.cast(
248 typing.Any,
249 parse_obj_as(
250 type_=typing.Any, # type: ignore
251 object_=_response.json(),
252 ),
253 ),
254 )
255 _response_json = _response.json()
256 except JSONDecodeError:
257 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
258 except ValidationError as e:
259 raise ParsingError(
260 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
261 )
262 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)