mirror of
https://github.com/bestnite/go-igdb.git
synced 2025-07-01 23:22:10 +08:00
u
This commit is contained in:
31
endpoint/age_rating_categories.go
Normal file
31
endpoint/age_rating_categories.go
Normal file
@ -0,0 +1,31 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type AgeRatingCategories struct {
|
||||
BaseEndpoint
|
||||
}
|
||||
|
||||
func (a *AgeRatingCategories) Query(query string) ([]*pb.AgeRatingCategory, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/age_rating_categories.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.AgeRatingCategoryResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Ageratingcategories) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Ageratingcategories, nil
|
||||
}
|
31
endpoint/age_rating_content_descriptions.go
Normal file
31
endpoint/age_rating_content_descriptions.go
Normal file
@ -0,0 +1,31 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type AgeRatingContentDescriptions struct {
|
||||
BaseEndpoint
|
||||
}
|
||||
|
||||
func (a *AgeRatingContentDescriptions) Query(query string) ([]*pb.AgeRatingContentDescription, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/age_rating_content_descriptions.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.AgeRatingContentDescriptionResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Ageratingcontentdescriptions) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Ageratingcontentdescriptions, nil
|
||||
}
|
31
endpoint/age_rating_content_descriptions_v2.go
Normal file
31
endpoint/age_rating_content_descriptions_v2.go
Normal file
@ -0,0 +1,31 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type AgeRatingContentDescriptionsV2 struct {
|
||||
BaseEndpoint
|
||||
}
|
||||
|
||||
func (a *AgeRatingContentDescriptionsV2) Query(query string) ([]*pb.AgeRatingContentDescriptionV2, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/age_rating_content_descriptions_v2.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.AgeRatingContentDescriptionV2Result{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Ageratingcontentdescriptionsv2) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Ageratingcontentdescriptionsv2, nil
|
||||
}
|
29
endpoint/age_rating_organizations.go
Normal file
29
endpoint/age_rating_organizations.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type AgeRatingOrganizations struct{ BaseEndpoint }
|
||||
|
||||
func (a *AgeRatingOrganizations) Query(query string) ([]*pb.AgeRatingOrganization, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/age_rating_organizations.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.AgeRatingOrganizationResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Ageratingorganizations) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Ageratingorganizations, nil
|
||||
}
|
29
endpoint/age_ratings.go
Normal file
29
endpoint/age_ratings.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type AgeRatings struct{ BaseEndpoint }
|
||||
|
||||
func (a *AgeRatings) Query(query string) ([]*pb.AgeRating, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/age_ratings.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.AgeRatingResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Ageratings) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Ageratings, nil
|
||||
}
|
29
endpoint/alternative_names.go
Normal file
29
endpoint/alternative_names.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type AlternativeNames struct{ BaseEndpoint }
|
||||
|
||||
func (a *AlternativeNames) Query(query string) ([]*pb.AlternativeName, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/alternative_names.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.AlternativeNameResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Alternativenames) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Alternativenames, nil
|
||||
}
|
29
endpoint/artworks.go
Normal file
29
endpoint/artworks.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Artworks struct{ BaseEndpoint }
|
||||
|
||||
func (a *Artworks) Query(query string) ([]*pb.Artwork, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/artworks.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.ArtworkResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Artworks) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Artworks, nil
|
||||
}
|
38
endpoint/base.go
Normal file
38
endpoint/base.go
Normal file
@ -0,0 +1,38 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
type BaseEndpoint struct {
|
||||
request func(URL string, dataBody any) (*resty.Response, error)
|
||||
endpointName EndpointName
|
||||
}
|
||||
|
||||
func NewBaseEndpoint(request func(URL string, dataBody any) (*resty.Response, error), endpointName EndpointName) *BaseEndpoint {
|
||||
return &BaseEndpoint{
|
||||
request: request,
|
||||
endpointName: endpointName,
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BaseEndpoint) GetEndpointName() EndpointName {
|
||||
return b.endpointName
|
||||
}
|
||||
|
||||
func (b *BaseEndpoint) Query(query string) (any, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (b *BaseEndpoint) QueryAny(query string) (any, error) {
|
||||
return b.Query(query)
|
||||
}
|
||||
|
||||
type Endpoint interface {
|
||||
GetEndpointName() EndpointName
|
||||
}
|
||||
|
||||
type EntityEndpoint interface {
|
||||
QueryAny(query string) (any, error)
|
||||
GetEndpointName() EndpointName
|
||||
}
|
29
endpoint/character_genders.go
Normal file
29
endpoint/character_genders.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type CharacterGenders struct{ BaseEndpoint }
|
||||
|
||||
func (a *CharacterGenders) Query(query string) ([]*pb.CharacterGender, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/character_genders.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.CharacterGenderResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Charactergenders) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Charactergenders, nil
|
||||
}
|
29
endpoint/character_mug_shots.go
Normal file
29
endpoint/character_mug_shots.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type CharacterMugShots struct{ BaseEndpoint }
|
||||
|
||||
func (a *CharacterMugShots) Query(query string) ([]*pb.CharacterMugShot, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/character_mug_shots.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.CharacterMugShotResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Charactermugshots) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Charactermugshots, nil
|
||||
}
|
29
endpoint/character_species.go
Normal file
29
endpoint/character_species.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type CharacterSpecies struct{ BaseEndpoint }
|
||||
|
||||
func (a *CharacterSpecies) Query(query string) ([]*pb.CharacterSpecie, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/character_species.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.CharacterSpecieResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Characterspecies) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Characterspecies, nil
|
||||
}
|
29
endpoint/characters.go
Normal file
29
endpoint/characters.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Characters struct{ BaseEndpoint }
|
||||
|
||||
func (a *Characters) Query(query string) ([]*pb.Character, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/characters.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.CharacterResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Characters) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Characters, nil
|
||||
}
|
29
endpoint/collection_membership_types.go
Normal file
29
endpoint/collection_membership_types.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type CollectionMembershipTypes struct{ BaseEndpoint }
|
||||
|
||||
func (a *CollectionMembershipTypes) Query(query string) ([]*pb.CollectionMembershipType, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/collection_membership_types.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.CollectionMembershipTypeResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Collectionmembershiptypes) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Collectionmembershiptypes, nil
|
||||
}
|
29
endpoint/collection_memberships.go
Normal file
29
endpoint/collection_memberships.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type CollectionMemberships struct{ BaseEndpoint }
|
||||
|
||||
func (a *CollectionMemberships) Query(query string) ([]*pb.CollectionMembership, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/collection_memberships.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.CollectionMembershipResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Collectionmemberships) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Collectionmemberships, nil
|
||||
}
|
29
endpoint/collection_relation_types.go
Normal file
29
endpoint/collection_relation_types.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type CollectionRelationTypes struct{ BaseEndpoint }
|
||||
|
||||
func (a *CollectionRelationTypes) Query(query string) ([]*pb.CollectionRelationType, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/collection_relation_types.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.CollectionRelationTypeResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Collectionrelationtypes) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Collectionrelationtypes, nil
|
||||
}
|
29
endpoint/collection_relations.go
Normal file
29
endpoint/collection_relations.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type CollectionRelations struct{ BaseEndpoint }
|
||||
|
||||
func (a *CollectionRelations) Query(query string) ([]*pb.CollectionRelation, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/collection_relations.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.CollectionRelationResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Collectionrelations) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Collectionrelations, nil
|
||||
}
|
29
endpoint/collection_types.go
Normal file
29
endpoint/collection_types.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type CollectionTypes struct{ BaseEndpoint }
|
||||
|
||||
func (a *CollectionTypes) Query(query string) ([]*pb.CollectionType, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/collection_types.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.CollectionTypeResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Collectiontypes) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Collectiontypes, nil
|
||||
}
|
29
endpoint/collections.go
Normal file
29
endpoint/collections.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Collections struct{ BaseEndpoint }
|
||||
|
||||
func (a *Collections) Query(query string) ([]*pb.Collection, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/collections.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.CollectionResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Collections) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Collections, nil
|
||||
}
|
30
endpoint/companies.go
Normal file
30
endpoint/companies.go
Normal file
@ -0,0 +1,30 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Companies struct{ BaseEndpoint }
|
||||
|
||||
func (a *Companies) Query(query string) ([]*pb.Company, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/companies.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.CompanyResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Companies) == 0 {
|
||||
return nil, errors.New("no results")
|
||||
}
|
||||
|
||||
return data.Companies, nil
|
||||
}
|
29
endpoint/company_logos.go
Normal file
29
endpoint/company_logos.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type CompanyLogos struct{ BaseEndpoint }
|
||||
|
||||
func (a *CompanyLogos) Query(query string) ([]*pb.CompanyLogo, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/company_logos.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.CompanyLogoResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Companylogos) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Companylogos, nil
|
||||
}
|
29
endpoint/company_statuses.go
Normal file
29
endpoint/company_statuses.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type CompanyStatuses struct{ BaseEndpoint }
|
||||
|
||||
func (a *CompanyStatuses) Query(query string) ([]*pb.CompanyStatus, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/company_statuses.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.CompanyStatusResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Companystatuses) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Companystatuses, nil
|
||||
}
|
29
endpoint/company_websites.go
Normal file
29
endpoint/company_websites.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type CompanyWebsites struct{ BaseEndpoint }
|
||||
|
||||
func (a *CompanyWebsites) Query(query string) ([]*pb.CompanyWebsite, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/company_websites.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.CompanyWebsiteResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Companywebsites) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Companywebsites, nil
|
||||
}
|
29
endpoint/covers.go
Normal file
29
endpoint/covers.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Covers struct{ BaseEndpoint }
|
||||
|
||||
func (a *Covers) Query(query string) ([]*pb.Cover, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/covers.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.CoverResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Covers) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Covers, nil
|
||||
}
|
29
endpoint/date_formats.go
Normal file
29
endpoint/date_formats.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type DateFormats struct{ BaseEndpoint }
|
||||
|
||||
func (a *DateFormats) Query(query string) ([]*pb.DateFormat, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/date_formats.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.DateFormatResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Dateformats) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Dateformats, nil
|
||||
}
|
@ -1,151 +0,0 @@
|
||||
package endpoint
|
||||
|
||||
type Endpoint string
|
||||
|
||||
var (
|
||||
AgeRatingCategories Endpoint = "age_rating_categories"
|
||||
AgeRatingContentDescriptions Endpoint = "age_rating_content_descriptions"
|
||||
AgeRatingContentDescriptionsV2 Endpoint = "age_rating_content_descriptions_v2"
|
||||
AgeRatingOrganizations Endpoint = "age_rating_organizations"
|
||||
AgeRatings Endpoint = "age_ratings"
|
||||
AlternativeNames Endpoint = "alternative_names"
|
||||
Artworks Endpoint = "artworks"
|
||||
CharacterGenders Endpoint = "character_genders"
|
||||
CharacterMugShots Endpoint = "character_mug_shots"
|
||||
Characters Endpoint = "characters"
|
||||
CharacterSpecies Endpoint = "character_species"
|
||||
CollectionMemberships Endpoint = "collection_memberships"
|
||||
CollectionMembershipTypes Endpoint = "collection_membership_types"
|
||||
CollectionRelations Endpoint = "collection_relations"
|
||||
CollectionRelationTypes Endpoint = "collection_relation_types"
|
||||
Collections Endpoint = "collections"
|
||||
CollectionTypes Endpoint = "collection_types"
|
||||
Companies Endpoint = "companies"
|
||||
CompanyLogos Endpoint = "company_logos"
|
||||
CompanyStatuses Endpoint = "company_statuses"
|
||||
CompanyWebsites Endpoint = "company_websites"
|
||||
Covers Endpoint = "covers"
|
||||
DateFormats Endpoint = "date_formats"
|
||||
EventLogos Endpoint = "event_logos"
|
||||
EventNetworks Endpoint = "event_networks"
|
||||
Events Endpoint = "events"
|
||||
ExternalGames Endpoint = "external_games"
|
||||
ExternalGameSources Endpoint = "external_game_sources"
|
||||
Franchises Endpoint = "franchises"
|
||||
GameEngineLogos Endpoint = "game_engine_logos"
|
||||
GameEngines Endpoint = "game_engines"
|
||||
GameLocalizations Endpoint = "game_localizations"
|
||||
GameModes Endpoint = "game_modes"
|
||||
GameReleaseFormats Endpoint = "game_release_formats"
|
||||
Games Endpoint = "games"
|
||||
GameStatuses Endpoint = "game_statuses"
|
||||
GameTimeToBeats Endpoint = "game_time_to_beats"
|
||||
GameTypes Endpoint = "game_types"
|
||||
GameVersionFeatures Endpoint = "game_version_features"
|
||||
GameVersionFeatureValues Endpoint = "game_version_feature_values"
|
||||
GameVersions Endpoint = "game_versions"
|
||||
GameVideos Endpoint = "game_videos"
|
||||
Genres Endpoint = "genres"
|
||||
InvolvedCompanies Endpoint = "involved_companies"
|
||||
Keywords Endpoint = "keywords"
|
||||
Languages Endpoint = "languages"
|
||||
LanguageSupports Endpoint = "language_supports"
|
||||
LanguageSupportTypes Endpoint = "language_support_types"
|
||||
MultiplayerModes Endpoint = "multiplayer_modes"
|
||||
NetworkTypes Endpoint = "network_types"
|
||||
PlatformFamilies Endpoint = "platform_families"
|
||||
PlatformLogos Endpoint = "platform_logos"
|
||||
Platforms Endpoint = "platforms"
|
||||
PlatformTypes Endpoint = "platform_types"
|
||||
PlatformVersionCompanies Endpoint = "platform_version_companies"
|
||||
PlatformVersionReleaseDates Endpoint = "platform_version_release_dates"
|
||||
PlatformVersions Endpoint = "platform_versions"
|
||||
PlatformWebsites Endpoint = "platform_websites"
|
||||
PlayerPerspectives Endpoint = "player_perspectives"
|
||||
PopularityPrimitives Endpoint = "popularity_primitives"
|
||||
PopularityTypes Endpoint = "popularity_types"
|
||||
Regions Endpoint = "regions"
|
||||
ReleaseDateRegions Endpoint = "release_date_regions"
|
||||
ReleaseDates Endpoint = "release_dates"
|
||||
ReleaseDateStatuses Endpoint = "release_date_statuses"
|
||||
Screenshots Endpoint = "screenshots"
|
||||
Search Endpoint = "search"
|
||||
Themes Endpoint = "themes"
|
||||
Webhooks Endpoint = "webhooks"
|
||||
Websites Endpoint = "websites"
|
||||
WebsiteTypes Endpoint = "website_types"
|
||||
)
|
||||
|
||||
var AllEndpoints = []Endpoint{
|
||||
AgeRatingCategories,
|
||||
AgeRatingContentDescriptions,
|
||||
AgeRatingContentDescriptionsV2,
|
||||
AgeRatingOrganizations,
|
||||
AgeRatings,
|
||||
AlternativeNames,
|
||||
Artworks,
|
||||
CharacterGenders,
|
||||
CharacterMugShots,
|
||||
Characters,
|
||||
CharacterSpecies,
|
||||
CollectionMemberships,
|
||||
CollectionMembershipTypes,
|
||||
CollectionRelations,
|
||||
CollectionRelationTypes,
|
||||
Collections,
|
||||
CollectionTypes,
|
||||
Companies,
|
||||
CompanyLogos,
|
||||
CompanyStatuses,
|
||||
CompanyWebsites,
|
||||
Covers,
|
||||
DateFormats,
|
||||
EventLogos,
|
||||
EventNetworks,
|
||||
Events,
|
||||
ExternalGames,
|
||||
ExternalGameSources,
|
||||
Franchises,
|
||||
GameEngineLogos,
|
||||
GameEngines,
|
||||
GameLocalizations,
|
||||
GameModes,
|
||||
GameReleaseFormats,
|
||||
Games,
|
||||
GameStatuses,
|
||||
GameTimeToBeats,
|
||||
GameTypes,
|
||||
GameVersionFeatures,
|
||||
GameVersionFeatureValues,
|
||||
GameVersions,
|
||||
GameVideos,
|
||||
Genres,
|
||||
InvolvedCompanies,
|
||||
Keywords,
|
||||
Languages,
|
||||
LanguageSupports,
|
||||
LanguageSupportTypes,
|
||||
MultiplayerModes,
|
||||
NetworkTypes,
|
||||
PlatformFamilies,
|
||||
PlatformLogos,
|
||||
Platforms,
|
||||
PlatformTypes,
|
||||
PlatformVersionCompanies,
|
||||
PlatformVersionReleaseDates,
|
||||
PlatformVersions,
|
||||
PlatformWebsites,
|
||||
PlayerPerspectives,
|
||||
PopularityPrimitives,
|
||||
PopularityTypes,
|
||||
Regions,
|
||||
ReleaseDateRegions,
|
||||
ReleaseDates,
|
||||
ReleaseDateStatuses,
|
||||
Screenshots,
|
||||
Search,
|
||||
Themes,
|
||||
Webhooks,
|
||||
Websites,
|
||||
WebsiteTypes,
|
||||
}
|
151
endpoint/endpoint_name.go
Normal file
151
endpoint/endpoint_name.go
Normal file
@ -0,0 +1,151 @@
|
||||
package endpoint
|
||||
|
||||
type EndpointName string
|
||||
|
||||
var (
|
||||
EPAgeRatingCategories EndpointName = "age_rating_categories"
|
||||
EPAgeRatingContentDescriptions EndpointName = "age_rating_content_descriptions"
|
||||
EPAgeRatingContentDescriptionsV2 EndpointName = "age_rating_content_descriptions_v2"
|
||||
EPAgeRatingOrganizations EndpointName = "age_rating_organizations"
|
||||
EPAgeRatings EndpointName = "age_ratings"
|
||||
EPAlternativeNames EndpointName = "alternative_names"
|
||||
EPArtworks EndpointName = "artworks"
|
||||
EPCharacterGenders EndpointName = "character_genders"
|
||||
EPCharacterMugShots EndpointName = "character_mug_shots"
|
||||
EPCharacters EndpointName = "characters"
|
||||
EPCharacterSpecies EndpointName = "character_species"
|
||||
EPCollectionMemberships EndpointName = "collection_memberships"
|
||||
EPCollectionMembershipTypes EndpointName = "collection_membership_types"
|
||||
EPCollectionRelations EndpointName = "collection_relations"
|
||||
EPCollectionRelationTypes EndpointName = "collection_relation_types"
|
||||
EPCollections EndpointName = "collections"
|
||||
EPCollectionTypes EndpointName = "collection_types"
|
||||
EPCompanies EndpointName = "companies"
|
||||
EPCompanyLogos EndpointName = "company_logos"
|
||||
EPCompanyStatuses EndpointName = "company_statuses"
|
||||
EPCompanyWebsites EndpointName = "company_websites"
|
||||
EPCovers EndpointName = "covers"
|
||||
EPDateFormats EndpointName = "date_formats"
|
||||
EPEventLogos EndpointName = "event_logos"
|
||||
EPEventNetworks EndpointName = "event_networks"
|
||||
EPEvents EndpointName = "events"
|
||||
EPExternalGames EndpointName = "external_games"
|
||||
EPExternalGameSources EndpointName = "external_game_sources"
|
||||
EPFranchises EndpointName = "franchises"
|
||||
EPGameEngineLogos EndpointName = "game_engine_logos"
|
||||
EPGameEngines EndpointName = "game_engines"
|
||||
EPGameLocalizations EndpointName = "game_localizations"
|
||||
EPGameModes EndpointName = "game_modes"
|
||||
EPGameReleaseFormats EndpointName = "game_release_formats"
|
||||
EPGames EndpointName = "games"
|
||||
EPGameStatuses EndpointName = "game_statuses"
|
||||
EPGameTimeToBeats EndpointName = "game_time_to_beats"
|
||||
EPGameTypes EndpointName = "game_types"
|
||||
EPGameVersionFeatures EndpointName = "game_version_features"
|
||||
EPGameVersionFeatureValues EndpointName = "game_version_feature_values"
|
||||
EPGameVersions EndpointName = "game_versions"
|
||||
EPGameVideos EndpointName = "game_videos"
|
||||
EPGenres EndpointName = "genres"
|
||||
EPInvolvedCompanies EndpointName = "involved_companies"
|
||||
EPKeywords EndpointName = "keywords"
|
||||
EPLanguages EndpointName = "languages"
|
||||
EPLanguageSupports EndpointName = "language_supports"
|
||||
EPLanguageSupportTypes EndpointName = "language_support_types"
|
||||
EPMultiplayerModes EndpointName = "multiplayer_modes"
|
||||
EPNetworkTypes EndpointName = "network_types"
|
||||
EPPlatformFamilies EndpointName = "platform_families"
|
||||
EPPlatformLogos EndpointName = "platform_logos"
|
||||
EPPlatforms EndpointName = "platforms"
|
||||
EPPlatformTypes EndpointName = "platform_types"
|
||||
EPPlatformVersionCompanies EndpointName = "platform_version_companies"
|
||||
EPPlatformVersionReleaseDates EndpointName = "platform_version_release_dates"
|
||||
EPPlatformVersions EndpointName = "platform_versions"
|
||||
EPPlatformWebsites EndpointName = "platform_websites"
|
||||
EPPlayerPerspectives EndpointName = "player_perspectives"
|
||||
EPPopularityPrimitives EndpointName = "popularity_primitives"
|
||||
EPPopularityTypes EndpointName = "popularity_types"
|
||||
EPRegions EndpointName = "regions"
|
||||
EPReleaseDateRegions EndpointName = "release_date_regions"
|
||||
EPReleaseDates EndpointName = "release_dates"
|
||||
EPReleaseDateStatuses EndpointName = "release_date_statuses"
|
||||
EPScreenshots EndpointName = "screenshots"
|
||||
EPSearch EndpointName = "search"
|
||||
EPThemes EndpointName = "themes"
|
||||
EPWebhooks EndpointName = "webhooks"
|
||||
EPWebsites EndpointName = "websites"
|
||||
EPWebsiteTypes EndpointName = "website_types"
|
||||
)
|
||||
|
||||
var AllEndpoints = []EndpointName{
|
||||
EPAgeRatingCategories,
|
||||
EPAgeRatingContentDescriptions,
|
||||
EPAgeRatingContentDescriptionsV2,
|
||||
EPAgeRatingOrganizations,
|
||||
EPAgeRatings,
|
||||
EPAlternativeNames,
|
||||
EPArtworks,
|
||||
EPCharacterGenders,
|
||||
EPCharacterMugShots,
|
||||
EPCharacters,
|
||||
EPCharacterSpecies,
|
||||
EPCollectionMemberships,
|
||||
EPCollectionMembershipTypes,
|
||||
EPCollectionRelations,
|
||||
EPCollectionRelationTypes,
|
||||
EPCollections,
|
||||
EPCollectionTypes,
|
||||
EPCompanies,
|
||||
EPCompanyLogos,
|
||||
EPCompanyStatuses,
|
||||
EPCompanyWebsites,
|
||||
EPCovers,
|
||||
EPDateFormats,
|
||||
EPEventLogos,
|
||||
EPEventNetworks,
|
||||
EPEvents,
|
||||
EPExternalGames,
|
||||
EPExternalGameSources,
|
||||
EPFranchises,
|
||||
EPGameEngineLogos,
|
||||
EPGameEngines,
|
||||
EPGameLocalizations,
|
||||
EPGameModes,
|
||||
EPGameReleaseFormats,
|
||||
EPGames,
|
||||
EPGameStatuses,
|
||||
EPGameTimeToBeats,
|
||||
EPGameTypes,
|
||||
EPGameVersionFeatures,
|
||||
EPGameVersionFeatureValues,
|
||||
EPGameVersions,
|
||||
EPGameVideos,
|
||||
EPGenres,
|
||||
EPInvolvedCompanies,
|
||||
EPKeywords,
|
||||
EPLanguages,
|
||||
EPLanguageSupports,
|
||||
EPLanguageSupportTypes,
|
||||
EPMultiplayerModes,
|
||||
EPNetworkTypes,
|
||||
EPPlatformFamilies,
|
||||
EPPlatformLogos,
|
||||
EPPlatforms,
|
||||
EPPlatformTypes,
|
||||
EPPlatformVersionCompanies,
|
||||
EPPlatformVersionReleaseDates,
|
||||
EPPlatformVersions,
|
||||
EPPlatformWebsites,
|
||||
EPPlayerPerspectives,
|
||||
EPPopularityPrimitives,
|
||||
EPPopularityTypes,
|
||||
EPRegions,
|
||||
EPReleaseDateRegions,
|
||||
EPReleaseDates,
|
||||
EPReleaseDateStatuses,
|
||||
EPScreenshots,
|
||||
EPSearch,
|
||||
EPThemes,
|
||||
EPWebhooks,
|
||||
EPWebsites,
|
||||
EPWebsiteTypes,
|
||||
}
|
29
endpoint/event_logos.go
Normal file
29
endpoint/event_logos.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type EventLogos struct{ BaseEndpoint }
|
||||
|
||||
func (a *EventLogos) Query(query string) ([]*pb.EventLogo, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/event_logos.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.EventLogoResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Eventlogos) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Eventlogos, nil
|
||||
}
|
29
endpoint/event_networks.go
Normal file
29
endpoint/event_networks.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type EventNetworks struct{ BaseEndpoint }
|
||||
|
||||
func (a *EventNetworks) Query(query string) ([]*pb.EventNetwork, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/event_networks.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.EventNetworkResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Eventnetworks) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Eventnetworks, nil
|
||||
}
|
29
endpoint/events.go
Normal file
29
endpoint/events.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Events struct{ BaseEndpoint }
|
||||
|
||||
func (a *Events) Query(query string) ([]*pb.Event, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/events.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.EventResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Events) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Events, nil
|
||||
}
|
29
endpoint/external_game_sources.go
Normal file
29
endpoint/external_game_sources.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type ExternalGameSources struct{ BaseEndpoint }
|
||||
|
||||
func (a *ExternalGameSources) Query(query string) ([]*pb.ExternalGameSource, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/external_game_sources.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.ExternalGameSourceResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Externalgamesources) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Externalgamesources, nil
|
||||
}
|
29
endpoint/external_games.go
Normal file
29
endpoint/external_games.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type ExternalGames struct{ BaseEndpoint }
|
||||
|
||||
func (a *ExternalGames) Query(query string) ([]*pb.ExternalGame, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/external_games.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.ExternalGameResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Externalgames) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Externalgames, nil
|
||||
}
|
29
endpoint/franchises.go
Normal file
29
endpoint/franchises.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Franchises struct{ BaseEndpoint }
|
||||
|
||||
func (a *Franchises) Query(query string) ([]*pb.Franchise, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/franchises.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.FranchiseResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Franchises) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Franchises, nil
|
||||
}
|
29
endpoint/game_engine_logos.go
Normal file
29
endpoint/game_engine_logos.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type GameEngineLogos struct{ BaseEndpoint }
|
||||
|
||||
func (a *GameEngineLogos) Query(query string) ([]*pb.GameEngineLogo, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/game_engine_logos.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.GameEngineLogoResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Gameenginelogos) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Gameenginelogos, nil
|
||||
}
|
29
endpoint/game_engines.go
Normal file
29
endpoint/game_engines.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type GameEngines struct{ BaseEndpoint }
|
||||
|
||||
func (a *GameEngines) Query(query string) ([]*pb.GameEngine, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/game_engines.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.GameEngineResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Gameengines) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Gameengines, nil
|
||||
}
|
29
endpoint/game_localizations.go
Normal file
29
endpoint/game_localizations.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type GameLocalizations struct{ BaseEndpoint }
|
||||
|
||||
func (a *GameLocalizations) Query(query string) ([]*pb.GameLocalization, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/game_localizations.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.GameLocalizationResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Gamelocalizations) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Gamelocalizations, nil
|
||||
}
|
29
endpoint/game_modes.go
Normal file
29
endpoint/game_modes.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type GameModes struct{ BaseEndpoint }
|
||||
|
||||
func (a *GameModes) Query(query string) ([]*pb.GameMode, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/game_modes.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.GameModeResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Gamemodes) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Gamemodes, nil
|
||||
}
|
29
endpoint/game_release_formats.go
Normal file
29
endpoint/game_release_formats.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type GameReleaseFormats struct{ BaseEndpoint }
|
||||
|
||||
func (a *GameReleaseFormats) Query(query string) ([]*pb.GameReleaseFormat, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/game_release_formats.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.GameReleaseFormatResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Gamereleaseformats) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Gamereleaseformats, nil
|
||||
}
|
29
endpoint/game_statuses.go
Normal file
29
endpoint/game_statuses.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type GameStatuses struct{ BaseEndpoint }
|
||||
|
||||
func (a *GameStatuses) Query(query string) ([]*pb.GameStatus, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/game_statuses.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.GameStatusResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Gamestatuses) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Gamestatuses, nil
|
||||
}
|
29
endpoint/game_time_to_beats.go
Normal file
29
endpoint/game_time_to_beats.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type GameTimeToBeats struct{ BaseEndpoint }
|
||||
|
||||
func (a *GameTimeToBeats) Query(query string) ([]*pb.GameTimeToBeat, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/game_time_to_beats.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.GameTimeToBeatResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Gametimetobeats) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Gametimetobeats, nil
|
||||
}
|
29
endpoint/game_types.go
Normal file
29
endpoint/game_types.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type GameTypes struct{ BaseEndpoint }
|
||||
|
||||
func (a *GameTypes) Query(query string) ([]*pb.GameType, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/game_types.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.GameTypeResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Gametypes) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Gametypes, nil
|
||||
}
|
29
endpoint/game_version_feature_values.go
Normal file
29
endpoint/game_version_feature_values.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type GameVersionFeatureValues struct{ BaseEndpoint }
|
||||
|
||||
func (a *GameVersionFeatureValues) Query(query string) ([]*pb.GameVersionFeatureValue, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/game_version_feature_values.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.GameVersionFeatureValueResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Gameversionfeaturevalues) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Gameversionfeaturevalues, nil
|
||||
}
|
29
endpoint/game_version_features.go
Normal file
29
endpoint/game_version_features.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type GameVersionFeatures struct{ BaseEndpoint }
|
||||
|
||||
func (a *GameVersionFeatures) Query(query string) ([]*pb.GameVersionFeature, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/game_version_features.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.GameVersionFeatureResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Gameversionfeatures) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Gameversionfeatures, nil
|
||||
}
|
29
endpoint/game_versions.go
Normal file
29
endpoint/game_versions.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type GameVersions struct{ BaseEndpoint }
|
||||
|
||||
func (a *GameVersions) Query(query string) ([]*pb.GameVersion, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/game_versions.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.GameVersionResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Gameversions) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Gameversions, nil
|
||||
}
|
29
endpoint/game_videos.go
Normal file
29
endpoint/game_videos.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type GameVideos struct{ BaseEndpoint }
|
||||
|
||||
func (a *GameVideos) Query(query string) ([]*pb.GameVideo, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/game_videos.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.GameVideoResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Gamevideos) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Gamevideos, nil
|
||||
}
|
29
endpoint/games.go
Normal file
29
endpoint/games.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Games struct{ BaseEndpoint }
|
||||
|
||||
func (a *Games) Query(query string) ([]*pb.Game, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/games.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.GameResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Games) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Games, nil
|
||||
}
|
29
endpoint/genres.go
Normal file
29
endpoint/genres.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Genres struct{ BaseEndpoint }
|
||||
|
||||
func (a *Genres) Query(query string) ([]*pb.Genre, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/genres.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.GenreResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Genres) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Genres, nil
|
||||
}
|
29
endpoint/involved_companies.go
Normal file
29
endpoint/involved_companies.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type InvolvedCompanies struct{ BaseEndpoint }
|
||||
|
||||
func (a *InvolvedCompanies) Query(query string) ([]*pb.InvolvedCompany, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/involved_companies.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.InvolvedCompanyResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Involvedcompanies) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Involvedcompanies, nil
|
||||
}
|
29
endpoint/keywords.go
Normal file
29
endpoint/keywords.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Keywords struct{ BaseEndpoint }
|
||||
|
||||
func (a *Keywords) Query(query string) ([]*pb.Keyword, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/keywords.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.KeywordResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Keywords) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Keywords, nil
|
||||
}
|
29
endpoint/language_support_types.go
Normal file
29
endpoint/language_support_types.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type LanguageSupportTypes struct{ BaseEndpoint }
|
||||
|
||||
func (a *LanguageSupportTypes) Query(query string) ([]*pb.LanguageSupportType, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/language_support_types.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.LanguageSupportTypeResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Languagesupporttypes) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Languagesupporttypes, nil
|
||||
}
|
29
endpoint/language_supports.go
Normal file
29
endpoint/language_supports.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type LanguageSupports struct{ BaseEndpoint }
|
||||
|
||||
func (a *LanguageSupports) Query(query string) ([]*pb.LanguageSupport, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/language_supports.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.LanguageSupportResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Languagesupports) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Languagesupports, nil
|
||||
}
|
29
endpoint/languages.go
Normal file
29
endpoint/languages.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Languages struct{ BaseEndpoint }
|
||||
|
||||
func (a *Languages) Query(query string) ([]*pb.Language, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/languages.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.LanguageResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Languages) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Languages, nil
|
||||
}
|
29
endpoint/multiplayer_modes.go
Normal file
29
endpoint/multiplayer_modes.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type MultiplayerModes struct{ BaseEndpoint }
|
||||
|
||||
func (a *MultiplayerModes) Query(query string) ([]*pb.MultiplayerMode, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/multiplayer_modes.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.MultiplayerModeResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Multiplayermodes) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Multiplayermodes, nil
|
||||
}
|
29
endpoint/network_types.go
Normal file
29
endpoint/network_types.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type NetworkTypes struct{ BaseEndpoint }
|
||||
|
||||
func (a *NetworkTypes) Query(query string) ([]*pb.NetworkType, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/network_types.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.NetworkTypeResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Networktypes) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Networktypes, nil
|
||||
}
|
29
endpoint/platform_families.go
Normal file
29
endpoint/platform_families.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type PlatformFamilies struct{ BaseEndpoint }
|
||||
|
||||
func (a *PlatformFamilies) Query(query string) ([]*pb.PlatformFamily, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/platform_families.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.PlatformFamilyResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Platformfamilies) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Platformfamilies, nil
|
||||
}
|
29
endpoint/platform_logos.go
Normal file
29
endpoint/platform_logos.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type PlatformLogos struct{ BaseEndpoint }
|
||||
|
||||
func (a *PlatformLogos) Query(query string) ([]*pb.PlatformLogo, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/platform_logos.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.PlatformLogoResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Platformlogos) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Platformlogos, nil
|
||||
}
|
29
endpoint/platform_types.go
Normal file
29
endpoint/platform_types.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type PlatformTypes struct{ BaseEndpoint }
|
||||
|
||||
func (a *PlatformTypes) Query(query string) ([]*pb.PlatformType, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/platform_types.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.PlatformTypeResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Platformtypes) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Platformtypes, nil
|
||||
}
|
29
endpoint/platform_version_companies.go
Normal file
29
endpoint/platform_version_companies.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type PlatformVersionCompanies struct{ BaseEndpoint }
|
||||
|
||||
func (a *PlatformVersionCompanies) Query(query string) ([]*pb.PlatformVersionCompany, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/platform_version_companies.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.PlatformVersionCompanyResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Platformversioncompanies) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Platformversioncompanies, nil
|
||||
}
|
29
endpoint/platform_version_release_dates.go
Normal file
29
endpoint/platform_version_release_dates.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type PlatformVersionReleaseDates struct{ BaseEndpoint }
|
||||
|
||||
func (a *PlatformVersionReleaseDates) Query(query string) ([]*pb.PlatformVersionReleaseDate, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/platform_version_release_dates.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.PlatformVersionReleaseDateResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Platformversionreleasedates) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Platformversionreleasedates, nil
|
||||
}
|
29
endpoint/platform_versions.go
Normal file
29
endpoint/platform_versions.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type PlatformVersions struct{ BaseEndpoint }
|
||||
|
||||
func (a *PlatformVersions) Query(query string) ([]*pb.PlatformVersion, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/platform_versions.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.PlatformVersionResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Platformversions) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Platformversions, nil
|
||||
}
|
29
endpoint/platform_websites.go
Normal file
29
endpoint/platform_websites.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type PlatformWebsites struct{ BaseEndpoint }
|
||||
|
||||
func (a *PlatformWebsites) Query(query string) ([]*pb.PlatformWebsite, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/platform_websites.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.PlatformWebsiteResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Platformwebsites) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Platformwebsites, nil
|
||||
}
|
28
endpoint/platforms.go
Normal file
28
endpoint/platforms.go
Normal file
@ -0,0 +1,28 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Platforms struct{ BaseEndpoint }
|
||||
|
||||
func (a *Platforms) Query(query string) ([]*pb.Platform, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/platforms.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.PlatformResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Platforms) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
return data.Platforms, nil
|
||||
}
|
29
endpoint/player_perspectives.go
Normal file
29
endpoint/player_perspectives.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type PlayerPerspectives struct{ BaseEndpoint }
|
||||
|
||||
func (a *PlayerPerspectives) Query(query string) ([]*pb.PlayerPerspective, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/player_perspectives.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.PlayerPerspectiveResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Playerperspectives) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Playerperspectives, nil
|
||||
}
|
29
endpoint/popularity_primitives.go
Normal file
29
endpoint/popularity_primitives.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type PopularityPrimitives struct{ BaseEndpoint }
|
||||
|
||||
func (a *PopularityPrimitives) Query(query string) ([]*pb.PopularityPrimitive, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/popularity_primitives.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.PopularityPrimitiveResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Popularityprimitives) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Popularityprimitives, nil
|
||||
}
|
29
endpoint/popularity_types.go
Normal file
29
endpoint/popularity_types.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type PopularityTypes struct{ BaseEndpoint }
|
||||
|
||||
func (a *PopularityTypes) Query(query string) ([]*pb.PopularityType, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/popularity_types.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.PopularityTypeResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Popularitytypes) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Popularitytypes, nil
|
||||
}
|
29
endpoint/regions.go
Normal file
29
endpoint/regions.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Regions struct{ BaseEndpoint }
|
||||
|
||||
func (a *Regions) Query(query string) ([]*pb.Region, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/regions.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.RegionResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Regions) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Regions, nil
|
||||
}
|
29
endpoint/release_date_regions.go
Normal file
29
endpoint/release_date_regions.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type ReleaseDateRegions struct{ BaseEndpoint }
|
||||
|
||||
func (a *ReleaseDateRegions) Query(query string) ([]*pb.ReleaseDateRegion, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/release_date_regions.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.ReleaseDateRegionResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Releasedateregions) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Releasedateregions, nil
|
||||
}
|
29
endpoint/release_date_statuses.go
Normal file
29
endpoint/release_date_statuses.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type ReleaseDateStatuses struct{ BaseEndpoint }
|
||||
|
||||
func (a *ReleaseDateStatuses) Query(query string) ([]*pb.ReleaseDateStatus, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/release_date_statuses.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.ReleaseDateStatusResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Releasedatestatuses) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Releasedatestatuses, nil
|
||||
}
|
29
endpoint/release_dates.go
Normal file
29
endpoint/release_dates.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type ReleaseDates struct{ BaseEndpoint }
|
||||
|
||||
func (a *ReleaseDates) Query(query string) ([]*pb.ReleaseDate, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/release_dates.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.ReleaseDateResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Releasedates) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Releasedates, nil
|
||||
}
|
29
endpoint/screenshots.go
Normal file
29
endpoint/screenshots.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Screenshots struct{ BaseEndpoint }
|
||||
|
||||
func (a *Screenshots) Query(query string) ([]*pb.Screenshot, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/screenshots.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.ScreenshotResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Screenshots) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Screenshots, nil
|
||||
}
|
109
endpoint/search.go
Normal file
109
endpoint/search.go
Normal file
@ -0,0 +1,109 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/bestnite/go-flaresolverr"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
var webSearchCFCookies struct {
|
||||
cookies []*http.Cookie
|
||||
expires time.Time
|
||||
}
|
||||
|
||||
type Search struct {
|
||||
BaseEndpoint
|
||||
flaresolverr *flaresolverr.Flaresolverr
|
||||
}
|
||||
|
||||
func (a *Search) Search(query string) ([]*pb.Search, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/search.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.SearchResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Searches) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Searches, nil
|
||||
}
|
||||
|
||||
func (a *Search) getFlaresolverr() (*flaresolverr.Flaresolverr, error) {
|
||||
if a.flaresolverr == nil {
|
||||
return nil, fmt.Errorf("flaresolverr is not initialized")
|
||||
}
|
||||
return a.flaresolverr, nil
|
||||
}
|
||||
|
||||
func (a *Search) WebSearchGameIDs(name string) ([]uint64, error) {
|
||||
params := url.Values{}
|
||||
params.Add("q", name)
|
||||
params.Add("utf8", "✓")
|
||||
Url := fmt.Sprintf("%s?%s", "https://www.igdb.com/search", params.Encode())
|
||||
|
||||
f, err := a.getFlaresolverr()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get flaresolverr: %w", err)
|
||||
}
|
||||
|
||||
var respBody io.Reader
|
||||
if webSearchCFCookies.cookies == nil || time.Now().After(webSearchCFCookies.expires) {
|
||||
resp, err := f.GetV1(Url, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to web search: %s: %w", name, err)
|
||||
}
|
||||
webSearchCFCookies.cookies = resp.Solution.Cookies
|
||||
webSearchCFCookies.expires = time.Now().Add(3 * time.Hour)
|
||||
respBody = strings.NewReader(resp.Solution.Response)
|
||||
} else if time.Now().Before(webSearchCFCookies.expires) {
|
||||
resp, err := f.SimulateGet(Url, &flaresolverr.SimulateOptions{
|
||||
HttpCookies: webSearchCFCookies.cookies,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to search IGDB ID: %s: %w", name, err)
|
||||
}
|
||||
respBody = strings.NewReader(resp.Body)
|
||||
}
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(respBody)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse IGDB web search response: %w", err)
|
||||
}
|
||||
selection := doc.Find("script[data-component-name='GameEntries']")
|
||||
if selection.Length() == 0 {
|
||||
return nil, fmt.Errorf("no search results found for: %s", name)
|
||||
}
|
||||
innerJson := selection.First().Text()
|
||||
data := struct {
|
||||
Games []struct {
|
||||
Id uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
} `json:"games"`
|
||||
}{}
|
||||
if err := json.Unmarshal([]byte(innerJson), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal IGDB web search response: %w", err)
|
||||
}
|
||||
|
||||
ids := make([]uint64, len(data.Games))
|
||||
for i, game := range data.Games {
|
||||
ids[i] = game.Id
|
||||
}
|
||||
|
||||
return ids, nil
|
||||
}
|
29
endpoint/themes.go
Normal file
29
endpoint/themes.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Themes struct{ BaseEndpoint }
|
||||
|
||||
func (a *Themes) Query(query string) ([]*pb.Theme, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/themes.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.ThemeResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Themes) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Themes, nil
|
||||
}
|
26
endpoint/webhooks.go
Normal file
26
endpoint/webhooks.go
Normal file
@ -0,0 +1,26 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type Webhooks struct{ BaseEndpoint }
|
||||
|
||||
func (a *Webhooks) Register(endpoint EndpointName, secret, callbackUrl string) error {
|
||||
dataBody := url.Values{}
|
||||
dataBody.Set("url", callbackUrl)
|
||||
dataBody.Set("secret", secret)
|
||||
dataBody.Set("method", "update")
|
||||
resp, err := a.request(fmt.Sprintf("https://api.igdb.com/v4/%s/webhooks/", endpoint), dataBody.Encode())
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to make request: %s: %w", callbackUrl, err)
|
||||
}
|
||||
|
||||
if resp.StatusCode() == http.StatusOK {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("failed to activate webhook: %s: %s", callbackUrl, resp.String())
|
||||
}
|
29
endpoint/website_types.go
Normal file
29
endpoint/website_types.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type WebsiteTypes struct{ BaseEndpoint }
|
||||
|
||||
func (a *WebsiteTypes) Query(query string) ([]*pb.WebsiteType, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/website_types.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.WebsiteTypeResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Websitetypes) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Websitetypes, nil
|
||||
}
|
29
endpoint/websites.go
Normal file
29
endpoint/websites.go
Normal file
@ -0,0 +1,29 @@
|
||||
package endpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/bestnite/go-igdb/proto"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Websites struct{ BaseEndpoint }
|
||||
|
||||
func (a *Websites) Query(query string) ([]*pb.Website, error) {
|
||||
resp, err := a.request("https://api.igdb.com/v4/websites.pb", query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to request: %w", err)
|
||||
}
|
||||
|
||||
data := pb.WebsiteResult{}
|
||||
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Websites) == 0 {
|
||||
return nil, fmt.Errorf("no results: %s", query)
|
||||
}
|
||||
|
||||
return data.Websites, nil
|
||||
}
|
Reference in New Issue
Block a user