Skip to content

Commit cb3d5e5

Browse files
Automatically update Python SDK
1 parent d9f4e2a commit cb3d5e5

File tree

9 files changed

+262
-2
lines changed

9 files changed

+262
-2
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.18"
7+
version = "1.0.19"
88
description = "A Python library for the Trophy API"
99
license = {text = "MIT"}
1010
readme = "README.md"

trophy/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
PointsTriggerResponseUserAttributesItem,
2929
PointsTriggerType,
3030
StreakFrequency,
31+
StreakRankingUser,
3132
StreakResponse,
3233
StreakResponseStreakHistoryItem,
3334
UpdatedUser,
@@ -40,9 +41,10 @@
4041
UnauthorizedError,
4142
UnprocessableEntityError,
4243
)
43-
from . import achievements, metrics, points, users
44+
from . import achievements, metrics, points, streaks, users
4445
from .client import AsyncTrophyApi, TrophyApi
4546
from .environment import TrophyApiEnvironment
47+
from .streaks import StreaksRankingsRequestType
4648
from .users import (
4749
UsersMetricEventSummaryRequestAggregation,
4850
UsersMetricEventSummaryResponseItem,
@@ -81,8 +83,10 @@
8183
"PointsTriggerResponseUserAttributesItem",
8284
"PointsTriggerType",
8385
"StreakFrequency",
86+
"StreakRankingUser",
8487
"StreakResponse",
8588
"StreakResponseStreakHistoryItem",
89+
"StreaksRankingsRequestType",
8690
"TrophyApi",
8791
"TrophyApiEnvironment",
8892
"UnauthorizedError",
@@ -97,5 +101,6 @@
97101
"achievements",
98102
"metrics",
99103
"points",
104+
"streaks",
100105
"users",
101106
]

trophy/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
from .achievements.client import AchievementsClient
88
from .metrics.client import MetricsClient
99
from .users.client import UsersClient
10+
from .streaks.client import StreaksClient
1011
from .points.client import PointsClient
1112
from .core.client_wrapper import AsyncClientWrapper
1213
from .achievements.client import AsyncAchievementsClient
1314
from .metrics.client import AsyncMetricsClient
1415
from .users.client import AsyncUsersClient
16+
from .streaks.client import AsyncStreaksClient
1517
from .points.client import AsyncPointsClient
1618

1719

