22
33import typing
44from ..core .client_wrapper import SyncClientWrapper
5- from ..types .upserted_user import UpsertedUser
65from ..core .request_options import RequestOptions
7- from ..types .achievement_completion_response import AchievementCompletionResponse
8- from ..core .jsonable_encoder import jsonable_encoder
9- from ..core .serialization import convert_and_respect_annotation_metadata
6+ from ..types .achievement_with_stats_response import AchievementWithStatsResponse
107from ..core .pydantic_utilities import parse_obj_as
118from ..errors .unauthorized_error import UnauthorizedError
129from ..types .error_body import ErrorBody
1310from ..errors .not_found_error import NotFoundError
1411from ..errors .unprocessable_entity_error import UnprocessableEntityError
1512from json .decoder import JSONDecodeError
1613from ..core .api_error import ApiError
14+ from ..types .updated_user import UpdatedUser
15+ from ..types .achievement_completion_response import AchievementCompletionResponse
16+ from ..core .jsonable_encoder import jsonable_encoder
17+ from ..core .serialization import convert_and_respect_annotation_metadata
1718from ..core .client_wrapper import AsyncClientWrapper
1819
1920# this is used as the default value for optional parameters
@@ -24,11 +25,85 @@ class AchievementsClient:
2425 def __init__ (self , * , client_wrapper : SyncClientWrapper ):
2526 self ._client_wrapper = client_wrapper
2627
28+ def all_ (
29+ self , * , request_options : typing .Optional [RequestOptions ] = None
30+ ) -> typing .List [AchievementWithStatsResponse ]:
31+ """
32+ Get all achievements and their completion stats.
33+
34+ Parameters
35+ ----------
36+ request_options : typing.Optional[RequestOptions]
37+ Request-specific configuration.
38+
39+ Returns
40+ -------
41+ typing.List[AchievementWithStatsResponse]
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.achievements.all_()
52+ """
53+ _response = self ._client_wrapper .httpx_client .request (
54+ "achievements" ,
55+ method = "GET" ,
56+ request_options = request_options ,
57+ )
58+ try :
59+ if 200 <= _response .status_code < 300 :
60+ return typing .cast (
61+ typing .List [AchievementWithStatsResponse ],
62+ parse_obj_as (
63+ type_ = typing .List [AchievementWithStatsResponse ], # type: ignore
64+ object_ = _response .json (),
65+ ),
66+ )
67+ if _response .status_code == 401 :
68+ raise UnauthorizedError (
69+ typing .cast (
70+ ErrorBody ,
71+ parse_obj_as (
72+ type_ = ErrorBody , # type: ignore
73+ object_ = _response .json (),
74+ ),
75+ )
76+ )
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+ )
87+ if _response .status_code == 422 :
88+ raise UnprocessableEntityError (
89+ typing .cast (
90+ ErrorBody ,
91+ parse_obj_as (
92+ type_ = ErrorBody , # type: ignore
93+ object_ = _response .json (),
94+ ),
95+ )
96+ )
97+ _response_json = _response .json ()
98+ except JSONDecodeError :
99+ raise ApiError (status_code = _response .status_code , body = _response .text )
100+ raise ApiError (status_code = _response .status_code , body = _response_json )
101+
27102 def complete (
28103 self ,
29104 key : str ,
30105 * ,
31- user : UpsertedUser ,
106+ user : UpdatedUser ,
32107 request_options : typing .Optional [RequestOptions ] = None ,
33108 ) -> AchievementCompletionResponse :
34109 """
@@ -39,7 +114,7 @@ def complete(
39114 key : str
40115 Unique reference of the achievement as set when created.
41116
42- user : UpsertedUser
117+ user : UpdatedUser
43118 The user that completed the achievement.
44119
45120 request_options : typing.Optional[RequestOptions]
@@ -52,15 +127,16 @@ def complete(
52127
53128 Examples
54129 --------
55- from trophy import TrophyApi, UpsertedUser
130+ from trophy import TrophyApi, UpdatedUser
56131
57132 client = TrophyApi(
58133 api_key="YOUR_API_KEY",
59134 )
60135 client.achievements.complete(
61136 key="finish-onboarding",
62- user=UpsertedUser(
63- id="user-id",
137+ user=UpdatedUser(
138+ email="user@example.com",
139+ tz="Europe/London",
64140 ),
65141 )
66142 """
@@ -69,7 +145,7 @@ def complete(
69145 method = "POST" ,
70146 json = {
71147 "user" : convert_and_respect_annotation_metadata (
72- object_ = user , annotation = UpsertedUser , direction = "write"
148+ object_ = user , annotation = UpdatedUser , direction = "write"
73149 ),
74150 },
75151 headers = {
@@ -127,11 +203,93 @@ class AsyncAchievementsClient:
127203 def __init__ (self , * , client_wrapper : AsyncClientWrapper ):
128204 self ._client_wrapper = client_wrapper
129205
206+ async def all_ (
207+ self , * , request_options : typing .Optional [RequestOptions ] = None
208+ ) -> typing .List [AchievementWithStatsResponse ]:
209+ """
210+ Get all achievements and their completion stats.
211+
212+ Parameters
213+ ----------
214+ request_options : typing.Optional[RequestOptions]
215+ Request-specific configuration.
216+
217+ Returns
218+ -------
219+ typing.List[AchievementWithStatsResponse]
220+ Successful operation
221+
222+ Examples
223+ --------
224+ import asyncio
225+
226+ from trophy import AsyncTrophyApi
227+
228+ client = AsyncTrophyApi(
229+ api_key="YOUR_API_KEY",
230+ )
231+
232+
233+ async def main() -> None:
234+ await client.achievements.all_()
235+
236+
237+ asyncio.run(main())
238+ """
239+ _response = await self ._client_wrapper .httpx_client .request (
240+ "achievements" ,
241+ method = "GET" ,
242+ request_options = request_options ,
243+ )
244+ try :
245+ if 200 <= _response .status_code < 300 :
246+ return typing .cast (
247+ typing .List [AchievementWithStatsResponse ],
248+ parse_obj_as (
249+ type_ = typing .List [AchievementWithStatsResponse ], # type: ignore
250+ object_ = _response .json (),
251+ ),
252+ )
253+ if _response .status_code == 401 :
254+ raise UnauthorizedError (
255+ typing .cast (
256+ ErrorBody ,
257+ parse_obj_as (
258+ type_ = ErrorBody , # type: ignore
259+ object_ = _response .json (),
260+ ),
261+ )
262+ )
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+ )
273+ if _response .status_code == 422 :
274+ raise UnprocessableEntityError (
275+ typing .cast (
276+ ErrorBody ,
277+ parse_obj_as (
278+ type_ = ErrorBody , # type: ignore
279+ object_ = _response .json (),
280+ ),
281+ )
282+ )
283+ _response_json = _response .json ()
284+ except JSONDecodeError :
285+ raise ApiError (status_code = _response .status_code , body = _response .text )
286+ raise ApiError (status_code = _response .status_code , body = _response_json )
287+
130288 async def complete (
131289 self ,
132290 key : str ,
133291 * ,
134- user : UpsertedUser ,
292+ user : UpdatedUser ,
135293 request_options : typing .Optional [RequestOptions ] = None ,
136294 ) -> AchievementCompletionResponse :
137295 """
@@ -142,7 +300,7 @@ async def complete(
142300 key : str
143301 Unique reference of the achievement as set when created.
144302
145- user : UpsertedUser
303+ user : UpdatedUser
146304 The user that completed the achievement.
147305
148306 request_options : typing.Optional[RequestOptions]
@@ -157,7 +315,7 @@ async def complete(
157315 --------
158316 import asyncio
159317
160- from trophy import AsyncTrophyApi, UpsertedUser
318+ from trophy import AsyncTrophyApi, UpdatedUser
161319
162320 client = AsyncTrophyApi(
163321 api_key="YOUR_API_KEY",
@@ -167,8 +325,9 @@ async def complete(
167325 async def main() -> None:
168326 await client.achievements.complete(
169327 key="finish-onboarding",
170- user=UpsertedUser(
171- id="user-id",
328+ user=UpdatedUser(
329+ email="user@example.com",
330+ tz="Europe/London",
172331 ),
173332 )
174333
@@ -180,7 +339,7 @@ async def main() -> None:
180339 method = "POST" ,
181340 json = {
182341 "user" : convert_and_respect_annotation_metadata (
183- object_ = user , annotation = UpsertedUser , direction = "write"
342+ object_ = user , annotation = UpdatedUser , direction = "write"
184343 ),
185344 },
186345 headers = {
0 commit comments