forked from nicklaw5/helix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
games.go
64 lines (51 loc) · 1.4 KB
/
games.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
package helix
type Game struct {
ID string `json:"id"`
Name string `json:"name"`
BoxArtURL string `json:"box_art_url"`
}
type ManyGames struct {
Games []Game `json:"data"`
}
type GamesResponse struct {
ResponseCommon
Data ManyGames
}
type GamesParams struct {
IDs []string `query:"id"` // Limit 100
Names []string `query:"name"` // Limit 100
}
func (c *Client) GetGames(params *GamesParams) (*GamesResponse, error) {
resp, err := c.get("/games", &ManyGames{}, params)
if err != nil {
return nil, err
}
games := &GamesResponse{}
resp.HydrateResponseCommon(&games.ResponseCommon)
games.Data.Games = resp.Data.(*ManyGames).Games
return games, nil
}
type ManyGamesWithPagination struct {
ManyGames
Pagination Pagination `json:"pagination"`
}
type TopGamesParams struct {
After string `query:"after"`
Before string `query:"before"`
First int `query:"first,20"` // Limit 100
}
type TopGamesResponse struct {
ResponseCommon
Data ManyGamesWithPagination
}
func (c *Client) GetTopGames(params *TopGamesParams) (*TopGamesResponse, error) {
resp, err := c.get("/games/top", &ManyGamesWithPagination{}, params)
if err != nil {
return nil, err
}
games := &TopGamesResponse{}
resp.HydrateResponseCommon(&games.ResponseCommon)
games.Data.Games = resp.Data.(*ManyGamesWithPagination).Games
games.Data.Pagination = resp.Data.(*ManyGamesWithPagination).Pagination
return games, nil
}