|
13 | 13 | from ..types.leaderboard_response_with_rankings import LeaderboardResponseWithRankings |
14 | 14 | from ..core.jsonable_encoder import jsonable_encoder |
15 | 15 | from ..errors.not_found_error import NotFoundError |
16 | | -from ..types.user_leaderboard_response import UserLeaderboardResponse |
17 | 16 | from ..core.client_wrapper import AsyncClientWrapper |
18 | 17 |
|
19 | 18 |
|
@@ -191,101 +190,6 @@ def get( |
191 | 190 | raise ApiError(status_code=_response.status_code, body=_response.text) |
192 | 191 | raise ApiError(status_code=_response.status_code, body=_response_json) |
193 | 192 |
|
194 | | - def users_leaderboards( |
195 | | - self, |
196 | | - user_id: str, |
197 | | - key: str, |
198 | | - *, |
199 | | - run: typing.Optional[str] = None, |
200 | | - request_options: typing.Optional[RequestOptions] = None, |
201 | | - ) -> UserLeaderboardResponse: |
202 | | - """ |
203 | | - Get a user's rank, value, and history for a specific leaderboard. |
204 | | -
|
205 | | - Parameters |
206 | | - ---------- |
207 | | - user_id : str |
208 | | - The user's ID in your database. |
209 | | -
|
210 | | - key : str |
211 | | - Unique key of the leaderboard as set when created. |
212 | | -
|
213 | | - run : typing.Optional[str] |
214 | | - Specific run date in YYYY-MM-DD format. If not provided, returns the current run. |
215 | | -
|
216 | | - request_options : typing.Optional[RequestOptions] |
217 | | - Request-specific configuration. |
218 | | -
|
219 | | - Returns |
220 | | - ------- |
221 | | - UserLeaderboardResponse |
222 | | - Successful operation |
223 | | -
|
224 | | - Examples |
225 | | - -------- |
226 | | - from trophy import TrophyApi |
227 | | -
|
228 | | - client = TrophyApi( |
229 | | - api_key="YOUR_API_KEY", |
230 | | - ) |
231 | | - client.leaderboards.users_leaderboards( |
232 | | - user_id="user-123", |
233 | | - key="weekly-words", |
234 | | - run="2025-01-15", |
235 | | - ) |
236 | | - """ |
237 | | - _response = self._client_wrapper.httpx_client.request( |
238 | | - f"users/{jsonable_encoder(user_id)}/leaderboards/{jsonable_encoder(key)}", |
239 | | - method="GET", |
240 | | - params={ |
241 | | - "run": run, |
242 | | - }, |
243 | | - request_options=request_options, |
244 | | - ) |
245 | | - try: |
246 | | - if 200 <= _response.status_code < 300: |
247 | | - return typing.cast( |
248 | | - UserLeaderboardResponse, |
249 | | - parse_obj_as( |
250 | | - type_=UserLeaderboardResponse, # type: ignore |
251 | | - object_=_response.json(), |
252 | | - ), |
253 | | - ) |
254 | | - if _response.status_code == 401: |
255 | | - raise UnauthorizedError( |
256 | | - typing.cast( |
257 | | - ErrorBody, |
258 | | - parse_obj_as( |
259 | | - type_=ErrorBody, # type: ignore |
260 | | - object_=_response.json(), |
261 | | - ), |
262 | | - ) |
263 | | - ) |
264 | | - if _response.status_code == 404: |
265 | | - raise NotFoundError( |
266 | | - typing.cast( |
267 | | - ErrorBody, |
268 | | - parse_obj_as( |
269 | | - type_=ErrorBody, # type: ignore |
270 | | - object_=_response.json(), |
271 | | - ), |
272 | | - ) |
273 | | - ) |
274 | | - if _response.status_code == 422: |
275 | | - raise UnprocessableEntityError( |
276 | | - typing.cast( |
277 | | - ErrorBody, |
278 | | - parse_obj_as( |
279 | | - type_=ErrorBody, # type: ignore |
280 | | - object_=_response.json(), |
281 | | - ), |
282 | | - ) |
283 | | - ) |
284 | | - _response_json = _response.json() |
285 | | - except JSONDecodeError: |
286 | | - raise ApiError(status_code=_response.status_code, body=_response.text) |
287 | | - raise ApiError(status_code=_response.status_code, body=_response_json) |
288 | | - |
289 | 193 |
|
290 | 194 | class AsyncLeaderboardsClient: |
291 | 195 | def __init__(self, *, client_wrapper: AsyncClientWrapper): |
@@ -476,106 +380,3 @@ async def main() -> None: |
476 | 380 | except JSONDecodeError: |
477 | 381 | raise ApiError(status_code=_response.status_code, body=_response.text) |
478 | 382 | raise ApiError(status_code=_response.status_code, body=_response_json) |
479 | | - |
480 | | - async def users_leaderboards( |
481 | | - self, |
482 | | - user_id: str, |
483 | | - key: str, |
484 | | - *, |
485 | | - run: typing.Optional[str] = None, |
486 | | - request_options: typing.Optional[RequestOptions] = None, |
487 | | - ) -> UserLeaderboardResponse: |
488 | | - """ |
489 | | - Get a user's rank, value, and history for a specific leaderboard. |
490 | | -
|
491 | | - Parameters |
492 | | - ---------- |
493 | | - user_id : str |
494 | | - The user's ID in your database. |
495 | | -
|
496 | | - key : str |
497 | | - Unique key of the leaderboard as set when created. |
498 | | -
|
499 | | - run : typing.Optional[str] |
500 | | - Specific run date in YYYY-MM-DD format. If not provided, returns the current run. |
501 | | -
|
502 | | - request_options : typing.Optional[RequestOptions] |
503 | | - Request-specific configuration. |
504 | | -
|
505 | | - Returns |
506 | | - ------- |
507 | | - UserLeaderboardResponse |
508 | | - Successful operation |
509 | | -
|
510 | | - Examples |
511 | | - -------- |
512 | | - import asyncio |
513 | | -
|
514 | | - from trophy import AsyncTrophyApi |
515 | | -
|
516 | | - client = AsyncTrophyApi( |
517 | | - api_key="YOUR_API_KEY", |
518 | | - ) |
519 | | -
|
520 | | -
|
521 | | - async def main() -> None: |
522 | | - await client.leaderboards.users_leaderboards( |
523 | | - user_id="user-123", |
524 | | - key="weekly-words", |
525 | | - run="2025-01-15", |
526 | | - ) |
527 | | -
|
528 | | -
|
529 | | - asyncio.run(main()) |
530 | | - """ |
531 | | - _response = await self._client_wrapper.httpx_client.request( |
532 | | - f"users/{jsonable_encoder(user_id)}/leaderboards/{jsonable_encoder(key)}", |
533 | | - method="GET", |
534 | | - params={ |
535 | | - "run": run, |
536 | | - }, |
537 | | - request_options=request_options, |
538 | | - ) |
539 | | - try: |
540 | | - if 200 <= _response.status_code < 300: |
541 | | - return typing.cast( |
542 | | - UserLeaderboardResponse, |
543 | | - parse_obj_as( |
544 | | - type_=UserLeaderboardResponse, # type: ignore |
545 | | - object_=_response.json(), |
546 | | - ), |
547 | | - ) |
548 | | - if _response.status_code == 401: |
549 | | - raise UnauthorizedError( |
550 | | - typing.cast( |
551 | | - ErrorBody, |
552 | | - parse_obj_as( |
553 | | - type_=ErrorBody, # type: ignore |
554 | | - object_=_response.json(), |
555 | | - ), |
556 | | - ) |
557 | | - ) |
558 | | - if _response.status_code == 404: |
559 | | - raise NotFoundError( |
560 | | - typing.cast( |
561 | | - ErrorBody, |
562 | | - parse_obj_as( |
563 | | - type_=ErrorBody, # type: ignore |
564 | | - object_=_response.json(), |
565 | | - ), |
566 | | - ) |
567 | | - ) |
568 | | - if _response.status_code == 422: |
569 | | - raise UnprocessableEntityError( |
570 | | - typing.cast( |
571 | | - ErrorBody, |
572 | | - parse_obj_as( |
573 | | - type_=ErrorBody, # type: ignore |
574 | | - object_=_response.json(), |
575 | | - ), |
576 | | - ) |
577 | | - ) |
578 | | - _response_json = _response.json() |
579 | | - except JSONDecodeError: |
580 | | - raise ApiError(status_code=_response.status_code, body=_response.text) |
581 | | - raise ApiError(status_code=_response.status_code, body=_response_json) |
0 commit comments