-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathinvolvedcompany.go
109 lines (89 loc) · 3.38 KB
/
involvedcompany.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package igdb
import (
"github.com/Henry-Sarabia/sliceconv"
"github.com/pkg/errors"
"strconv"
)
//go:generate gomodifytags -file $GOFILE -struct InvolvedCompany -add-tags json -w
// InvolvedCompany represents a company involved in the development
// of a particular video game.
// For more information visit: https://api-docs.igdb.com/#involved-company
type InvolvedCompany struct {
ID int `json:"id"`
Company int `json:"company"`
CreatedAt int `json:"created_at"`
Developer bool `json:"developer"`
Game int `json:"game"`
Porting bool `json:"porting"`
Publisher bool `json:"publisher"`
Supporting bool `json:"supporting"`
UpdatedAt int `json:"updated_at"`
}
// InvolvedCompanyService handles all the API calls for the IGDB InvolvedCompany endpoint.
type InvolvedCompanyService service
// Get returns a single InvolvedCompany identified by the provided IGDB ID. Provide
// the SetFields functional option if you need to specify which fields to
// retrieve. If the ID does not match any InvolvedCompanies, an error is returned.
func (is *InvolvedCompanyService) Get(id int, opts ...Option) (*InvolvedCompany, error) {
if id < 0 {
return nil, ErrNegativeID
}
var com []*InvolvedCompany
opts = append(opts, SetFilter("id", OpEquals, strconv.Itoa(id)))
err := is.client.post(is.end, &com, opts...)
if err != nil {
return nil, errors.Wrapf(err, "cannot get InvolvedCompany with ID %v", id)
}
return com[0], nil
}
// List returns a list of InvolvedCompanies identified by the provided list of IGDB IDs.
// Provide functional options to sort, filter, and paginate the results.
// Any ID that does not match a InvolvedCompany is ignored. If none of the IDs
// match a InvolvedCompany, an error is returned.
func (is *InvolvedCompanyService) List(ids []int, opts ...Option) ([]*InvolvedCompany, error) {
for len(ids) < 1 {
return nil, ErrEmptyIDs
}
for _, id := range ids {
if id < 0 {
return nil, ErrNegativeID
}
}
var com []*InvolvedCompany
opts = append(opts, SetFilter("id", OpContainsAtLeast, sliceconv.Itoa(ids)...))
err := is.client.post(is.end, &com, opts...)
if err != nil {
return nil, errors.Wrapf(err, "cannot get InvolvedCompanies with IDs %v", ids)
}
return com, nil
}
// Index returns an index of InvolvedCompanies based solely on the provided functional
// options used to sort, filter, and paginate the results. If no InvolvedCompanies can
// be found using the provided options, an error is returned.
func (is *InvolvedCompanyService) Index(opts ...Option) ([]*InvolvedCompany, error) {
var com []*InvolvedCompany
err := is.client.post(is.end, &com, opts...)
if err != nil {
return nil, errors.Wrap(err, "cannot get index of InvolvedCompanies")
}
return com, nil
}
// Count returns the number of InvolvedCompanies available in the IGDB.
// Provide the SetFilter functional option if you need to filter
// which InvolvedCompanies to count.
func (is *InvolvedCompanyService) Count(opts ...Option) (int, error) {
ct, err := is.client.getCount(is.end, opts...)
if err != nil {
return 0, errors.Wrap(err, "cannot count InvolvedCompanies")
}
return ct, nil
}
// Fields returns the up-to-date list of fields in an
// IGDB InvolvedCompany object.
func (is *InvolvedCompanyService) Fields() ([]string, error) {
f, err := is.client.getFields(is.end)
if err != nil {
return nil, errors.Wrap(err, "cannot get InvolvedCompany fields")
}
return f, nil
}