-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathleaderboards.go
More file actions
89 lines (84 loc) · 2.76 KB
/
leaderboards.go
File metadata and controls
89 lines (84 loc) · 2.76 KB
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
package retroachievements
import (
"fmt"
"net/http"
"strconv"
raHttp "github.com/joshraphael/go-retroachievements/http"
"github.com/joshraphael/go-retroachievements/models"
)
// GetGameLeaderboards gets a given games's list of leaderboards.
func (c *Client) GetGameLeaderboards(params models.GetGameLeaderboardsParameters) (*models.GetGameLeaderboards, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetGameLeaderboards.php"),
raHttp.Y(c.APISecret),
raHttp.I([]string{strconv.Itoa(params.GameID)}),
}
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.GetGameLeaderboards](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}
// GetLeaderboardEntries gets a given leaderboards's entries.
func (c *Client) GetLeaderboardEntries(params models.GetLeaderboardEntriesParameters) (*models.GetLeaderboardEntries, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetLeaderboardEntries.php"),
raHttp.Y(c.APISecret),
raHttp.I([]string{strconv.Itoa(params.LeaderboardID)}),
}
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.GetLeaderboardEntries](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}
// GetUserGameLeaderboards gets a user's list of leaderboards for a given game.
func (c *Client) GetUserGameLeaderboards(params models.GetUserGameLeaderboardsParameters) (*models.GetUserGameLeaderboards, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserGameLeaderboards.php"),
raHttp.Y(c.APISecret),
raHttp.U(params.Username),
raHttp.I([]string{strconv.Itoa(params.GameID)}),
}
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.GetUserGameLeaderboards](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}