|
2 | 2 |
|
3 | 3 | from ..core.client_wrapper import SyncClientWrapper |
4 | 4 | import typing |
5 | | -from .types.streaks_rankings_request_type import StreaksRankingsRequestType |
6 | 5 | from ..core.request_options import RequestOptions |
7 | | -from ..types.streak_ranking_user import StreakRankingUser |
| 6 | +from ..types.bulk_streak_response import BulkStreakResponse |
8 | 7 | from ..core.pydantic_utilities import parse_obj_as |
9 | 8 | from ..errors.unauthorized_error import UnauthorizedError |
10 | 9 | from ..types.error_body import ErrorBody |
11 | 10 | from ..errors.unprocessable_entity_error import UnprocessableEntityError |
12 | 11 | from json.decoder import JSONDecodeError |
13 | 12 | from ..core.api_error import ApiError |
| 13 | +from .types.streaks_rankings_request_type import StreaksRankingsRequestType |
| 14 | +from ..types.streak_ranking_user import StreakRankingUser |
14 | 15 | from ..core.client_wrapper import AsyncClientWrapper |
15 | 16 |
|
16 | 17 |
|
17 | 18 | class StreaksClient: |
18 | 19 | def __init__(self, *, client_wrapper: SyncClientWrapper): |
19 | 20 | self._client_wrapper = client_wrapper |
20 | 21 |
|
| 22 | + def list( |
| 23 | + self, |
| 24 | + *, |
| 25 | + user_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, |
| 26 | + request_options: typing.Optional[RequestOptions] = None, |
| 27 | + ) -> BulkStreakResponse: |
| 28 | + """ |
| 29 | + Get the streak lengths of a list of users, ranked by streak length from longest to shortest. |
| 30 | +
|
| 31 | + Parameters |
| 32 | + ---------- |
| 33 | + user_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]] |
| 34 | + A list of up to 100 user IDs. |
| 35 | +
|
| 36 | + request_options : typing.Optional[RequestOptions] |
| 37 | + Request-specific configuration. |
| 38 | +
|
| 39 | + Returns |
| 40 | + ------- |
| 41 | + BulkStreakResponse |
| 42 | + Successful operation |
| 43 | +
|
| 44 | + Examples |
| 45 | + -------- |
| 46 | + from trophy import TrophyApi |
| 47 | +
|
| 48 | + client = TrophyApi( |
| 49 | + api_key="YOUR_API_KEY", |
| 50 | + ) |
| 51 | + client.streaks.list() |
| 52 | + """ |
| 53 | + _response = self._client_wrapper.httpx_client.request( |
| 54 | + "streaks", |
| 55 | + method="GET", |
| 56 | + params={ |
| 57 | + "userIds": user_ids, |
| 58 | + }, |
| 59 | + request_options=request_options, |
| 60 | + ) |
| 61 | + try: |
| 62 | + if 200 <= _response.status_code < 300: |
| 63 | + return typing.cast( |
| 64 | + BulkStreakResponse, |
| 65 | + parse_obj_as( |
| 66 | + type_=BulkStreakResponse, # type: ignore |
| 67 | + object_=_response.json(), |
| 68 | + ), |
| 69 | + ) |
| 70 | + if _response.status_code == 401: |
| 71 | + raise UnauthorizedError( |
| 72 | + typing.cast( |
| 73 | + ErrorBody, |
| 74 | + parse_obj_as( |
| 75 | + type_=ErrorBody, # type: ignore |
| 76 | + object_=_response.json(), |
| 77 | + ), |
| 78 | + ) |
| 79 | + ) |
| 80 | + if _response.status_code == 422: |
| 81 | + raise UnprocessableEntityError( |
| 82 | + typing.cast( |
| 83 | + ErrorBody, |
| 84 | + parse_obj_as( |
| 85 | + type_=ErrorBody, # type: ignore |
| 86 | + object_=_response.json(), |
| 87 | + ), |
| 88 | + ) |
| 89 | + ) |
| 90 | + _response_json = _response.json() |
| 91 | + except JSONDecodeError: |
| 92 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 93 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
| 94 | + |
21 | 95 | def rankings( |
22 | 96 | self, |
23 | 97 | *, |
@@ -101,6 +175,87 @@ class AsyncStreaksClient: |
101 | 175 | def __init__(self, *, client_wrapper: AsyncClientWrapper): |
102 | 176 | self._client_wrapper = client_wrapper |
103 | 177 |
|
| 178 | + async def list( |
| 179 | + self, |
| 180 | + *, |
| 181 | + user_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, |
| 182 | + request_options: typing.Optional[RequestOptions] = None, |
| 183 | + ) -> BulkStreakResponse: |
| 184 | + """ |
| 185 | + Get the streak lengths of a list of users, ranked by streak length from longest to shortest. |
| 186 | +
|
| 187 | + Parameters |
| 188 | + ---------- |
| 189 | + user_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]] |
| 190 | + A list of up to 100 user IDs. |
| 191 | +
|
| 192 | + request_options : typing.Optional[RequestOptions] |
| 193 | + Request-specific configuration. |
| 194 | +
|
| 195 | + Returns |
| 196 | + ------- |
| 197 | + BulkStreakResponse |
| 198 | + Successful operation |
| 199 | +
|
| 200 | + Examples |
| 201 | + -------- |
| 202 | + import asyncio |
| 203 | +
|
| 204 | + from trophy import AsyncTrophyApi |
| 205 | +
|
| 206 | + client = AsyncTrophyApi( |
| 207 | + api_key="YOUR_API_KEY", |
| 208 | + ) |
| 209 | +
|
| 210 | +
|
| 211 | + async def main() -> None: |
| 212 | + await client.streaks.list() |
| 213 | +
|
| 214 | +
|
| 215 | + asyncio.run(main()) |
| 216 | + """ |
| 217 | + _response = await self._client_wrapper.httpx_client.request( |
| 218 | + "streaks", |
| 219 | + method="GET", |
| 220 | + params={ |
| 221 | + "userIds": user_ids, |
| 222 | + }, |
| 223 | + request_options=request_options, |
| 224 | + ) |
| 225 | + try: |
| 226 | + if 200 <= _response.status_code < 300: |
| 227 | + return typing.cast( |
| 228 | + BulkStreakResponse, |
| 229 | + parse_obj_as( |
| 230 | + type_=BulkStreakResponse, # type: ignore |
| 231 | + object_=_response.json(), |
| 232 | + ), |
| 233 | + ) |
| 234 | + if _response.status_code == 401: |
| 235 | + raise UnauthorizedError( |
| 236 | + typing.cast( |
| 237 | + ErrorBody, |
| 238 | + parse_obj_as( |
| 239 | + type_=ErrorBody, # type: ignore |
| 240 | + object_=_response.json(), |
| 241 | + ), |
| 242 | + ) |
| 243 | + ) |
| 244 | + if _response.status_code == 422: |
| 245 | + raise UnprocessableEntityError( |
| 246 | + typing.cast( |
| 247 | + ErrorBody, |
| 248 | + parse_obj_as( |
| 249 | + type_=ErrorBody, # type: ignore |
| 250 | + object_=_response.json(), |
| 251 | + ), |
| 252 | + ) |
| 253 | + ) |
| 254 | + _response_json = _response.json() |
| 255 | + except JSONDecodeError: |
| 256 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 257 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
| 258 | + |
104 | 259 | async def rankings( |
105 | 260 | self, |
106 | 261 | *, |
|
0 commit comments