@@ -80,6 +82,7 @@ def __init__(
8082
self.achievements = AchievementsClient(client_wrapper=self._client_wrapper)
8183
self.metrics = MetricsClient(client_wrapper=self._client_wrapper)
8284
self.users = UsersClient(client_wrapper=self._client_wrapper)
85+
self.streaks = StreaksClient(client_wrapper=self._client_wrapper)
8386
self.points = PointsClient(client_wrapper=self._client_wrapper)
8487

8588

@@ -148,6 +151,7 @@ def __init__(
148151
self.achievements = AsyncAchievementsClient(client_wrapper=self._client_wrapper)
149152
self.metrics = AsyncMetricsClient(client_wrapper=self._client_wrapper)
150153
self.users = AsyncUsersClient(client_wrapper=self._client_wrapper)
154+
self.streaks = AsyncStreaksClient(client_wrapper=self._client_wrapper)
151155
self.points = AsyncPointsClient(client_wrapper=self._client_wrapper)
152156

153157

trophy/streaks/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+
3+
from .types import StreaksRankingsRequestType
4+
5+
__all__ = ["StreaksRankingsRequestType"]

trophy/streaks/client.py

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+
3+
from ..core.client_wrapper import SyncClientWrapper
4+
import typing
5+
from .types.streaks_rankings_request_type import StreaksRankingsRequestType
6+
from ..core.request_options import RequestOptions
7+
from ..types.streak_ranking_user import StreakRankingUser
8+
from ..core.pydantic_utilities import parse_obj_as
9+
from ..errors.unauthorized_error import UnauthorizedError
10+
from ..types.error_body import ErrorBody
11+
from ..errors.unprocessable_entity_error import UnprocessableEntityError
12+
from json.decoder import JSONDecodeError
13+
from ..core.api_error import ApiError
14+
from ..core.client_wrapper import AsyncClientWrapper
15+
16+
17+
class StreaksClient:
18+
def __init__(self, *, client_wrapper: SyncClientWrapper):
19+
self._client_wrapper = client_wrapper
20+
21+
def rankings(
22+
self,
23+
*,
24+
limit: typing.Optional[int] = None,
25+
type: typing.Optional[StreaksRankingsRequestType] = None,
26+
request_options: typing.Optional[RequestOptions] = None,
27+
) -> typing.List[StreakRankingUser]:
28+
"""
29+
Get the top users by streak length (active or longest).
30+
31+
Parameters
32+
----------
33+
limit : typing.Optional[int]
34+
Number of users to return. Must be between 1 and 100.
35+
36+
type : typing.Optional[StreaksRankingsRequestType]
37+
Whether to rank users by active streaks or longest streaks ever achieved.
38+
39+
request_options : typing.Optional[RequestOptions]
40+
Request-specific configuration.
41+
42+
Returns
43+
-------
44+
typing.List[StreakRankingUser]
45+
Successful operation
46+
47+
Examples
48+
--------
49+
from trophy import TrophyApi
50+
51+
client = TrophyApi(
52+
api_key="YOUR_API_KEY",
53+
)
54+
client.streaks.rankings()
55+
"""
56+
_response = self._client_wrapper.httpx_client.request(
57+
"streaks/rankings",
58+
method="GET",
59+
params={
60+
"limit": limit,
61+
"type": type,
62+
},
63+
request_options=request_options,
64+
)
65+
try:
66+
if 200 <= _response.status_code < 300:
67+
return typing.cast(
68+
typing.List[StreakRankingUser],
69+
parse_obj_as(
70+
type_=typing.List[StreakRankingUser], # type: ignore
71+
object_=_response.json(),
72+
),
73+
)
74+
if _response.status_code == 401:
75+
raise UnauthorizedError(
76+
typing.cast(
77+
ErrorBody,
78+
parse_obj_as(
79+
type_=ErrorBody, # type: ignore
80+
object_=_response.json(),
81+
),
82+
)
83+
)
84+
if _response.status_code == 422:
85+
raise UnprocessableEntityError(
86+
typing.cast(
87+
ErrorBody,
88+
parse_obj_as(
89+
type_=ErrorBody, # type: ignore
90+
object_=_response.json(),
91+
),
92+
)
93+
)
94+
_response_json = _response.json()
95+
except JSONDecodeError:
96+
raise ApiError(status_code=_response.status_code, body=_response.text)
97+
raise ApiError(status_code=_response.status_code, body=_response_json)
98+
99+
100+
class AsyncStreaksClient:
101+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
102+
self._client_wrapper = client_wrapper
103+
104+
async def rankings(
105+
self,
106+
*,
107+
limit: typing.Optional[int] = None,
108+
type: typing.Optional[StreaksRankingsRequestType] = None,
109+
request_options: typing.Optional[RequestOptions] = None,
110+
) -> typing.List[StreakRankingUser]:
111+
"""
112+
Get the top users by streak length (active or longest).
113+
114+
Parameters
115+
----------
116+
limit : typing.Optional[int]
117+
Number of users to return. Must be between 1 and 100.
118+
119+
type : typing.Optional[StreaksRankingsRequestType]
120+
Whether to rank users by active streaks or longest streaks ever achieved.
121+
122+
request_options : typing.Optional[RequestOptions]
123+
Request-specific configuration.
124+
125+
Returns
126+
-------
127+
typing.List[StreakRankingUser]
128+
Successful operation
129+
130+
Examples
131+
--------
132+
import asyncio
133+
134+
from trophy import AsyncTrophyApi
135+
136+
client = AsyncTrophyApi(
137+
api_key="YOUR_API_KEY",
138+
)
139+
140+
141+
async def main() -> None:
142+
await client.streaks.rankings()
143+
144+
145+
asyncio.run(main())
146+
"""
147+
_response = await self._client_wrapper.httpx_client.request(
148+
"streaks/rankings",
149+
method="GET",
150+
params={
151+
"limit": limit,
152+
"type": type,
153+
},
154+
request_options=request_options,
155+
)
156+
try:
157+
if 200 <= _response.status_code < 300:
158+
return typing.cast(
159+
typing.List[StreakRankingUser],
160+
parse_obj_as(
161+
type_=typing.List[StreakRankingUser], # type: ignore
162+
object_=_response.json(),
163+
),
164+
)
165+
if _response.status_code == 401:
166+
raise UnauthorizedError(
167+
typing.cast(
168+
ErrorBody,
169+
parse_obj_as(
170+
type_=ErrorBody, # type: ignore
171+
object_=_response.json(),
172+
),
173+
)
174+
)
175+
if _response.status_code == 422:
176+
raise UnprocessableEntityError(
177+
typing.cast(
178+
ErrorBody,
179+
parse_obj_as(
180+
type_=ErrorBody, # type: ignore
181+
object_=_response.json(),
182+
),
183+
)
184+
)
185+
_response_json = _response.json()
186+
except JSONDecodeError:
187+
raise ApiError(status_code=_response.status_code, body=_response.text)
188+
raise ApiError(status_code=_response.status_code, body=_response_json)

trophy/streaks/types/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+
3+
from .streaks_rankings_request_type import StreaksRankingsRequestType
4+
5+
__all__ = ["StreaksRankingsRequestType"]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+
3+
import typing
4+
5+
StreaksRankingsRequestType = typing.Union[
6+
typing.Literal["active", "longest"], typing.Any
7+
]

trophy/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
)
3434
from .points_trigger_type import PointsTriggerType
3535
from .streak_frequency import StreakFrequency
36+
from .streak_ranking_user import StreakRankingUser
3637
from .streak_response import StreakResponse
3738
from .streak_response_streak_history_item import StreakResponseStreakHistoryItem
3839
from .updated_user import UpdatedUser
@@ -67,6 +68,7 @@
6768
"PointsTriggerResponseUserAttributesItem",
6869
"PointsTriggerType",
6970
"StreakFrequency",
71+
"StreakRankingUser",
7072
"StreakResponse",
7173
"StreakResponseStreakHistoryItem",
7274
"UpdatedUser",
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 StreakRankingUser(UniversalBaseModel):
12+
"""
13+
A user with their streak length in the rankings.
14+
"""
15+
16+
user_id: typing_extensions.Annotated[str, FieldMetadata(alias="userId")] = (
17+
pydantic.Field()
18+
)
19+
"""
20+
The ID of the user.
21+
"""
22+
23+
name: typing.Optional[str] = pydantic.Field(default=None)
24+
"""
25+
The name of the user. May be null if no name is set.
26+
"""
27+
28+
streak_length: typing_extensions.Annotated[
29+
int, FieldMetadata(alias="streakLength")
30+
] = pydantic.Field()
31+
"""
32+
The user's streak length (active or longest depending on query parameter).
33+
"""
34+
35+
if IS_PYDANTIC_V2:
36+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
37+
extra="allow", frozen=True
38+
) # type: ignore # Pydantic v2
39+
else:
40+
41+
class Config:
42+
frozen = True
43+
smart_union = True
44+
extra = pydantic.Extra.allow

0 commit comments

Comments
 (0)