-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsystem.go
More file actions
83 lines (79 loc) · 2.12 KB
/
Copy pathsystem.go
File metadata and controls
83 lines (79 loc) · 2.12 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
package retroachievements
import (
"fmt"
"net/http"
"strconv"
raHttp "github.com/joshraphael/go-retroachievements/http"
"github.com/joshraphael/go-retroachievements/models"
)
// GetConsoleIDs gets the complete list of all system ID and name pairs on the site.
func (c *Client) GetConsoleIDs(params models.GetConsoleIDsParameters) ([]models.GetConsoleIDs, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetConsoleIDs.php"),
raHttp.Y(c.APISecret),
}
if params.OnlyActive != nil {
active := 0
if *params.OnlyActive {
active = 1
}
details = append(details, raHttp.A(active))
}
if params.OnlyGameSystems != nil {
g := 0
if *params.OnlyGameSystems {
g = 1
}
details = append(details, raHttp.G(g))
}
r, err := c.do(details...)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseList[models.GetConsoleIDs](r)
if err != nil {
return nil, fmt.Errorf("parsing response list: %w", err)
}
return resp, nil
}
// GetGameList gets the complete list of games for a specified console on the site.
func (c *Client) GetGameList(params models.GetGameListParameters) ([]models.GetGameList, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetGameList.php"),
raHttp.Y(c.APISecret),
raHttp.I([]string{strconv.Itoa(params.SystemID)}),
}
if params.HasAchievements != nil {
f := 0
if *params.HasAchievements {
f = 1
}
details = append(details, raHttp.F(f))
}
if params.IncludeHashes != nil {
h := 0
if *params.IncludeHashes {
h = 1
}
details = append(details, raHttp.H(h))
}
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.GetGameList](r)
if err != nil {
return nil, fmt.Errorf("parsing response list: %w", err)
}
return resp, nil
}