Skip to content

Commit 12d4935

Browse files
Automatically update Python SDK
1 parent dc298ce commit 12d4935

18 files changed

Lines changed: 514 additions & 83 deletions

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

trophy/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
AchievementResponse,
66
AchievementResponseTrigger,
77
AchievementWithStatsResponse,
8+
AchievementWithStatsResponseEventAttribute,
9+
AchievementWithStatsResponseUserAttributesItem,
810
BaseStreakResponse,
911
CompletedAchievementResponse,
1012
ErrorBody,
@@ -17,10 +19,13 @@
1719
PointsAward,
1820
PointsRange,
1921
PointsSummaryResponse,
22+
PointsSystemResponse,
2023
PointsTrigger,
2124
PointsTriggerResponse,
25+
PointsTriggerResponseEventAttribute,
2226
PointsTriggerResponseStatus,
2327
PointsTriggerResponseType,
28+
PointsTriggerResponseUserAttributesItem,
2429
PointsTriggerType,
2530
StreakFrequency,
2631
StreakResponse,
@@ -50,6 +55,8 @@
5055
"AchievementResponse",
5156
"AchievementResponseTrigger",
5257
"AchievementWithStatsResponse",
58+
"AchievementWithStatsResponseEventAttribute",
59+
"AchievementWithStatsResponseUserAttributesItem",
5360
"AsyncTrophyApi",
5461
"BadRequestError",
5562
"BaseStreakResponse",
@@ -65,10 +72,13 @@
6572
"PointsAward",
6673
"PointsRange",
6774
"PointsSummaryResponse",
75+
"PointsSystemResponse",
6876
"PointsTrigger",
6977
"PointsTriggerResponse",
78+
"PointsTriggerResponseEventAttribute",
7079
"PointsTriggerResponseStatus",
7180
"PointsTriggerResponseType",
81+
"PointsTriggerResponseUserAttributesItem",
7282
"PointsTriggerType",
7383
"StreakFrequency",
7484
"StreakResponse",

trophy/achievements/client.py

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
from ..core.pydantic_utilities import parse_obj_as
88
from ..errors.unauthorized_error import UnauthorizedError
99
from ..types.error_body import ErrorBody
10-
from ..errors.not_found_error import NotFoundError
1110
from ..errors.unprocessable_entity_error import UnprocessableEntityError
1211
from json.decoder import JSONDecodeError
1312
from ..core.api_error import ApiError
14-
from ..types.updated_user import UpdatedUser
13+
from ..types.upserted_user import UpsertedUser
1514
from ..types.achievement_completion_response import AchievementCompletionResponse
1615
from ..core.jsonable_encoder import jsonable_encoder
1716
from ..core.serialization import convert_and_respect_annotation_metadata
17+
from ..errors.not_found_error import NotFoundError
1818
from ..core.client_wrapper import AsyncClientWrapper
1919

