-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpublishers.go
38 lines (30 loc) · 904 Bytes
/
publishers.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
package rawg
import (
"context"
"fmt"
)
// GetPublishers returns a list of video game publishers
func (api *Client) GetPublishers(ctx context.Context, page int, pageSize int) ([]*Publisher, int, error) {
path := "/publishers"
data := map[string]interface{}{
"page": fmt.Sprint(page),
"page_size": fmt.Sprint(pageSize),
}
var response struct {
Results []*Publisher `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
}
// GetPublisher returns details of the publisher
func (api *Client) GetPublisher(ctx context.Context, id int) (*PublisherDetailed, error) {
path := fmt.Sprintf("/publishers/%d", id)
var publisher PublisherDetailed
if err := api.get(ctx, path, nil, &publisher); err != nil {
return nil, err
}
return &publisher, nil
}