-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplatforms.go
65 lines (52 loc) · 1.54 KB
/
platforms.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
package rawg
import (
"context"
"fmt"
)
// GetPlatforms returns a list of video game platforms
func (api *Client) GetPlatforms(ctx context.Context, page int, pageSize int, ordering string) ([]*Platform, int, error) {
path := "/platforms"
data := map[string]interface{}{
"page": fmt.Sprint(page),
"page_size": fmt.Sprint(pageSize),
}
if ordering != "" {
data["ordering"] = ordering
}
var response struct {
Results []*Platform `json:"results"`
Count int `json:"count"`
}
if err := api.get(ctx, path, data, &response); err != nil {
return nil, 0, err
}
return response.Results, response.Count, nil
}
// GetParentsPlatforms returns a list of parent platforms
func (api *Client) GetParentsPlatforms(ctx context.Context, page int, pageSize int, ordering string) ([]*Platform, int, error) {
path := "/platforms/lists/parents"
data := map[string]interface{}{
"page": fmt.Sprint(page),
"page_size": fmt.Sprint(pageSize),
}
if ordering != "" {
data["ordering"] = ordering
}
var response struct {
Results []*Platform `json:"results"`
Count int `json:"count"`
}
if err := api.get(ctx, path, data, &response); err != nil {
return nil, 0, err
}
return response.Results, response.Count, nil
}
// GetPlatform returns details of the platform
func (api *Client) GetPlatform(ctx context.Context, id int) (*PlatformDetailed, error) {
path := fmt.Sprintf("/platforms/%d", id)
var platform PlatformDetailed
if err := api.get(ctx, path, nil, &platform); err != nil {
return nil, err
}
return &platform, nil
}