Debian Codegraph @

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