forked from nicklaw5/helix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgames.go
81 lines (68 loc) · 1.81 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package helix
// Game ...
type Game struct {
ID string `json:"id"`
Name string `json:"name"`
BoxArtURL string `json:"box_art_url"`
}
// ManyGames ...
type ManyGames struct {
Games []Game `json:"data"`
}
// GamesResponse ...
type GamesResponse struct {
ResponseCommon
Data ManyGames
}
// GamesParams ...
type GamesParams struct {
IDs []string `query:"id"` // Limit 100
Names []string `query:"name"` // Limit 100
}
// GetGames ...
func (c *Client) GetGames(params *GamesParams) (*GamesResponse, error) {
resp, err := c.get("/games", &ManyGames{}, params)
if err != nil {
return nil, err
}
games := &GamesResponse{}
games.StatusCode = resp.StatusCode
games.Header = resp.Header
games.Error = resp.Error
games.ErrorStatus = resp.ErrorStatus
games.ErrorMessage = resp.ErrorMessage
games.Data.Games = resp.Data.(*ManyGames).Games
return games, nil
}
// ManyGamesWithPagination ...
type ManyGamesWithPagination struct {
ManyGames
Pagination Pagination `json:"pagination"`
}
// TopGamesParams ...
type TopGamesParams struct {
After string `query:"after"`
Before string `query:"before"`
First int `query:"first,20"` // Limit 100
}
// TopGamesResponse ...
type TopGamesResponse struct {
ResponseCommon
Data ManyGamesWithPagination
}
// GetTopGames ...
func (c *Client) GetTopGames(params *TopGamesParams) (*TopGamesResponse, error) {
resp, err := c.get("/games/top", &ManyGamesWithPagination{}, params)
if err != nil {
return nil, err
}
games := &TopGamesResponse{}
games.StatusCode = resp.StatusCode
games.Header = resp.Header
games.Error = resp.Error
games.ErrorStatus = resp.ErrorStatus
games.ErrorMessage = resp.ErrorMessage
games.Data.Games = resp.Data.(*ManyGamesWithPagination).Games
games.Data.Pagination = resp.Data.(*ManyGamesWithPagination).Pagination
return games, nil
}