Debian Codegraph @

src/auth0/management/prompts/partials/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 ...types.get_partials_response_content import GetPartialsResponseContent
19 from ...types.partial_groups_enum import PartialGroupsEnum
20 from ...types.set_partials_request_content import SetPartialsRequestContent
21 from pydantic import ValidationError
22
23 # this is used as the default value for optional parameters
24 OMIT = typing.cast(typing.Any, ...)
25
26
27 class RawPartialsClient:
28 def __init__(self, *, client_wrapper: SyncClientWrapper):
29 self._client_wrapper = client_wrapper
30
31 def get(
32 self, prompt: PartialGroupsEnum, *, request_options: typing.Optional[RequestOptions] = None
33 ) -> HttpResponse[GetPartialsResponseContent]:
34 """
35 Get template partials for a prompt
36
37 Parameters
38 ----------
39 prompt : PartialGroupsEnum
40 Name of the prompt.
41
42 request_options : typing.Optional[RequestOptions]
43 Request-specific configuration.
44
45 Returns
46 -------
47 HttpResponse[GetPartialsResponseContent]
48 Prompt partials successfully retrieved.
49 """
50 _response = self._client_wrapper.httpx_client.request(
51 f"prompts/{encode_path_param(prompt)}/partials",
52 method="GET",
53 request_options=request_options,
54 )
55 try:
56 if 200 <= _response.status_code < 300:
57 _data = typing.cast(
58 GetPartialsResponseContent,
59 parse_obj_as(
60 type_=GetPartialsResponseContent, # type: ignore
61 object_=_response.json(),
62 ),
63 )
64 return HttpResponse(response=_response, data=_data)
65 if _response.status_code == 400:
66 raise BadRequestError(
67 headers=dict(_response.headers),
68 body=typing.cast(
69 typing.Any,
70 parse_obj_as(
71 type_=typing.Any, # type: ignore
72 object_=_response.json(),
73 ),
74 ),
75 )
76 if _response.status_code == 401:
77 raise UnauthorizedError(
78 headers=dict(_response.headers),
79 body=typing.cast(
80 typing.Any,
81 parse_obj_as(
82 type_=typing.Any, # type: ignore
83 object_=_response.json(),
84 ),
85 ),
86 )
87 if _response.status_code == 403:
88 raise ForbiddenError(
89 headers=dict(_response.headers),
90 body=typing.cast(
91 typing.Any,
92 parse_obj_as(
93 type_=typing.Any, # type: ignore
94 object_=_response.json(),
95 ),
96 ),
97 )
98 if _response.status_code == 404:
99 raise NotFoundError(
100 headers=dict(_response.headers),
101 body=typing.cast(
102 typing.Any,
103 parse_obj_as(
104 type_=typing.Any, # type: ignore
105 object_=_response.json(),
106 ),
107 ),
108 )
109 if _response.status_code == 429:
110 raise TooManyRequestsError(
111 headers=dict(_response.headers),
112 body=typing.cast(
113 typing.Any,
114 parse_obj_as(
115 type_=typing.Any, # type: ignore
116 object_=_response.json(),
117 ),
118 ),
119 )
120 _response_json = _response.json()
121 except JSONDecodeError:
122 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
123 except ValidationError as e:
124 raise ParsingError(
125 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
126 )
127 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
128
129 def set(
130 self,
131 prompt: PartialGroupsEnum,
132 *,
133 request: SetPartialsRequestContent,
134 request_options: typing.Optional[RequestOptions] = None,
135 ) -> HttpResponse[None]:
136 """
137 Set template partials for a prompt
138
139 Parameters
140 ----------
141 prompt : PartialGroupsEnum
142 Name of the prompt.
143
144 request : SetPartialsRequestContent
145
146 request_options : typing.Optional[RequestOptions]
147 Request-specific configuration.
148
149 Returns
150 -------
151 HttpResponse[None]
152 """
153 _response = self._client_wrapper.httpx_client.request(
154 f"prompts/{encode_path_param(prompt)}/partials",
155 method="PUT",
156 json=request,
157 request_options=request_options,
158 omit=OMIT,
159 )
160 try:
161 if 200 <= _response.status_code < 300:
162 return HttpResponse(response=_response, data=None)
163 if _response.status_code == 400:
164 raise BadRequestError(
165 headers=dict(_response.headers),
166 body=typing.cast(
167 typing.Any,
168 parse_obj_as(
169 type_=typing.Any, # type: ignore
170 object_=_response.json(),
171 ),
172 ),
173 )
174 if _response.status_code == 401:
175 raise UnauthorizedError(
176 headers=dict(_response.headers),
177 body=typing.cast(
178 typing.Any,
179 parse_obj_as(
180 type_=typing.Any, # type: ignore
181 object_=_response.json(),
182 ),
183 ),
184 )
185 if _response.status_code == 403:
186 raise ForbiddenError(
187 headers=dict(_response.headers),
188 body=typing.cast(
189 typing.Any,
190 parse_obj_as(
191 type_=typing.Any, # type: ignore
192 object_=_response.json(),
193 ),
194 ),
195 )
196 if _response.status_code == 429:
197 raise TooManyRequestsError(
198 headers=dict(_response.headers),
199 body=typing.cast(
200 typing.Any,
201 parse_obj_as(
202 type_=typing.Any, # type: ignore
203 object_=_response.json(),
204 ),
205 ),
206 )
207 _response_json = _response.json()
208 except JSONDecodeError:
209 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
210 except ValidationError as e:
211 raise ParsingError(
212 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
213 )
214 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
215
216
217 class AsyncRawPartialsClient:
218 def __init__(self, *, client_wrapper: AsyncClientWrapper):
219 self._client_wrapper = client_wrapper
220
221 async def get(
222 self, prompt: PartialGroupsEnum, *, request_options: typing.Optional[RequestOptions] = None
223 ) -> AsyncHttpResponse[GetPartialsResponseContent]:
224 """
225 Get template partials for a prompt
226
227 Parameters
228 ----------
229 prompt : PartialGroupsEnum
230 Name of the prompt.
231
232 request_options : typing.Optional[RequestOptions]
233 Request-specific configuration.
234
235 Returns
236 -------
237 AsyncHttpResponse[GetPartialsResponseContent]
238 Prompt partials successfully retrieved.
239 """
240 _response = await self._client_wrapper.httpx_client.request(
241 f"prompts/{encode_path_param(prompt)}/partials",
242 method="GET",
243 request_options=request_options,
244 )
245 try:
246 if 200 <= _response.status_code < 300:
247 _data = typing.cast(
248 GetPartialsResponseContent,
249 parse_obj_as(
250 type_=GetPartialsResponseContent, # type: ignore
251 object_=_response.json(),
252 ),
253 )
254 return AsyncHttpResponse(response=_response, data=_data)
255 if _response.status_code == 400:
256 raise BadRequestError(
257 headers=dict(_response.headers),
258 body=typing.cast(
259 typing.Any,
260 parse_obj_as(
261 type_=typing.Any, # type: ignore
262 object_=_response.json(),
263 ),
264 ),
265 )
266 if _response.status_code == 401:
267 raise UnauthorizedError(
268 headers=dict(_response.headers),
269 body=typing.cast(
270 typing.Any,
271 parse_obj_as(
272 type_=typing.Any, # type: ignore
273 object_=_response.json(),
274 ),
275 ),
276 )
277 if _response.status_code == 403:
278 raise ForbiddenError(
279 headers=dict(_response.headers),
280 body=typing.cast(
281 typing.Any,
282 parse_obj_as(
283 type_=typing.Any, # type: ignore
284 object_=_response.json(),
285 ),
286 ),
287 )
288 if _response.status_code == 404:
289 raise NotFoundError(
290 headers=dict(_response.headers),
291 body=typing.cast(
292 typing.Any,
293 parse_obj_as(
294 type_=typing.Any, # type: ignore
295 object_=_response.json(),
296 ),
297 ),
298 )
299 if _response.status_code == 429:
300 raise TooManyRequestsError(
301 headers=dict(_response.headers),
302 body=typing.cast(
303 typing.Any,
304 parse_obj_as(
305 type_=typing.Any, # type: ignore
306 object_=_response.json(),
307 ),
308 ),
309 )
310 _response_json = _response.json()
311 except JSONDecodeError:
312 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
313 except ValidationError as e:
314 raise ParsingError(
315 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
316 )
317 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
318
319 async def set(
320 self,
321 prompt: PartialGroupsEnum,
322 *,
323 request: SetPartialsRequestContent,
324 request_options: typing.Optional[RequestOptions] = None,
325 ) -> AsyncHttpResponse[None]:
326 """
327 Set template partials for a prompt
328
329 Parameters
330 ----------
331 prompt : PartialGroupsEnum
332 Name of the prompt.
333
334 request : SetPartialsRequestContent
335
336 request_options : typing.Optional[RequestOptions]
337 Request-specific configuration.
338
339 Returns
340 -------
341 AsyncHttpResponse[None]
342 """
343 _response = await self._client_wrapper.httpx_client.request(
344 f"prompts/{encode_path_param(prompt)}/partials",
345 method="PUT",
346 json=request,
347 request_options=request_options,
348 omit=OMIT,
349 )
350 try:
351 if 200 <= _response.status_code < 300:
352 return AsyncHttpResponse(response=_response, data=None)
353 if _response.status_code == 400:
354 raise BadRequestError(
355 headers=dict(_response.headers),
356 body=typing.cast(
357 typing.Any,
358 parse_obj_as(
359 type_=typing.Any, # type: ignore
360 object_=_response.json(),
361 ),
362 ),
363 )
364 if _response.status_code == 401:
365 raise UnauthorizedError(
366 headers=dict(_response.headers),
367 body=typing.cast(
368 typing.Any,
369 parse_obj_as(
370 type_=typing.Any, # type: ignore
371 object_=_response.json(),
372 ),
373 ),
374 )
375 if _response.status_code == 403:
376 raise ForbiddenError(
377 headers=dict(_response.headers),
378 body=typing.cast(
379 typing.Any,
380 parse_obj_as(
381 type_=typing.Any, # type: ignore
382 object_=_response.json(),
383 ),
384 ),
385 )
386 if _response.status_code == 429:
387 raise TooManyRequestsError(
388 headers=dict(_response.headers),
389 body=typing.cast(
390 typing.Any,
391 parse_obj_as(
392 type_=typing.Any, # type: ignore
393 object_=_response.json(),
394 ),
395 ),
396 )
397 _response_json = _response.json()
398 except JSONDecodeError:
399 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
400 except ValidationError as e:
401 raise ParsingError(
402 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
403 )
404 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)