This repository was archived by the owner on Jun 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathListGames.go
58 lines (51 loc) · 1.4 KB
/
ListGames.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
package hitGox
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
just "github.com/toby3d/hitGox/tools"
f "github.com/valyala/fasthttp"
)
// ListGames contains search results by games.
type ListGames struct {
Request struct {
This string `json:"this"`
} `json:"request"`
Category []struct {
ID string `json:"category_id"`
Name string `json:"category_name"`
NameShort string `json:"category_name_short"`
SeoKey string `json:"category_seo_key"`
Viewers string `json:"category_viewers"`
MediaCount string `json:"category_media_count"`
Channels string `json:"category_channels"`
LogoSmall string `json:"category_logo_small"`
LogoLarge string `json:"category_logo_large"`
Updated string `json:"category_updated"`
} `json:"categories"`
}
// GetListGames returns a list games sorted by the number of viewers.
func GetListGames(query string, limit int, liveOnly bool) (*ListGames, error) {
var args f.Args
switch {
case query != "":
args.Add("q", query)
fallthrough
case limit > 0 && limit <= 100:
args.Add("limit", strconv.Itoa(limit))
fallthrough
default:
args.Add("liveonly", strconv.FormatBool(liveOnly))
}
url := fmt.Sprintf(APIEndpoint, "games")
resp, err := just.GET(url, &args)
if err != nil {
return nil, err
}
var obj ListGames
if err = json.NewDecoder(bytes.NewReader(resp)).Decode(&obj); err != nil {
return nil, err
}
return &obj, nil
}