-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
416 lines (396 loc) · 13.2 KB
/
user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
package retroachievements
import (
"fmt"
"net/http"
"strconv"
"time"
raHttp "github.com/joshraphael/go-retroachievements/http"
"github.com/joshraphael/go-retroachievements/models"
)
// GetUserProfile get a user's basic profile information.
func (c *Client) GetUserProfile(params models.GetUserProfileParameters) (*models.GetUserProfile, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserProfile.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseObject[models.GetUserProfile](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}
// GetUserRecentAchievements get a list of achievements recently earned by the user.
func (c *Client) GetUserRecentAchievements(params models.GetUserRecentAchievementsParameters) ([]models.GetUserRecentAchievements, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserRecentAchievements.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
}
if params.LookbackMinutes != nil {
details = append(details, raHttp.M(*params.LookbackMinutes))
}
r, err := c.do(details...)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseList[models.GetUserRecentAchievements](r)
if err != nil {
return nil, fmt.Errorf("parsing response list: %w", err)
}
return resp, nil
}
// GetAchievementsEarnedBetween get a list of achievements earned by a user between two dates.
func (c *Client) GetAchievementsEarnedBetween(params models.GetAchievementsEarnedBetweenParameters) ([]models.GetAchievementsEarnedBetween, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetAchievementsEarnedBetween.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
raHttp.F(int(params.From.Unix())),
raHttp.T(strconv.Itoa(int(params.To.Unix()))),
)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseList[models.GetAchievementsEarnedBetween](r)
if err != nil {
return nil, fmt.Errorf("parsing response list: %w", err)
}
return resp, nil
}
// GetAchievementsEarnedOnDay get a list of achievements earned by a user on a given date.
func (c *Client) GetAchievementsEarnedOnDay(params models.GetAchievementsEarnedOnDayParameters) ([]models.GetAchievementsEarnedOnDay, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetAchievementsEarnedOnDay.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
raHttp.D(params.Date.UTC().Format(time.DateOnly)),
)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseList[models.GetAchievementsEarnedOnDay](r)
if err != nil {
return nil, fmt.Errorf("parsing response list: %w", err)
}
return resp, nil
}
// GetGameInfoAndUserProgress get metadata about a game as well as a user's progress on that game.
func (c *Client) GetGameInfoAndUserProgress(params models.GetGameInfoAndUserProgressParameters) (*models.GetGameInfoAndUserProgress, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetGameInfoAndUserProgress.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
raHttp.G(params.GameID),
}
if params.IncludeAwardMetadata != nil {
a := 0
if *params.IncludeAwardMetadata {
a = 1
}
details = append(details, raHttp.A(a))
}
r, err := c.do(details...)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseObject[models.GetGameInfoAndUserProgress](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}
// GetUserCompletionProgress get metadata about all the user's played games and any awards associated with them.
func (c *Client) GetUserCompletionProgress(params models.GetUserCompletionProgressParameters) (*models.GetUserCompletionProgress, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserCompletionProgress.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseObject[models.GetUserCompletionProgress](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}
// GetUserAwards get a list of a user's site awards/badges.
func (c *Client) GetUserAwards(params models.GetUserAwardsParameters) (*models.GetUserAwards, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserAwards.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseObject[models.GetUserAwards](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}
// GetUserClaims get a list of set development claims made over the lifetime of a user.
func (c *Client) GetUserClaims(params models.GetUserClaimsParameters) ([]models.GetUserClaims, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserClaims.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseList[models.GetUserClaims](r)
if err != nil {
return nil, fmt.Errorf("parsing response list: %w", err)
}
return resp, nil
}
// GetUserGameRankAndScore get metadata about how a user has performed on a given game.
func (c *Client) GetUserGameRankAndScore(params models.GetUserGameRankAndScoreParameters) ([]models.GetUserGameRankAndScore, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserGameRankAndScore.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
raHttp.G(params.GameID),
)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseList[models.GetUserGameRankAndScore](r)
if err != nil {
return nil, fmt.Errorf("parsing response list: %w", err)
}
return resp, nil
}
// GetUserPoints get a user's total hardcore and softcore points.
func (c *Client) GetUserPoints(params models.GetUserPointsParameters) (*models.GetUserPoints, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserPoints.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseObject[models.GetUserPoints](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}
// GetUserProgress get a user's progress on a list of specified games.
func (c *Client) GetUserProgress(params models.GetUserProgressParameters) (*map[string]models.GetUserProgress, error) {
strIDs := []string{}
for i := range params.GameIDs {
strIDs = append(strIDs, strconv.Itoa(params.GameIDs[i]))
}
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserProgress.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
raHttp.I(strIDs),
)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseObject[map[string]models.GetUserProgress](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}
// GetUserRecentlyPlayedGames get a list of games a user has recently played.
func (c *Client) GetUserRecentlyPlayedGames(params models.GetUserRecentlyPlayedGamesParameters) ([]models.GetUserRecentlyPlayedGames, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserRecentlyPlayedGames.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
}
if params.Count != nil {
details = append(details, raHttp.C(*params.Count))
}
if params.Offset != nil {
details = append(details, raHttp.O(*params.Offset))
}
r, err := c.do(details...)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseList[models.GetUserRecentlyPlayedGames](r)
if err != nil {
return nil, fmt.Errorf("parsing response list: %w", err)
}
return resp, nil
}
// GetUserSummary get summary information about a given user.
func (c *Client) GetUserSummary(params models.GetUserSummaryParameters) (*models.GetUserSummary, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserSummary.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
}
if params.GamesCount != nil {
details = append(details, raHttp.G(*params.GamesCount))
}
if params.AchievementsCount != nil {
details = append(details, raHttp.A(*params.AchievementsCount))
}
r, err := c.do(details...)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseObject[models.GetUserSummary](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}
// GetUserCompletedGames gets completion metadata about the games a given user has played.
func (c *Client) GetUserCompletedGames(params models.GetUserCompletedGamesParameters) ([]models.GetUserCompletedGames, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserCompletedGames.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseList[models.GetUserCompletedGames](r)
if err != nil {
return nil, fmt.Errorf("parsing response list: %w", err)
}
return resp, nil
}
// GetUserWantToPlayList gets a given user's "Want to Play Games" list.
func (c *Client) GetUserWantToPlayList(params models.GetUserWantToPlayListParameters) (*models.GetUserWantToPlayList, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserWantToPlayList.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
}
if params.Count != nil {
details = append(details, raHttp.C(*params.Count))
}
if params.Offset != nil {
details = append(details, raHttp.O(*params.Offset))
}
r, err := c.do(details...)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseObject[models.GetUserWantToPlayList](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}
// GetUsersIFollow gets the caller's "Following" users list.
func (c *Client) GetUsersIFollow(params models.GetUsersIFollowParameters) (*models.GetUsersIFollow, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUsersIFollow.php"),
raHttp.Y(c.APISecret),
}
if params.Count != nil {
details = append(details, raHttp.C(*params.Count))
}
if params.Offset != nil {
details = append(details, raHttp.O(*params.Offset))
}
r, err := c.do(details...)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseObject[models.GetUsersIFollow](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}
// GetUsersIFollow gets the caller's "Followers" users list.
func (c *Client) GetUsersFollowingMe(params models.GetUsersFollowingMeParameters) (*models.GetUsersFollowingMe, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUsersFollowingMe.php"),
raHttp.Y(c.APISecret),
}
if params.Count != nil {
details = append(details, raHttp.C(*params.Count))
}
if params.Offset != nil {
details = append(details, raHttp.O(*params.Offset))
}
r, err := c.do(details...)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseObject[models.GetUsersFollowingMe](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}
// GetUserSetRequests gets a user's list of set requests.
func (c *Client) GetUserSetRequests(params models.GetUserSetRequestsParameters) (*models.GetUserSetRequests, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserSetRequests.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
}
if params.All != nil {
t := "0"
if *params.All {
t = "1"
}
details = append(details, raHttp.T(t))
}
r, err := c.do(details...)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseObject[models.GetUserSetRequests](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}