2020
# this is used as the default value for optional parameters
@@ -74,16 +74,6 @@ def all_(
7474
),
7575
)
7676
)
77-
if _response.status_code == 404:
78-
raise NotFoundError(
79-
typing.cast(
80-
ErrorBody,
81-
parse_obj_as(
82-
type_=ErrorBody, # type: ignore
83-
object_=_response.json(),
84-
),
85-
)
86-
)
8777
if _response.status_code == 422:
8878
raise UnprocessableEntityError(
8979
typing.cast(
@@ -103,7 +93,7 @@ def complete(
10393
self,
10494
key: str,
10595
*,
106-
user: UpdatedUser,
96+
user: UpsertedUser,
10797
request_options: typing.Optional[RequestOptions] = None,
10898
) -> AchievementCompletionResponse:
10999
"""
@@ -114,7 +104,7 @@ def complete(
114104
key : str
115105
Unique reference of the achievement as set when created.
116106
117-
user : UpdatedUser
107+
user : UpsertedUser
118108
The user that completed the achievement.
119109
120110
request_options : typing.Optional[RequestOptions]
@@ -127,16 +117,17 @@ def complete(
127117
128118
Examples
129119
--------
130-
from trophy import TrophyApi, UpdatedUser
120+
from trophy import TrophyApi, UpsertedUser
131121
132122
client = TrophyApi(
133123
api_key="YOUR_API_KEY",
134124
)
135125
client.achievements.complete(
136126
key="finish-onboarding",
137-
user=UpdatedUser(
127+
user=UpsertedUser(
138128
email="user@example.com",
139129
tz="Europe/London",
130+
id="user-id",
140131
),
141132
)
142133
"""
@@ -145,7 +136,7 @@ def complete(
145136
method="POST",
146137
json={
147138
"user": convert_and_respect_annotation_metadata(
148-
object_=user, annotation=UpdatedUser, direction="write"
139+
object_=user, annotation=UpsertedUser, direction="write"
149140
),
150141
},
151142
headers={
@@ -260,16 +251,6 @@ async def main() -> None:
260251
),
261252
)
262253
)
263-
if _response.status_code == 404:
264-
raise NotFoundError(
265-
typing.cast(
266-
ErrorBody,
267-
parse_obj_as(
268-
type_=ErrorBody, # type: ignore
269-
object_=_response.json(),
270-
),
271-
)
272-
)
273254
if _response.status_code == 422:
274255
raise UnprocessableEntityError(
275256
typing.cast(
@@ -289,7 +270,7 @@ async def complete(
289270
self,
290271
key: str,
291272
*,
292-
user: UpdatedUser,
273+
user: UpsertedUser,
293274
request_options: typing.Optional[RequestOptions] = None,
294275
) -> AchievementCompletionResponse:
295276
"""
@@ -300,7 +281,7 @@ async def complete(
300281
key : str
301282
Unique reference of the achievement as set when created.
302283
303-
user : UpdatedUser
284+
user : UpsertedUser
304285
The user that completed the achievement.
305286
306287
request_options : typing.Optional[RequestOptions]
@@ -315,7 +296,7 @@ async def complete(
315296
--------
316297
import asyncio
317298
318-
from trophy import AsyncTrophyApi, UpdatedUser
299+
from trophy import AsyncTrophyApi, UpsertedUser
319300
320301
client = AsyncTrophyApi(
321302
api_key="YOUR_API_KEY",
@@ -325,9 +306,10 @@ async def complete(
325306
async def main() -> None:
326307
await client.achievements.complete(
327308
key="finish-onboarding",
328-
user=UpdatedUser(
309+
user=UpsertedUser(
329310
email="user@example.com",
330311
tz="Europe/London",
312+
id="user-id",
331313
),
332314
)
333315
@@ -339,7 +321,7 @@ async def main() -> None:
339321
method="POST",
340322
json={
341323
"user": convert_and_respect_annotation_metadata(
342-
object_=user, annotation=UpdatedUser, direction="write"
324+
object_=user, annotation=UpsertedUser, direction="write"
343325
),
344326
},
345327
headers={

trophy/metrics/client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def event(
3030
*,
3131
user: UpsertedUser,
3232
value: float,
33+
attributes: typing.Optional[typing.Dict[str, str]] = OMIT,
3334
request_options: typing.Optional[RequestOptions] = None,
3435
) -> EventResponse:
3536
"""
@@ -46,6 +47,9 @@ def event(
4647
value : float
4748
The value to add to the user's current total for the given metric.
4849
50+
attributes : typing.Optional[typing.Dict[str, str]]
51+
Event attributes as key-value pairs. Keys must match existing event attributes set up in the Trophy dashboard.
52+
4953
request_options : typing.Optional[RequestOptions]
5054
Request-specific configuration.
5155
@@ -66,9 +70,11 @@ def event(
6670
user=UpsertedUser(
6771
email="user@example.com",
6872
tz="Europe/London",
73+
attributes={"department": "engineering", "role": "developer"},
6974
id="18",
7075
),
7176
value=750.0,
77+
attributes={"category": "writing", "source": "mobile-app"},
7278
)
7379
"""
7480
_response = self._client_wrapper.httpx_client.request(
@@ -79,6 +85,7 @@ def event(
7985
object_=user, annotation=UpsertedUser, direction="write"
8086
),
8187
"value": value,
88+
"attributes": attributes,
8289
},
8390
headers={
8491
"content-type": "application/json",
@@ -141,6 +148,7 @@ async def event(
141148
*,
142149
user: UpsertedUser,
143150
value: float,
151+
attributes: typing.Optional[typing.Dict[str, str]] = OMIT,
144152
request_options: typing.Optional[RequestOptions] = None,
145153
) -> EventResponse:
146154
"""
@@ -157,6 +165,9 @@ async def event(
157165
value : float
158166
The value to add to the user's current total for the given metric.
159167
168+
attributes : typing.Optional[typing.Dict[str, str]]
169+
Event attributes as key-value pairs. Keys must match existing event attributes set up in the Trophy dashboard.
170+
160171
request_options : typing.Optional[RequestOptions]
161172
Request-specific configuration.
162173
@@ -182,9 +193,11 @@ async def main() -> None:
182193
user=UpsertedUser(
183194
email="user@example.com",
184195
tz="Europe/London",
196+
attributes={"department": "engineering", "role": "developer"},
185197
id="18",
186198
),
187199
value=750.0,
200+
attributes={"category": "writing", "source": "mobile-app"},
188201
)
189202
190203
@@ -198,6 +211,7 @@ async def main() -> None:
198211
object_=user, annotation=UpsertedUser, direction="write"
199212
),
200213
"value": value,
214+
"attributes": attributes,
201215
},
202216
headers={
203217
"content-type": "application/json",

0 commit comments

Comments
 (0)