-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgames.go
54 lines (45 loc) · 1.05 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
package twch
type Games struct {
client *Client
}
type Game struct {
Name *string `json:"name" `
Box *Asset `json:"box"`
Logo *Asset `json:"logo"`
GiantbombId *int `json:"giantbomb_id"`
Popularity *int `json:"popularity,omitempty"`
Viewers *int
Channels *int
}
type gameRoot struct {
Top []gameResult `json:"top"`
listTotal
listLinks
}
type gameResult struct {
Game *Game `json:"game"`
Viewers *int `json:"viewers"`
Channels *int `json:"channels"`
}
// Top lists games sorted by number of current viewers on Twitch, most popular first
func (g *Games) ListTop(opts *RequestOptions) (games []Game, resp *Response, err error) {
url, err := appendOptions("games/top", opts)
if err != nil {
return
}
req, err := g.client.NewRequest("GET", url)
if err != nil {
return
}
r := new(gameRoot)
resp, err = g.client.Do(req, r)
if err != nil {
return
}
for _, v := range r.Top {
v.Game.Viewers = v.Viewers
v.Game.Channels = v.Channels
games = append(games, *v.Game)
}
return games, resp, err
}