Skip to content

Commit 7468180

Browse files
Automatically update Python SDK
1 parent efe2727 commit 7468180

File tree

6 files changed

+212
-3
lines changed

6 files changed

+212
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "trophy"
7-
version = "1.0.20"
7+
version = "1.0.21"
88
description = "A Python library for the Trophy API"
99
license = {text = "MIT"}
1010
readme = "README.md"

trophy/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
AchievementWithStatsResponseEventAttribute,
99
AchievementWithStatsResponseUserAttributesItem,
1010
BaseStreakResponse,
11+
BulkStreakResponse,
12+
BulkStreakResponseItem,
1113
CompletedAchievementResponse,
1214
ErrorBody,
1315
EventResponse,
@@ -62,6 +64,8 @@
6264
"AsyncTrophyApi",
6365
"BadRequestError",
6466
"BaseStreakResponse",
67+
"BulkStreakResponse",
68+
"BulkStreakResponseItem",
6569
"CompletedAchievementResponse",
6670
"ErrorBody",
6771
"EventResponse",

trophy/streaks/client.py

Lines changed: 157 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,96 @@
22

33
from ..core.client_wrapper import SyncClientWrapper
44
import typing
5-
from .types.streaks_rankings_request_type import StreaksRankingsRequestType
65
from ..core.request_options import RequestOptions
7-
from ..types.streak_ranking_user import StreakRankingUser
6+
from ..types.bulk_streak_response import BulkStreakResponse
87
from ..core.pydantic_utilities import parse_obj_as
98
from ..errors.unauthorized_error import UnauthorizedError
109
from ..types.error_body import ErrorBody
1110
from ..errors.unprocessable_entity_error import UnprocessableEntityError
1211
from json.decoder import JSONDecodeError
1312
from ..core.api_error import ApiError
13+
from .types.streaks_rankings_request_type import StreaksRankingsRequestType
14+
from ..types.streak_ranking_user import StreakRankingUser
1415
from ..core.client_wrapper import AsyncClientWrapper
1516

1617

1718
class StreaksClient:
1819
def __init__(self, *, client_wrapper: SyncClientWrapper):
1920
self._client_wrapper = client_wrapper
2021

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+
2195
def rankings(
2296
self,
2397
*,
@@ -101,6 +175,87 @@ class AsyncStreaksClient:
101175
def __init__(self, *, client_wrapper: AsyncClientWrapper):
102176
self._client_wrapper = client_wrapper
103177

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+
104259
async def rankings(
105260
self,
106261
*,

trophy/types/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
AchievementWithStatsResponseUserAttributesItem,
1212
)
1313
from .base_streak_response import BaseStreakResponse
14+
from .bulk_streak_response import BulkStreakResponse
15+
from .bulk_streak_response_item import BulkStreakResponseItem
1416
from .completed_achievement_response import CompletedAchievementResponse
1517
from .error_body import ErrorBody
1618
from .event_response import EventResponse
@@ -48,6 +50,8 @@
4850
"AchievementWithStatsResponseEventAttribute",
4951
"AchievementWithStatsResponseUserAttributesItem",
5052
"BaseStreakResponse",
53+
"BulkStreakResponse",
54+
"BulkStreakResponseItem",
5155
"CompletedAchievementResponse",
5256
"ErrorBody",
5357
"EventResponse",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+
3+
import typing
4+
from .bulk_streak_response_item import BulkStreakResponseItem
5+
6+
BulkStreakResponse = typing.List[BulkStreakResponseItem]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+
3+
from ..core.pydantic_utilities import UniversalBaseModel
4+
import typing_extensions
5+
from ..core.serialization import FieldMetadata
6+
import pydantic
7+
import typing
8+
from ..core.pydantic_utilities import IS_PYDANTIC_V2
9+
10+
11+
class BulkStreakResponseItem(UniversalBaseModel):
12+
user_id: typing_extensions.Annotated[str, FieldMetadata(alias="userId")] = (
13+
pydantic.Field()
14+
)
15+
"""
16+
The ID of the user.
17+
"""
18+
19+
streak_length: typing_extensions.Annotated[
20+
int, FieldMetadata(alias="streakLength")
21+
] = pydantic.Field()
22+
"""
23+
The length of the user's streak.
24+
"""
25+
26+
extended: typing.Optional[str] = pydantic.Field(default=None)
27+
"""
28+
The timestamp the streak was extended, as a string.
29+
"""
30+
31+
if IS_PYDANTIC_V2:
32+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
33+
extra="allow", frozen=True
34+
) # type: ignore # Pydantic v2
35+
else:
36+
37+
class Config:
38+
frozen = True
39+
smart_union = True
40+
extra = pydantic.Extra.allow

0 commit comments

Comments
 (0)