Debian Codegraph @

src/auth0/management/stats/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 ..errors.bad_request_error import BadRequestError
13 from ..errors.forbidden_error import ForbiddenError
14 from ..errors.too_many_requests_error import TooManyRequestsError
15 from ..errors.unauthorized_error import UnauthorizedError
16 from ..types.daily_stats import DailyStats
17 from ..types.get_active_users_count_stats_response_content import GetActiveUsersCountStatsResponseContent
18 from pydantic import ValidationError
19
20
21 class RawStatsClient:
22 def __init__(self, *, client_wrapper: SyncClientWrapper):
23 self._client_wrapper = client_wrapper
24
25 def get_active_users_count(
26 self, *, request_options: typing.Optional[RequestOptions] = None
27 ) -> HttpResponse[GetActiveUsersCountStatsResponseContent]:
28 """
29 Retrieve the number of active users that logged in during the last 30 days.
30
31 Parameters
32 ----------
33 request_options : typing.Optional[RequestOptions]
34 Request-specific configuration.
35
36 Returns
37 -------
38 HttpResponse[GetActiveUsersCountStatsResponseContent]
39 Number of active users successfully retrieved.
40 """
41 _response = self._client_wrapper.httpx_client.request(
42 "stats/active-users",
43 method="GET",
44 request_options=request_options,
45 )
46 try:
47 if 200 <= _response.status_code < 300:
48 _data = typing.cast(
49 GetActiveUsersCountStatsResponseContent,
50 parse_obj_as(
51 type_=GetActiveUsersCountStatsResponseContent, # type: ignore
52 object_=_response.json(),
53 ),
54 )
55 return HttpResponse(response=_response, data=_data)
56 if _response.status_code == 401:
57 raise UnauthorizedError(
58 headers=dict(_response.headers),
59 body=typing.cast(
60 typing.Any,
61 parse_obj_as(
62 type_=typing.Any, # type: ignore
63 object_=_response.json(),
64 ),
65 ),
66 )
67 if _response.status_code == 403:
68 raise ForbiddenError(
69 headers=dict(_response.headers),
70 body=typing.cast(
71 typing.Any,
72 parse_obj_as(
73 type_=typing.Any, # type: ignore
74 object_=_response.json(),
75 ),
76 ),
77 )
78 if _response.status_code == 429:
79 raise TooManyRequestsError(
80 headers=dict(_response.headers),
81 body=typing.cast(
82 typing.Any,
83 parse_obj_as(
84 type_=typing.Any, # type: ignore
85 object_=_response.json(),
86 ),
87 ),
88 )
89 _response_json = _response.json()
90 except JSONDecodeError:
91 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
92 except ValidationError as e:
93 raise ParsingError(
94 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
95 )
96 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
97
98 def get_daily(
99 self,
100 *,
101 from_: typing.Optional[str] = None,
102 to: typing.Optional[str] = None,
103 request_options: typing.Optional[RequestOptions] = None,
104 ) -> HttpResponse[typing.List[DailyStats]]:
105 """
106 Retrieve the number of logins, signups and breached-password detections (subscription required) that occurred each day within a specified date range.
107
108 Parameters
109 ----------
110 from_ : typing.Optional[str]
111 Optional first day of the date range (inclusive) in YYYYMMDD format.
112
113 to : typing.Optional[str]
114 Optional last day of the date range (inclusive) in YYYYMMDD format.
115
116 request_options : typing.Optional[RequestOptions]
117 Request-specific configuration.
118
119 Returns
120 -------
121 HttpResponse[typing.List[DailyStats]]
122 Daily stats successfully retrieved.
123 """
124 _response = self._client_wrapper.httpx_client.request(
125 "stats/daily",
126 method="GET",
127 params={
128 "from": from_,
129 "to": to,
130 },
131 request_options=request_options,
132 )
133 try:
134 if 200 <= _response.status_code < 300:
135 _data = typing.cast(
136 typing.List[DailyStats],
137 parse_obj_as(
138 type_=typing.List[DailyStats], # type: ignore
139 object_=_response.json(),
140 ),
141 )
142 return HttpResponse(response=_response, data=_data)
143 if _response.status_code == 400:
144 raise BadRequestError(
145 headers=dict(_response.headers),
146 body=typing.cast(
147 typing.Any,
148 parse_obj_as(
149 type_=typing.Any, # type: ignore
150 object_=_response.json(),
151 ),
152 ),
153 )
154 if _response.status_code == 401:
155 raise UnauthorizedError(
156 headers=dict(_response.headers),
157 body=typing.cast(
158 typing.Any,
159 parse_obj_as(
160 type_=typing.Any, # type: ignore
161 object_=_response.json(),
162 ),
163 ),
164 )
165 if _response.status_code == 403:
166 raise ForbiddenError(
167 headers=dict(_response.headers),
168 body=typing.cast(
169 typing.Any,
170 parse_obj_as(
171 type_=typing.Any, # type: ignore
172 object_=_response.json(),
173 ),
174 ),
175 )
176 if _response.status_code == 429:
177 raise TooManyRequestsError(
178 headers=dict(_response.headers),
179 body=typing.cast(
180 typing.Any,
181 parse_obj_as(
182 type_=typing.Any, # type: ignore
183 object_=_response.json(),
184 ),
185 ),
186 )
187 _response_json = _response.json()
188 except JSONDecodeError:
189 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
190 except ValidationError as e:
191 raise ParsingError(
192 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
193 )
194 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
195
196
197 class AsyncRawStatsClient:
198 def __init__(self, *, client_wrapper: AsyncClientWrapper):
199 self._client_wrapper = client_wrapper
200
201 async def get_active_users_count(
202 self, *, request_options: typing.Optional[RequestOptions] = None
203 ) -> AsyncHttpResponse[GetActiveUsersCountStatsResponseContent]:
204 """
205 Retrieve the number of active users that logged in during the last 30 days.
206
207 Parameters
208 ----------
209 request_options : typing.Optional[RequestOptions]
210 Request-specific configuration.
211
212 Returns
213 -------
214 AsyncHttpResponse[GetActiveUsersCountStatsResponseContent]
215 Number of active users successfully retrieved.
216 """
217 _response = await self._client_wrapper.httpx_client.request(
218 "stats/active-users",
219 method="GET",
220 request_options=request_options,
221 )
222 try:
223 if 200 <= _response.status_code < 300:
224 _data = typing.cast(
225 GetActiveUsersCountStatsResponseContent,
226 parse_obj_as(
227 type_=GetActiveUsersCountStatsResponseContent, # type: ignore
228 object_=_response.json(),
229 ),
230 )
231 return AsyncHttpResponse(response=_response, data=_data)
232 if _response.status_code == 401:
233 raise UnauthorizedError(
234 headers=dict(_response.headers),
235 body=typing.cast(
236 typing.Any,
237 parse_obj_as(
238 type_=typing.Any, # type: ignore
239 object_=_response.json(),
240 ),
241 ),
242 )
243 if _response.status_code == 403:
244 raise ForbiddenError(
245 headers=dict(_response.headers),
246 body=typing.cast(
247 typing.Any,
248 parse_obj_as(
249 type_=typing.Any, # type: ignore
250 object_=_response.json(),
251 ),
252 ),
253 )
254 if _response.status_code == 429:
255 raise TooManyRequestsError(
256 headers=dict(_response.headers),
257 body=typing.cast(
258 typing.Any,
259 parse_obj_as(
260 type_=typing.Any, # type: ignore
261 object_=_response.json(),
262 ),
263 ),
264 )
265 _response_json = _response.json()
266 except JSONDecodeError:
267 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
268 except ValidationError as e:
269 raise ParsingError(
270 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
271 )
272 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
273
274 async def get_daily(
275 self,
276 *,
277 from_: typing.Optional[str] = None,
278 to: typing.Optional[str] = None,
279 request_options: typing.Optional[RequestOptions] = None,
280 ) -> AsyncHttpResponse[typing.List[DailyStats]]:
281 """
282 Retrieve the number of logins, signups and breached-password detections (subscription required) that occurred each day within a specified date range.
283
284 Parameters
285 ----------
286 from_ : typing.Optional[str]
287 Optional first day of the date range (inclusive) in YYYYMMDD format.
288
289 to : typing.Optional[str]
290 Optional last day of the date range (inclusive) in YYYYMMDD format.
291
292 request_options : typing.Optional[RequestOptions]
293 Request-specific configuration.
294
295 Returns
296 -------
297 AsyncHttpResponse[typing.List[DailyStats]]
298 Daily stats successfully retrieved.
299 """
300 _response = await self._client_wrapper.httpx_client.request(
301 "stats/daily",
302 method="GET",
303 params={
304 "from": from_,
305 "to": to,
306 },
307 request_options=request_options,
308 )
309 try:
310 if 200 <= _response.status_code < 300:
311 _data = typing.cast(
312 typing.List[DailyStats],
313 parse_obj_as(
314 type_=typing.List[DailyStats], # type: ignore
315 object_=_response.json(),
316 ),
317 )
318 return AsyncHttpResponse(response=_response, data=_data)
319 if _response.status_code == 400:
320 raise BadRequestError(
321 headers=dict(_response.headers),
322 body=typing.cast(
323 typing.Any,
324 parse_obj_as(
325 type_=typing.Any, # type: ignore
326 object_=_response.json(),
327 ),
328 ),
329 )
330 if _response.status_code == 401:
331 raise UnauthorizedError(
332 headers=dict(_response.headers),
333 body=typing.cast(
334 typing.Any,
335 parse_obj_as(
336 type_=typing.Any, # type: ignore
337 object_=_response.json(),
338 ),
339 ),
340 )
341 if _response.status_code == 403:
342 raise ForbiddenError(
343 headers=dict(_response.headers),
344 body=typing.cast(
345 typing.Any,
346 parse_obj_as(
347 type_=typing.Any, # type: ignore
348 object_=_response.json(),
349 ),
350 ),
351 )
352 if _response.status_code == 429:
353 raise TooManyRequestsError(
354 headers=dict(_response.headers),
355 body=typing.cast(
356 typing.Any,
357 parse_obj_as(
358 type_=typing.Any, # type: ignore
359 object_=_response.json(),
360 ),
361 ),
362 )
363 _response_json = _response.json()
364 except JSONDecodeError:
365 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
366 except ValidationError as e:
367 raise ParsingError(
368 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
369 )
370 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)