diff --git a/README.md b/README.md index 8629aca..2a75bf2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ a go library to access IGDB API ```go g := igdb.New("clientID", "clientSecret") -game, err := g.GetGame(325594) +game, err := g.GetGameByID(325594) if err != nil { log.Fatal(err) } diff --git a/age_rating_categories.go b/age_rating_categories.go new file mode 100644 index 0000000..8991b52 --- /dev/null +++ b/age_rating_categories.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetAgeRatingCategories(query string) ([]*pb.AgeRatingCategory, error) { + resp, err := g.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 +} + +func (g *igdb) GetAgeRatingCategoryByID(id uint64) (*pb.AgeRatingCategory, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + ageRatingCategories, err := g.GetAgeRatingCategories(query) + if err != nil { + return nil, err + } + return ageRatingCategories[0], nil +} + +func (g *igdb) GetAgeRatingCategoriesByIDs(ids []uint64) ([]*pb.AgeRatingCategory, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetAgeRatingCategories(idStr) +} diff --git a/age_rating_content_descriptions.go b/age_rating_content_descriptions.go new file mode 100644 index 0000000..3ddb9b9 --- /dev/null +++ b/age_rating_content_descriptions.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetAgeRatingContentDescriptions(query string) ([]*pb.AgeRatingContentDescription, error) { + resp, err := g.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 +} + +func (g *igdb) GetAgeRatingContentDescriptionByID(id uint64) (*pb.AgeRatingContentDescription, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + ageRatingContentDescriptions, err := g.GetAgeRatingContentDescriptions(query) + if err != nil { + return nil, err + } + return ageRatingContentDescriptions[0], nil +} + +func (g *igdb) GetAgeRatingContentDescriptionsByIDs(ids []uint64) ([]*pb.AgeRatingContentDescription, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetAgeRatingContentDescriptions(idStr) +} diff --git a/age_rating_content_descriptions_v2.go b/age_rating_content_descriptions_v2.go new file mode 100644 index 0000000..2c1f743 --- /dev/null +++ b/age_rating_content_descriptions_v2.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetAgeRatingContentDescriptionsV2(query string) ([]*pb.AgeRatingContentDescriptionV2, error) { + resp, err := g.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 +} + +func (g *igdb) GetAgeRatingContentDescriptionV2ByID(id uint64) (*pb.AgeRatingContentDescriptionV2, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + ageRatingContentDescriptions, err := g.GetAgeRatingContentDescriptionsV2(query) + if err != nil { + return nil, err + } + return ageRatingContentDescriptions[0], nil +} + +func (g *igdb) GetAgeRatingContentDescriptionsV2ByIDs(ids []uint64) ([]*pb.AgeRatingContentDescriptionV2, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetAgeRatingContentDescriptionsV2(idStr) +} diff --git a/age_rating_organizations.go b/age_rating_organizations.go new file mode 100644 index 0000000..2943132 --- /dev/null +++ b/age_rating_organizations.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetAgeRatingOrganizations(query string) ([]*pb.AgeRatingOrganization, error) { + resp, err := g.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 +} + +func (g *igdb) GetAgeRatingOrganizationByID(id uint64) (*pb.AgeRatingOrganization, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + ageRatingOrganizations, err := g.GetAgeRatingOrganizations(query) + if err != nil { + return nil, err + } + return ageRatingOrganizations[0], nil +} + +func (g *igdb) GetAgeRatingOrganizationsByIDs(ids []uint64) ([]*pb.AgeRatingOrganization, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetAgeRatingOrganizations(idStr) +} diff --git a/age_ratings.go b/age_ratings.go new file mode 100644 index 0000000..0d03f5f --- /dev/null +++ b/age_ratings.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetAgeRatings(query string) ([]*pb.AgeRating, error) { + resp, err := g.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 +} + +func (g *igdb) GetAgeRatingByID(id uint64) (*pb.AgeRating, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + ageRatings, err := g.GetAgeRatings(query) + if err != nil { + return nil, err + } + return ageRatings[0], nil +} + +func (g *igdb) GetAgeRatingsByIDs(ids []uint64) ([]*pb.AgeRating, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetAgeRatings(idStr) +} diff --git a/alternative_names.go b/alternative_names.go new file mode 100644 index 0000000..8592c15 --- /dev/null +++ b/alternative_names.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetAlternativeNames(query string) ([]*pb.AlternativeName, error) { + resp, err := g.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 +} + +func (g *igdb) GetAlternativeNameByID(id uint64) (*pb.AlternativeName, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + alternativeNames, err := g.GetAlternativeNames(query) + if err != nil { + return nil, err + } + return alternativeNames[0], nil +} + +func (g *igdb) GetAlternativeNamesByIDs(ids []uint64) ([]*pb.AlternativeName, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetAlternativeNames(idStr) +} diff --git a/artworks.go b/artworks.go new file mode 100644 index 0000000..f0e70ab --- /dev/null +++ b/artworks.go @@ -0,0 +1,48 @@ +package igdb + +import ( + "fmt" + "strings" + + pb "github/bestnite/go-igdb/proto" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetArtworks(query string) ([]*pb.Artwork, error) { + resp, err := g.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 +} + +func (g *igdb) GetArtworkByID(id uint64) (*pb.Artwork, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + artworks, err := g.GetArtworks(query) + if err != nil { + return nil, err + } + return artworks[0], nil +} + +func (g *igdb) GetArtworksByIDs(ids []uint64) ([]*pb.Artwork, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetArtworks(idStr) +} diff --git a/character_genders.go b/character_genders.go new file mode 100644 index 0000000..09f19c0 --- /dev/null +++ b/character_genders.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetCharacterGenders(query string) ([]*pb.CharacterGender, error) { + resp, err := g.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 +} + +func (g *igdb) GetCharacterGenderByID(id uint64) (*pb.CharacterGender, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + characterGenders, err := g.GetCharacterGenders(query) + if err != nil { + return nil, err + } + return characterGenders[0], nil +} + +func (g *igdb) GetCharacterGendersByIDs(ids []uint64) ([]*pb.CharacterGender, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetCharacterGenders(idStr) +} diff --git a/character_mug_shots.go b/character_mug_shots.go new file mode 100644 index 0000000..dc4adcb --- /dev/null +++ b/character_mug_shots.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetCharacterMugShots(query string) ([]*pb.CharacterMugShot, error) { + resp, err := g.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 +} + +func (g *igdb) GetCharacterMugShotByID(id uint64) (*pb.CharacterMugShot, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + characterMugShots, err := g.GetCharacterMugShots(query) + if err != nil { + return nil, err + } + return characterMugShots[0], nil +} + +func (g *igdb) GetCharacterMugShotsByIDs(ids []uint64) ([]*pb.CharacterMugShot, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetCharacterMugShots(idStr) +} diff --git a/character_species.go b/character_species.go new file mode 100644 index 0000000..4a30ccb --- /dev/null +++ b/character_species.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetCharacterSpecies(query string) ([]*pb.CharacterSpecie, error) { + resp, err := g.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 +} + +func (g *igdb) GetCharacterSpecieByID(id uint64) (*pb.CharacterSpecie, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + characterSpecies, err := g.GetCharacterSpecies(query) + if err != nil { + return nil, err + } + return characterSpecies[0], nil +} + +func (g *igdb) GetCharacterSpeciesByIDs(ids []uint64) ([]*pb.CharacterSpecie, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetCharacterSpecies(idStr) +} diff --git a/characters.go b/characters.go new file mode 100644 index 0000000..94ae041 --- /dev/null +++ b/characters.go @@ -0,0 +1,48 @@ +package igdb + +import ( + "fmt" + "strings" + + pb "github/bestnite/go-igdb/proto" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetCharacters(query string) ([]*pb.Character, error) { + resp, err := g.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 +} + +func (g *igdb) GetCharacterByID(id uint64) (*pb.Character, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + characters, err := g.GetCharacters(query) + if err != nil { + return nil, err + } + return characters[0], nil +} + +func (g *igdb) GetCharactersByIDs(ids []uint64) ([]*pb.Character, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetCharacters(idStr) +} diff --git a/collection_membership_types.go b/collection_membership_types.go new file mode 100644 index 0000000..162f78c --- /dev/null +++ b/collection_membership_types.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetCollectionMembershipTypes(query string) ([]*pb.CollectionMembershipType, error) { + resp, err := g.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 +} + +func (g *igdb) GetCollectionMembershipTypeByID(id uint64) (*pb.CollectionMembershipType, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + collectionMembershipTypes, err := g.GetCollectionMembershipTypes(query) + if err != nil { + return nil, err + } + return collectionMembershipTypes[0], nil +} + +func (g *igdb) GetCollectionMembershipTypesByIDs(ids []uint64) ([]*pb.CollectionMembershipType, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetCollectionMembershipTypes(idStr) +} diff --git a/collection_memberships.go b/collection_memberships.go new file mode 100644 index 0000000..88b15cf --- /dev/null +++ b/collection_memberships.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetCollectionMemberships(query string) ([]*pb.CollectionMembership, error) { + resp, err := g.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 +} + +func (g *igdb) GetCollectionMembershipByID(id uint64) (*pb.CollectionMembership, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + collectionMemberships, err := g.GetCollectionMemberships(query) + if err != nil { + return nil, err + } + return collectionMemberships[0], nil +} + +func (g *igdb) GetCollectionMembershipsByIDs(ids []uint64) ([]*pb.CollectionMembership, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetCollectionMemberships(idStr) +} diff --git a/collection_relation_types.go b/collection_relation_types.go new file mode 100644 index 0000000..b61b1f4 --- /dev/null +++ b/collection_relation_types.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetCollectionRelationTypes(query string) ([]*pb.CollectionRelationType, error) { + resp, err := g.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 +} + +func (g *igdb) GetCollectionRelationTypeByID(id uint64) (*pb.CollectionRelationType, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + collectionRelationTypes, err := g.GetCollectionRelationTypes(query) + if err != nil { + return nil, err + } + return collectionRelationTypes[0], nil +} + +func (g *igdb) GetCollectionRelationTypesByIDs(ids []uint64) ([]*pb.CollectionRelationType, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetCollectionRelationTypes(idStr) +} diff --git a/collection_relations.go b/collection_relations.go new file mode 100644 index 0000000..af314e9 --- /dev/null +++ b/collection_relations.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetCollectionRelations(query string) ([]*pb.CollectionRelation, error) { + resp, err := g.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 +} + +func (g *igdb) GetCollectionRelationByID(id uint64) (*pb.CollectionRelation, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + collectionRelations, err := g.GetCollectionRelations(query) + if err != nil { + return nil, err + } + return collectionRelations[0], nil +} + +func (g *igdb) GetCollectionRelationsByIDs(ids []uint64) ([]*pb.CollectionRelation, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetCollectionRelations(idStr) +} diff --git a/collection_types.go b/collection_types.go new file mode 100644 index 0000000..b85606d --- /dev/null +++ b/collection_types.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetCollectionTypes(query string) ([]*pb.CollectionType, error) { + resp, err := g.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 +} + +func (g *igdb) GetCollectionTypeByID(id uint64) (*pb.CollectionType, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + collectionTypes, err := g.GetCollectionTypes(query) + if err != nil { + return nil, err + } + return collectionTypes[0], nil +} + +func (g *igdb) GetCollectionTypesByIDs(ids []uint64) ([]*pb.CollectionType, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetCollectionTypes(idStr) +} diff --git a/collections.go b/collections.go new file mode 100644 index 0000000..9a8b11a --- /dev/null +++ b/collections.go @@ -0,0 +1,48 @@ +package igdb + +import ( + "fmt" + "strings" + + pb "github/bestnite/go-igdb/proto" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetCollections(query string) ([]*pb.Collection, error) { + resp, err := g.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 +} + +func (g *igdb) GetCollectionByID(id uint64) (*pb.Collection, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + collections, err := g.GetCollections(query) + if err != nil { + return nil, err + } + return collections[0], nil +} + +func (g *igdb) GetCollectionsByIDs(ids []uint64) ([]*pb.Collection, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetCollections(idStr) +} diff --git a/companies.go b/companies.go new file mode 100644 index 0000000..83e069c --- /dev/null +++ b/companies.go @@ -0,0 +1,49 @@ +package igdb + +import ( + "errors" + "fmt" + "strings" + + pb "github/bestnite/go-igdb/proto" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetCompanies(query string) ([]*pb.Company, error) { + resp, err := g.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 +} + +func (g *igdb) GetCompanyByID(id uint64) (*pb.Company, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + companys, err := g.GetCompanies(query) + if err != nil { + return nil, err + } + return companys[0], nil +} + +func (g *igdb) GetCompanyByIDs(ids []uint64) ([]*pb.Company, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetCompanies(idStr) +} diff --git a/company.go b/company.go deleted file mode 100644 index 637aa7e..0000000 --- a/company.go +++ /dev/null @@ -1,30 +0,0 @@ -package igdb - -import ( - "errors" - "fmt" - "github/bestnite/go-igdb/constant" - - pb "github/bestnite/go-igdb/proto" - - "google.golang.org/protobuf/proto" -) - -func (g *igdb) GetIGDBCompany(id uint64) (*pb.Company, error) { - query := fmt.Sprintf(`where id=%d; fields *;`, id) - resp, err := g.Request(constant.IGDBCompaniesURL, query) - if err != nil { - return nil, fmt.Errorf("failed to fetch IGDB company for ID %d: %w", id, err) - } - - var data pb.CompanyResult - if err = proto.Unmarshal(resp.Body(), &data); err != nil { - return nil, fmt.Errorf("failed to unmarshal IGDB companies response: %w", err) - } - - if len(data.Companies) == 0 { - return nil, errors.New("company not found") - } - - return data.Companies[0], nil -} diff --git a/company_logos.go b/company_logos.go new file mode 100644 index 0000000..159df29 --- /dev/null +++ b/company_logos.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetCompanyLogos(query string) ([]*pb.CompanyLogo, error) { + resp, err := g.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 +} + +func (g *igdb) GetCompanyLogoByID(id uint64) (*pb.CompanyLogo, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + companyLogos, err := g.GetCompanyLogos(query) + if err != nil { + return nil, err + } + return companyLogos[0], nil +} + +func (g *igdb) GetCompanyLogosByIDs(ids []uint64) ([]*pb.CompanyLogo, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetCompanyLogos(idStr) +} diff --git a/company_statuses.go b/company_statuses.go new file mode 100644 index 0000000..526b908 --- /dev/null +++ b/company_statuses.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetCompanyStatuses(query string) ([]*pb.CompanyStatus, error) { + resp, err := g.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 +} + +func (g *igdb) GetCompanyStatusByID(id uint64) (*pb.CompanyStatus, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + companyStatuses, err := g.GetCompanyStatuses(query) + if err != nil { + return nil, err + } + return companyStatuses[0], nil +} + +func (g *igdb) GetCompanyStatusesByIDs(ids []uint64) ([]*pb.CompanyStatus, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetCompanyStatuses(idStr) +} diff --git a/company_websites.go b/company_websites.go new file mode 100644 index 0000000..9926a02 --- /dev/null +++ b/company_websites.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetCompanyWebsites(query string) ([]*pb.CompanyWebsite, error) { + resp, err := g.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 +} + +func (g *igdb) GetCompanyWebsiteByID(id uint64) (*pb.CompanyWebsite, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + companyWebsites, err := g.GetCompanyWebsites(query) + if err != nil { + return nil, err + } + return companyWebsites[0], nil +} + +func (g *igdb) GetCompanyWebsitesByIDs(ids []uint64) ([]*pb.CompanyWebsite, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetCompanyWebsites(idStr) +} diff --git a/constant/url.go b/constant/url.go deleted file mode 100644 index d4ef4b8..0000000 --- a/constant/url.go +++ /dev/null @@ -1,12 +0,0 @@ -package constant - -const ( - IGDBGameURL = "https://api.igdb.com/v4/games.pb" - IGDBCompaniesURL = "https://api.igdb.com/v4/companies.pb" - IGDBWebsitesURL = "https://api.igdb.com/v4/websites.pb" - IGDBExternalGameURL = "https://api.igdb.com/v4/external_games.pb" - IGDBPopularityURL = "https://api.igdb.com/v4/popularity_primitives.pb" - IGDBWebhookURL = "https://api.igdb.com/v4/%s/webhooks/" - IGDBWebSearchURL = "https://www.igdb.com/search" - TwitchAuthURL = "https://id.twitch.tv/oauth2/token" -) diff --git a/covers.go b/covers.go new file mode 100644 index 0000000..1d285ce --- /dev/null +++ b/covers.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetCovers(query string) ([]*pb.Cover, error) { + resp, err := g.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 +} + +func (g *igdb) GetCoverByID(id uint64) (*pb.Cover, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + covers, err := g.GetCovers(query) + if err != nil { + return nil, err + } + return covers[0], nil +} + +func (g *igdb) GetCoversByIDs(ids []uint64) ([]*pb.Cover, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetCovers(idStr) +} diff --git a/date_formats.go b/date_formats.go new file mode 100644 index 0000000..8dd2f87 --- /dev/null +++ b/date_formats.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetDateFormats(query string) ([]*pb.DateFormat, error) { + resp, err := g.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 +} + +func (g *igdb) GetDateFormatByID(id uint64) (*pb.DateFormat, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + dateFormats, err := g.GetDateFormats(query) + if err != nil { + return nil, err + } + return dateFormats[0], nil +} + +func (g *igdb) GetDateFormatsByIDs(ids []uint64) ([]*pb.DateFormat, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetDateFormats(idStr) +} diff --git a/endpoint/endpoint.go b/endpoint/endpoint.go new file mode 100644 index 0000000..927a032 --- /dev/null +++ b/endpoint/endpoint.go @@ -0,0 +1,77 @@ +package endpoint + +type Endpoint string + +var ( + AgeRatingCategories Endpoint = "age_rating_categories" + AgeRatingContentDescriptions = "age_rating_content_descriptions" + AgeRatingContentDescriptionsV2 = "age_rating_content_descriptions_v2" + AgeRatingOrganizations = "age_rating_organizations" + AgeRatings = "age_ratings" + AlternativeNames = "alternative_names" + Artworks = "artworks" + CharacterGenders = "character_genders" + CharacterMugShots = "character_mug_shots" + Characters = "characters" + CharacterSpecies = "character_species" + CollectionMemberships = "collection_memberships" + CollectionMembershipTypes = "collection_membership_types" + CollectionRelations = "collection_relations" + CollectionRelationTypes = "collection_relation_types" + Collections = "collections" + CollectionTypes = "collection_types" + Companies = "companies" + CompanyLogos = "company_logos" + CompanyStatuses = "company_statuses" + CompanyWebsites = "company_websites" + Covers = "covers" + DateFormats = "date_formats" + EventLogos = "event_logos" + EventNetworks = "event_networks" + Events = "events" + ExternalGames = "external_games" + ExternalGameSources = "external_game_sources" + Franchises = "franchises" + GameEngineLogos = "game_engine_logos" + GameEngines = "game_engines" + GameLocalizations = "game_localizations" + GameModes = "game_modes" + GameReleaseFormats = "game_release_formats" + Games = "games" + GameStatuses = "game_statuses" + GameTimeToBeats = "game_time_to_beats" + GameTypes = "game_types" + GameVersionFeatures = "game_version_features" + GameVersionFeatureValues = "game_version_feature_values" + GameVersions = "game_versions" + GameVideos = "game_videos" + Genres = "genres" + InvolvedCompanies = "involved_companies" + Keywords = "keywords" + Languages = "languages" + LanguageSupports = "language_supports" + LanguageSupportTypes = "language_support_types" + MultiplayerModes = "multiplayer_modes" + NetworkTypes = "network_types" + PlatformFamilies = "platform_families" + PlatformLogos = "platform_logos" + Platforms = "platforms" + PlatformTypes = "platform_types" + PlatformVersionCompanies = "platform_version_companies" + PlatformVersionReleaseDates = "platform_version_release_dates" + PlatformVersions = "platform_versions" + PlatformWebsites = "platform_websites" + PlayerPerspectives = "player_perspectives" + PopularityPrimitives = "popularity_primitives" + PopularityTypes = "popularity_types" + Regions = "regions" + ReleaseDateRegions = "release_date_regions" + ReleaseDates = "release_dates" + ReleaseDateStatuses = "release_date_statuses" + Screenshots = "screenshots" + Search = "search" + Themes = "themes" + Webhooks = "webhooks" + Websites = "websites" + WebsiteTypes = "website_types" +) diff --git a/event_logos.go b/event_logos.go new file mode 100644 index 0000000..2adfd7b --- /dev/null +++ b/event_logos.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetEventLogos(query string) ([]*pb.EventLogo, error) { + resp, err := g.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 +} + +func (g *igdb) GetEventLogoByID(id uint64) (*pb.EventLogo, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + eventLogos, err := g.GetEventLogos(query) + if err != nil { + return nil, err + } + return eventLogos[0], nil +} + +func (g *igdb) GetEventLogosByIDs(ids []uint64) ([]*pb.EventLogo, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetEventLogos(idStr) +} diff --git a/event_networks.go b/event_networks.go new file mode 100644 index 0000000..8ab2214 --- /dev/null +++ b/event_networks.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetEventNetworks(query string) ([]*pb.EventNetwork, error) { + resp, err := g.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 +} + +func (g *igdb) GetEventNetworkByID(id uint64) (*pb.EventNetwork, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + eventNetworks, err := g.GetEventNetworks(query) + if err != nil { + return nil, err + } + return eventNetworks[0], nil +} + +func (g *igdb) GetEventNetworksByIDs(ids []uint64) ([]*pb.EventNetwork, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetEventNetworks(idStr) +} diff --git a/events.go b/events.go new file mode 100644 index 0000000..154b821 --- /dev/null +++ b/events.go @@ -0,0 +1,48 @@ +package igdb + +import ( + "fmt" + "strings" + + pb "github/bestnite/go-igdb/proto" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetEvents(query string) ([]*pb.Event, error) { + resp, err := g.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 +} + +func (g *igdb) GetEventByID(id uint64) (*pb.Event, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + events, err := g.GetEvents(query) + if err != nil { + return nil, err + } + return events[0], nil +} + +func (g *igdb) GetEventsByIDs(ids []uint64) ([]*pb.Event, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetEvents(idStr) +} diff --git a/external_game_sources.go b/external_game_sources.go new file mode 100644 index 0000000..15a75eb --- /dev/null +++ b/external_game_sources.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetExternalGameSources(query string) ([]*pb.ExternalGameSource, error) { + resp, err := g.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 +} + +func (g *igdb) GetExternalGameSourceByID(id uint64) (*pb.ExternalGameSource, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + externalGameSources, err := g.GetExternalGameSources(query) + if err != nil { + return nil, err + } + return externalGameSources[0], nil +} + +func (g *igdb) GetExternalGameSourcesByIDs(ids []uint64) ([]*pb.ExternalGameSource, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetExternalGameSources(idStr) +} diff --git a/external_games.go b/external_games.go new file mode 100644 index 0000000..b353cbb --- /dev/null +++ b/external_games.go @@ -0,0 +1,66 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strconv" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetExternalGames(query string) ([]*pb.ExternalGame, error) { + resp, err := g.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 +} + +func (g *igdb) GetExternalGameByID(id uint64) (*pb.ExternalGame, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + externalGames, err := g.GetExternalGames(query) + if err != nil { + return nil, err + } + return externalGames[0], nil +} + +func (g *igdb) GetExternalGamesByIDs(ids []uint64) ([]*pb.ExternalGame, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetExternalGames(idStr) +} + +func (g *igdb) GetGameIDBySteamAppID(id uint64) (uint64, error) { + query := fmt.Sprintf(`where game_type.id = 0 & uid = "%d"; fields game;`, id) + externalGames, err := g.GetExternalGames(query) + if err != nil { + return 0, err + } + return externalGames[0].Game.Id, nil +} + +func (g *igdb) GetSteamIDByGameID(id uint64) (uint64, error) { + query := fmt.Sprintf(`where game = %v & game_type.id = 0; fields *;`, id) + externalGames, err := g.GetExternalGames(query) + if err != nil { + return 0, err + } + return strconv.ParseUint(externalGames[0].Uid, 10, 64) +} diff --git a/franchises.go b/franchises.go new file mode 100644 index 0000000..4dbee87 --- /dev/null +++ b/franchises.go @@ -0,0 +1,48 @@ +package igdb + +import ( + "fmt" + "strings" + + pb "github/bestnite/go-igdb/proto" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetFranchises(query string) ([]*pb.Franchise, error) { + resp, err := g.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 +} + +func (g *igdb) GetFranchiseByID(id uint64) (*pb.Franchise, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + franchises, err := g.GetFranchises(query) + if err != nil { + return nil, err + } + return franchises[0], nil +} + +func (g *igdb) GetFranchisesByIDs(ids []uint64) ([]*pb.Franchise, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetFranchises(idStr) +} diff --git a/game.go b/game.go deleted file mode 100644 index 1858ef0..0000000 --- a/game.go +++ /dev/null @@ -1,63 +0,0 @@ -package igdb - -import ( - "fmt" - "github/bestnite/go-igdb/constant" - "strconv" - "strings" - - pb "github/bestnite/go-igdb/proto" - - "google.golang.org/protobuf/proto" -) - -func (g *igdb) GetGame(id uint64) (*pb.Game, error) { - resp, err := g.Request(constant.IGDBGameURL, fmt.Sprintf(`where id = %v; fields *, age_ratings.*, alternative_names.*, artworks.*, collection.*, cover.*, external_games.*, external_games.platform.* , franchise.*, game_engines.*, game_engines.logo.*, game_engines.companies.* , game_modes.*, genres.*, involved_companies.*, involved_companies.company.* , keywords.*, multiplayer_modes.*, multiplayer_modes.platform.*, platforms.*, platforms.platform_logo.*, platforms.platform_family.*, platforms.versions.*, platforms.websites.* , player_perspectives.*, release_dates.*, release_dates.platform.*, release_dates.status.* , screenshots.*, themes.*, videos.*, websites.*, language_supports.*, language_supports.language.*, language_supports.language_support_type.* , game_localizations.*, game_localizations.region.* , collections.*, collections.type.*, collections.as_parent_relations.child_collection.*, collections.as_parent_relations.parent_collection.*, collections.as_parent_relations.type.*,collections.as_child_relations.child_collection.*, collections.as_child_relations.parent_collection.*, collections.as_child_relations.type.*, age_ratings.content_descriptions.*, cover.game_localization.*;`, id)) - if err != nil { - return nil, fmt.Errorf("failed to fetch game detail for ID %d: %w", id, err) - } - - res := pb.GameResult{} - if err = proto.Unmarshal(resp.Body(), &res); err != nil { - return nil, fmt.Errorf("failed to unmarshal game detail response: %w", err) - } - - if len(res.Games) == 0 { - return nil, fmt.Errorf("failed to fetch game detail for ID %d", id) - } - - if res.Games[0].Name == "" { - return g.GetGame(id) - } - - return res.Games[0], nil -} - -func (g *igdb) GetGames(ids []uint64) ([]*pb.Game, error) { - idStrSlice := make([]string, len(ids)) - for i, id := range ids { - idStrSlice[i] = strconv.FormatUint(id, 10) - } - - idStr := strings.Join(idStrSlice, ",") - - resp, err := g.Request(constant.IGDBGameURL, fmt.Sprintf(`where id = (%s); fields *, age_ratings.*, alternative_names.*, artworks.*, collection.*, cover.*, external_games.*, external_games.platform.* , franchise.*, game_engines.*, game_engines.logo.*, game_engines.companies.* , game_modes.*, genres.*, involved_companies.*, involved_companies.company.* , keywords.*, multiplayer_modes.*, multiplayer_modes.platform.*, platforms.*, platforms.platform_logo.*, platforms.platform_family.*, platforms.versions.*, platforms.websites.* , player_perspectives.*, release_dates.*, release_dates.platform.*, release_dates.status.* , screenshots.*, themes.*, videos.*, websites.*, language_supports.*, language_supports.language.*, language_supports.language_support_type.* , game_localizations.*, game_localizations.region.* , collections.*, collections.type.*, collections.as_parent_relations.child_collection.*, collections.as_parent_relations.parent_collection.*, collections.as_parent_relations.type.*,collections.as_child_relations.child_collection.*, collections.as_child_relations.parent_collection.*, collections.as_child_relations.type.*, age_ratings.content_descriptions.*, cover.game_localization.*;`, idStr)) - if err != nil { - return nil, fmt.Errorf("failed to fetch IGDB games detail for ID %s: %w", idStr, err) - } - - res := pb.GameResult{} - if err = proto.Unmarshal(resp.Body(), &res); err != nil { - return nil, fmt.Errorf("failed to unmarshal IGDB games detail response: %w", err) - } - - if len(res.Games) == 0 { - return nil, fmt.Errorf("failed to fetch IGDB games detail for ID %s", idStr) - } - - if res.Games[0].Name == "" { - return g.GetGames(ids) - } - - return res.Games, nil -} diff --git a/game_engine_logos.go b/game_engine_logos.go new file mode 100644 index 0000000..176f035 --- /dev/null +++ b/game_engine_logos.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetGameEngineLogos(query string) ([]*pb.GameEngineLogo, error) { + resp, err := g.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 +} + +func (g *igdb) GetGameEngineLogoByID(id uint64) (*pb.GameEngineLogo, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + gameEngineLogos, err := g.GetGameEngineLogos(query) + if err != nil { + return nil, err + } + return gameEngineLogos[0], nil +} + +func (g *igdb) GetGameEngineLogosByIDs(ids []uint64) ([]*pb.GameEngineLogo, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetGameEngineLogos(idStr) +} diff --git a/game_engines.go b/game_engines.go new file mode 100644 index 0000000..7cb8012 --- /dev/null +++ b/game_engines.go @@ -0,0 +1,48 @@ +package igdb + +import ( + "fmt" + "strings" + + pb "github/bestnite/go-igdb/proto" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetGameEngines(query string) ([]*pb.GameEngine, error) { + resp, err := g.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 +} + +func (g *igdb) GetGameEngineByID(id uint64) (*pb.GameEngine, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + gameEngines, err := g.GetGameEngines(query) + if err != nil { + return nil, err + } + return gameEngines[0], nil +} + +func (g *igdb) GetGameEnginesByIDs(ids []uint64) ([]*pb.GameEngine, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetGameEngines(idStr) +} diff --git a/game_localizations.go b/game_localizations.go new file mode 100644 index 0000000..1d1a51d --- /dev/null +++ b/game_localizations.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetGameLocalizations(query string) ([]*pb.GameLocalization, error) { + resp, err := g.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 +} + +func (g *igdb) GetGameLocalizationByID(id uint64) (*pb.GameLocalization, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + gameLocalizations, err := g.GetGameLocalizations(query) + if err != nil { + return nil, err + } + return gameLocalizations[0], nil +} + +func (g *igdb) GetGameLocalizationsByIDs(ids []uint64) ([]*pb.GameLocalization, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetGameLocalizations(idStr) +} diff --git a/game_modes.go b/game_modes.go new file mode 100644 index 0000000..1468438 --- /dev/null +++ b/game_modes.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetGameModes(query string) ([]*pb.GameMode, error) { + resp, err := g.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 +} + +func (g *igdb) GetGameModeByID(id uint64) (*pb.GameMode, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + gameModes, err := g.GetGameModes(query) + if err != nil { + return nil, err + } + return gameModes[0], nil +} + +func (g *igdb) GetGameModesByIDs(ids []uint64) ([]*pb.GameMode, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetGameModes(idStr) +} diff --git a/game_release_formats.go b/game_release_formats.go new file mode 100644 index 0000000..3b27152 --- /dev/null +++ b/game_release_formats.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetGameReleaseFormats(query string) ([]*pb.GameReleaseFormat, error) { + resp, err := g.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 +} + +func (g *igdb) GetGameReleaseFormatByID(id uint64) (*pb.GameReleaseFormat, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + gameReleaseFormats, err := g.GetGameReleaseFormats(query) + if err != nil { + return nil, err + } + return gameReleaseFormats[0], nil +} + +func (g *igdb) GetGameReleaseFormatsByIDs(ids []uint64) ([]*pb.GameReleaseFormat, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetGameReleaseFormats(idStr) +} diff --git a/game_statuses.go b/game_statuses.go new file mode 100644 index 0000000..4592f6e --- /dev/null +++ b/game_statuses.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetGameStatuses(query string) ([]*pb.GameStatus, error) { + resp, err := g.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 +} + +func (g *igdb) GetGameStatusByID(id uint64) (*pb.GameStatus, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + gameStatuses, err := g.GetGameStatuses(query) + if err != nil { + return nil, err + } + return gameStatuses[0], nil +} + +func (g *igdb) GetGameStatusesByIDs(ids []uint64) ([]*pb.GameStatus, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetGameStatuses(idStr) +} diff --git a/game_time_to_beats.go b/game_time_to_beats.go new file mode 100644 index 0000000..1463dd7 --- /dev/null +++ b/game_time_to_beats.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetGameTimeToBeats(query string) ([]*pb.GameTimeToBeat, error) { + resp, err := g.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 +} + +func (g *igdb) GetGameTimeToBeatByID(id uint64) (*pb.GameTimeToBeat, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + gameTimeToBeats, err := g.GetGameTimeToBeats(query) + if err != nil { + return nil, err + } + return gameTimeToBeats[0], nil +} + +func (g *igdb) GetGameTimeToBeatsByIDs(ids []uint64) ([]*pb.GameTimeToBeat, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetGameTimeToBeats(idStr) +} diff --git a/game_types.go b/game_types.go new file mode 100644 index 0000000..53b64e7 --- /dev/null +++ b/game_types.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetGameTypes(query string) ([]*pb.GameType, error) { + resp, err := g.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 +} + +func (g *igdb) GetGameTypeByID(id uint64) (*pb.GameType, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + gameTypes, err := g.GetGameTypes(query) + if err != nil { + return nil, err + } + return gameTypes[0], nil +} + +func (g *igdb) GetGameTypesByIDs(ids []uint64) ([]*pb.GameType, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetGameTypes(idStr) +} diff --git a/game_version_feature_values.go b/game_version_feature_values.go new file mode 100644 index 0000000..990f233 --- /dev/null +++ b/game_version_feature_values.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetGameVersionFeatureValues(query string) ([]*pb.GameVersionFeatureValue, error) { + resp, err := g.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 +} + +func (g *igdb) GetGameVersionFeatureValueByID(id uint64) (*pb.GameVersionFeatureValue, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + gameVersionFeatureValues, err := g.GetGameVersionFeatureValues(query) + if err != nil { + return nil, err + } + return gameVersionFeatureValues[0], nil +} + +func (g *igdb) GetGameVersionFeatureValuesByIDs(ids []uint64) ([]*pb.GameVersionFeatureValue, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetGameVersionFeatureValues(idStr) +} diff --git a/game_version_features.go b/game_version_features.go new file mode 100644 index 0000000..6ba0c6c --- /dev/null +++ b/game_version_features.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetGameVersionFeatures(query string) ([]*pb.GameVersionFeature, error) { + resp, err := g.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 +} + +func (g *igdb) GetGameVersionFeatureByID(id uint64) (*pb.GameVersionFeature, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + gameVersionFeatures, err := g.GetGameVersionFeatures(query) + if err != nil { + return nil, err + } + return gameVersionFeatures[0], nil +} + +func (g *igdb) GetGameVersionFeaturesByIDs(ids []uint64) ([]*pb.GameVersionFeature, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetGameVersionFeatures(idStr) +} diff --git a/game_versions.go b/game_versions.go new file mode 100644 index 0000000..5e7ae09 --- /dev/null +++ b/game_versions.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetGameVersions(query string) ([]*pb.GameVersion, error) { + resp, err := g.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 +} + +func (g *igdb) GetGameVersionByID(id uint64) (*pb.GameVersion, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + gameVersions, err := g.GetGameVersions(query) + if err != nil { + return nil, err + } + return gameVersions[0], nil +} + +func (g *igdb) GetGameVersionsByIDs(ids []uint64) ([]*pb.GameVersion, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetGameVersions(idStr) +} diff --git a/game_videos.go b/game_videos.go new file mode 100644 index 0000000..a1e7bf2 --- /dev/null +++ b/game_videos.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetGameVideos(query string) ([]*pb.GameVideo, error) { + resp, err := g.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 +} + +func (g *igdb) GetGameVideoByID(id uint64) (*pb.GameVideo, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + gameVideos, err := g.GetGameVideos(query) + if err != nil { + return nil, err + } + return gameVideos[0], nil +} + +func (g *igdb) GetGameVideosByIDs(ids []uint64) ([]*pb.GameVideo, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetGameVideos(idStr) +} diff --git a/games.go b/games.go new file mode 100644 index 0000000..9a03f90 --- /dev/null +++ b/games.go @@ -0,0 +1,48 @@ +package igdb + +import ( + "fmt" + "strings" + + pb "github/bestnite/go-igdb/proto" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetGames(query string) ([]*pb.Game, error) { + resp, err := g.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 +} + +func (g *igdb) GetGameByID(id uint64) (*pb.Game, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + games, err := g.GetGames(query) + if err != nil { + return nil, err + } + return games[0], nil +} + +func (g *igdb) GetGameByIDs(ids []uint64) ([]*pb.Game, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetGames(idStr) +} diff --git a/genres.go b/genres.go new file mode 100644 index 0000000..930cca5 --- /dev/null +++ b/genres.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetGenres(query string) ([]*pb.Genre, error) { + resp, err := g.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 +} + +func (g *igdb) GetGenreByID(id uint64) (*pb.Genre, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + genres, err := g.GetGenres(query) + if err != nil { + return nil, err + } + return genres[0], nil +} + +func (g *igdb) GetGenresByIDs(ids []uint64) ([]*pb.Genre, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetGenres(idStr) +} diff --git a/id.go b/id.go deleted file mode 100644 index 808599c..0000000 --- a/id.go +++ /dev/null @@ -1,49 +0,0 @@ -package igdb - -import ( - "errors" - "fmt" - "github/bestnite/go-igdb/constant" - pb "github/bestnite/go-igdb/proto" - "strconv" - - "google.golang.org/protobuf/proto" -) - -func (g *igdb) GetGameIDBySteamAppID(id uint64) (uint64, error) { - query := fmt.Sprintf(`where game_type.id = 0 & uid = "%d"; fields game;`, id) - resp, err := g.Request(constant.IGDBExternalGameURL, query) - if err != nil { - return 0, fmt.Errorf("failed to fetch IGDB ID by Steam App ID %d: %w", id, err) - } - - res := pb.ExternalGameResult{} - if err = proto.Unmarshal(resp.Body(), &res); err != nil { - return 0, fmt.Errorf("failed to unmarshal IGDB response for Steam App ID %d: %w", id, err) - } - - if len(res.Externalgames) == 0 || res.Externalgames[0].Game.Id == 0 { - return 0, errors.New("no matching IGDB game found") - } - - return res.Externalgames[0].Game.Id, nil -} - -func (g *igdb) GetSteamIDByGameID(id uint64) (uint64, error) { - query := fmt.Sprintf(`where game = %v & game_type.id = 0; fields *;`, id) - resp, err := g.Request(constant.IGDBExternalGameURL, query) - if err != nil { - return 0, fmt.Errorf("failed to fetch IGDB websites for IGDB ID %d: %w", id, err) - } - - res := pb.ExternalGameResult{} - if err := proto.Unmarshal(resp.Body(), &res); err != nil { - return 0, fmt.Errorf("failed to unmarshal IGDB websites response for IGDB ID %d: %w", id, err) - } - - if len(res.Externalgames) == 0 { - return 0, errors.New("steam ID not found") - } - - return strconv.ParseUint(res.Externalgames[0].Uid, 10, 64) -} diff --git a/igdb.go b/igdb.go index fdcee74..634068e 100644 --- a/igdb.go +++ b/igdb.go @@ -32,7 +32,7 @@ func NewWithFlaresolverr(clientID, clientSecret string, f *flaresolverr.Flaresol func (g *igdb) Request(URL string, dataBody any) (*resty.Response, error) { t, err := g.token.getToken() if err != nil { - return nil, fmt.Errorf("failed to get Twitch token: %w", err) + return nil, fmt.Errorf("failed to get twitch token: %w", err) } resp, err := request().SetBody(dataBody).SetHeaders(map[string]string{ @@ -43,7 +43,7 @@ func (g *igdb) Request(URL string, dataBody any) (*resty.Response, error) { }).Post(URL) if err != nil { - return nil, fmt.Errorf("failed to make request: %s: %w", URL, err) + return nil, fmt.Errorf("failed to request: %s: %w", URL, err) } return resp, nil } diff --git a/involved_companies.go b/involved_companies.go new file mode 100644 index 0000000..5df647d --- /dev/null +++ b/involved_companies.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetInvolvedCompanies(query string) ([]*pb.InvolvedCompany, error) { + resp, err := g.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 +} + +func (g *igdb) GetInvolvedCompanyByID(id uint64) (*pb.InvolvedCompany, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + involvedCompanies, err := g.GetInvolvedCompanies(query) + if err != nil { + return nil, err + } + return involvedCompanies[0], nil +} + +func (g *igdb) GetInvolvedCompaniesByIDs(ids []uint64) ([]*pb.InvolvedCompany, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetInvolvedCompanies(idStr) +} diff --git a/keywords.go b/keywords.go new file mode 100644 index 0000000..140d861 --- /dev/null +++ b/keywords.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetKeywords(query string) ([]*pb.Keyword, error) { + resp, err := g.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 +} + +func (g *igdb) GetKeywordByID(id uint64) (*pb.Keyword, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + keywords, err := g.GetKeywords(query) + if err != nil { + return nil, err + } + return keywords[0], nil +} + +func (g *igdb) GetKeywordsByIDs(ids []uint64) ([]*pb.Keyword, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetKeywords(idStr) +} diff --git a/language_support_types.go b/language_support_types.go new file mode 100644 index 0000000..d40a79f --- /dev/null +++ b/language_support_types.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetLanguageSupportTypes(query string) ([]*pb.LanguageSupportType, error) { + resp, err := g.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 +} + +func (g *igdb) GetLanguageSupportTypeByID(id uint64) (*pb.LanguageSupportType, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + languageSupportTypes, err := g.GetLanguageSupportTypes(query) + if err != nil { + return nil, err + } + return languageSupportTypes[0], nil +} + +func (g *igdb) GetLanguageSupportTypesByIDs(ids []uint64) ([]*pb.LanguageSupportType, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetLanguageSupportTypes(idStr) +} diff --git a/language_supports.go b/language_supports.go new file mode 100644 index 0000000..a9491d8 --- /dev/null +++ b/language_supports.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetLanguageSupports(query string) ([]*pb.LanguageSupport, error) { + resp, err := g.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 +} + +func (g *igdb) GetLanguageSupportByID(id uint64) (*pb.LanguageSupport, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + languageSupports, err := g.GetLanguageSupports(query) + if err != nil { + return nil, err + } + return languageSupports[0], nil +} + +func (g *igdb) GetLanguageSupportsByIDs(ids []uint64) ([]*pb.LanguageSupport, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetLanguageSupports(idStr) +} diff --git a/languages.go b/languages.go new file mode 100644 index 0000000..eb68616 --- /dev/null +++ b/languages.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetLanguages(query string) ([]*pb.Language, error) { + resp, err := g.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 +} + +func (g *igdb) GetLanguageByID(id uint64) (*pb.Language, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + languages, err := g.GetLanguages(query) + if err != nil { + return nil, err + } + return languages[0], nil +} + +func (g *igdb) GetLanguagesByIDs(ids []uint64) ([]*pb.Language, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetLanguages(idStr) +} diff --git a/multiplayer_modes.go b/multiplayer_modes.go new file mode 100644 index 0000000..95eda9c --- /dev/null +++ b/multiplayer_modes.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetMultiplayerModes(query string) ([]*pb.MultiplayerMode, error) { + resp, err := g.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 +} + +func (g *igdb) GetMultiplayerModeByID(id uint64) (*pb.MultiplayerMode, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + multiplayerModes, err := g.GetMultiplayerModes(query) + if err != nil { + return nil, err + } + return multiplayerModes[0], nil +} + +func (g *igdb) GetMultiplayerModesByIDs(ids []uint64) ([]*pb.MultiplayerMode, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetMultiplayerModes(idStr) +} diff --git a/network_types.go b/network_types.go new file mode 100644 index 0000000..03525e8 --- /dev/null +++ b/network_types.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetNetworkTypes(query string) ([]*pb.NetworkType, error) { + resp, err := g.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 +} + +func (g *igdb) GetNetworkTypeByID(id uint64) (*pb.NetworkType, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + networkTypes, err := g.GetNetworkTypes(query) + if err != nil { + return nil, err + } + return networkTypes[0], nil +} + +func (g *igdb) GetNetworkTypesByIDs(ids []uint64) ([]*pb.NetworkType, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetNetworkTypes(idStr) +} diff --git a/parent.go b/parent.go index a04faac..12cf442 100644 --- a/parent.go +++ b/parent.go @@ -5,21 +5,21 @@ import ( ) func (g *igdb) GetParentGameID(id uint64) (uint64, error) { - detail, err := g.GetGame(id) + detail, err := g.GetGameByID(id) if err != nil { return 0, fmt.Errorf("failed to fetch IGDB app detail for parent: %d: %w", id, err) } hasParent := false if detail.ParentGame != nil && detail.ParentGame.Id != 0 { hasParent = true - detail, err = g.GetGame(detail.ParentGame.Id) + detail, err = g.GetGameByID(detail.ParentGame.Id) if err != nil { return 0, fmt.Errorf("failed to fetch IGDB version parent: %d: %w", detail.VersionParent.Id, err) } } for detail.VersionParent != nil && detail.VersionParent.Id != 0 { hasParent = true - detail, err = g.GetGame(detail.VersionParent.Id) + detail, err = g.GetGameByID(detail.VersionParent.Id) if err != nil { return 0, fmt.Errorf("failed to fetch IGDB version parent: %d: %w", detail.VersionParent.Id, err) } diff --git a/platform_families.go b/platform_families.go new file mode 100644 index 0000000..1e7ddc1 --- /dev/null +++ b/platform_families.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetPlatformFamilies(query string) ([]*pb.PlatformFamily, error) { + resp, err := g.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 +} + +func (g *igdb) GetPlatformFamilyByID(id uint64) (*pb.PlatformFamily, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + platformFamilies, err := g.GetPlatformFamilies(query) + if err != nil { + return nil, err + } + return platformFamilies[0], nil +} + +func (g *igdb) GetPlatformFamiliesByIDs(ids []uint64) ([]*pb.PlatformFamily, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetPlatformFamilies(idStr) +} diff --git a/platform_logos.go b/platform_logos.go new file mode 100644 index 0000000..a96db6c --- /dev/null +++ b/platform_logos.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetPlatformLogos(query string) ([]*pb.PlatformLogo, error) { + resp, err := g.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 +} + +func (g *igdb) GetPlatformLogoByID(id uint64) (*pb.PlatformLogo, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + platformLogos, err := g.GetPlatformLogos(query) + if err != nil { + return nil, err + } + return platformLogos[0], nil +} + +func (g *igdb) GetPlatformLogosByIDs(ids []uint64) ([]*pb.PlatformLogo, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetPlatformLogos(idStr) +} diff --git a/platform_types.go b/platform_types.go new file mode 100644 index 0000000..c609d49 --- /dev/null +++ b/platform_types.go @@ -0,0 +1,48 @@ +package igdb + +import ( + "fmt" + "strings" + + pb "github/bestnite/go-igdb/proto" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetPlatformTypes(query string) ([]*pb.PlatformType, error) { + resp, err := g.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 +} + +func (g *igdb) GetPlatformTypeByID(id uint64) (*pb.PlatformType, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + platformTypes, err := g.GetPlatformTypes(query) + if err != nil { + return nil, err + } + return platformTypes[0], nil +} + +func (g *igdb) GetPlatformTypesByIDs(ids []uint64) ([]*pb.PlatformType, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetPlatformTypes(idStr) +} diff --git a/platform_version_companies.go b/platform_version_companies.go new file mode 100644 index 0000000..0159d7a --- /dev/null +++ b/platform_version_companies.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetPlatformVersionCompanies(query string) ([]*pb.PlatformVersionCompany, error) { + resp, err := g.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 +} + +func (g *igdb) GetPlatformVersionCompanyByID(id uint64) (*pb.PlatformVersionCompany, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + platformVersionCompanies, err := g.GetPlatformVersionCompanies(query) + if err != nil { + return nil, err + } + return platformVersionCompanies[0], nil +} + +func (g *igdb) GetPlatformVersionCompaniesByIDs(ids []uint64) ([]*pb.PlatformVersionCompany, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetPlatformVersionCompanies(idStr) +} diff --git a/platform_version_release_dates.go b/platform_version_release_dates.go new file mode 100644 index 0000000..0248b2a --- /dev/null +++ b/platform_version_release_dates.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetPlatformVersionReleaseDates(query string) ([]*pb.PlatformVersionReleaseDate, error) { + resp, err := g.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 +} + +func (g *igdb) GetPlatformVersionReleaseDateByID(id uint64) (*pb.PlatformVersionReleaseDate, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + platformVersionReleaseDates, err := g.GetPlatformVersionReleaseDates(query) + if err != nil { + return nil, err + } + return platformVersionReleaseDates[0], nil +} + +func (g *igdb) GetPlatformVersionReleaseDatesByIDs(ids []uint64) ([]*pb.PlatformVersionReleaseDate, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetPlatformVersionReleaseDates(idStr) +} diff --git a/platform_versions.go b/platform_versions.go new file mode 100644 index 0000000..3a87490 --- /dev/null +++ b/platform_versions.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetPlatformVersions(query string) ([]*pb.PlatformVersion, error) { + resp, err := g.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 +} + +func (g *igdb) GetPlatformVersionByID(id uint64) (*pb.PlatformVersion, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + platformVersions, err := g.GetPlatformVersions(query) + if err != nil { + return nil, err + } + return platformVersions[0], nil +} + +func (g *igdb) GetPlatformVersionsByIDs(ids []uint64) ([]*pb.PlatformVersion, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetPlatformVersions(idStr) +} diff --git a/platform_websites.go b/platform_websites.go new file mode 100644 index 0000000..9aff95f --- /dev/null +++ b/platform_websites.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetPlatformWebsites(query string) ([]*pb.PlatformWebsite, error) { + resp, err := g.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 +} + +func (g *igdb) GetPlatformWebsiteByID(id uint64) (*pb.PlatformWebsite, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + platformWebsites, err := g.GetPlatformWebsites(query) + if err != nil { + return nil, err + } + return platformWebsites[0], nil +} + +func (g *igdb) GetPlatformWebsitesByIDs(ids []uint64) ([]*pb.PlatformWebsite, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetPlatformWebsites(idStr) +} diff --git a/platforms.go b/platforms.go new file mode 100644 index 0000000..cfad5df --- /dev/null +++ b/platforms.go @@ -0,0 +1,46 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetPlatforms(query string) ([]*pb.Platform, error) { + resp, err := g.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 +} + +func (g *igdb) GetPlatformByID(id uint64) (*pb.Platform, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + platforms, err := g.GetPlatforms(query) + if err != nil { + return nil, err + } + return platforms[0], nil +} + +func (g *igdb) GetPlatformsByIDs(ids []uint64) ([]*pb.Platform, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetPlatforms(idStr) +} diff --git a/player_perspectives.go b/player_perspectives.go new file mode 100644 index 0000000..c0a1ce4 --- /dev/null +++ b/player_perspectives.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetPlayerPerspectives(query string) ([]*pb.PlayerPerspective, error) { + resp, err := g.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 +} + +func (g *igdb) GetPlayerPerspectiveByID(id uint64) (*pb.PlayerPerspective, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + playerPerspectives, err := g.GetPlayerPerspectives(query) + if err != nil { + return nil, err + } + return playerPerspectives[0], nil +} + +func (g *igdb) GetPlayerPerspectivesByIDs(ids []uint64) ([]*pb.PlayerPerspective, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetPlayerPerspectives(idStr) +} diff --git a/popular.go b/popular.go deleted file mode 100644 index dddebf8..0000000 --- a/popular.go +++ /dev/null @@ -1,33 +0,0 @@ -package igdb - -import ( - "fmt" - "github/bestnite/go-igdb/constant" - pb "github/bestnite/go-igdb/proto" - - "google.golang.org/protobuf/proto" -) - -// GetPopularGameIDs retrieves popular IGDB game IDs based on a given popularity type. -// popularity_type = 1 IGDB Visits: Game page visits on IGDB.com. -// popularity_type = 2 IGDB Want to Play: Additions to IGDB.com users’ “Want to Play” lists. -// popularity_type = 3 IGDB Playing: Additions to IGDB.com users’ “Playing” lists. -// popularity_type = 4 IGDB Played: Additions to IGDB.com users’ “Played” lists. -func (g *igdb) GetPopularGameIDs(popularityType, offset, limit int) ([]uint64, error) { - query := fmt.Sprintf("fields game_id,value,popularity_type; sort value desc; limit %d; offset %d; where popularity_type = %d;", limit, offset, popularityType) - resp, err := g.Request(constant.IGDBPopularityURL, query) - if err != nil { - return nil, fmt.Errorf("failed to fetch popular IGDB game IDs for type %d: %w", popularityType, err) - } - data := pb.PopularityPrimitiveResult{} - if err = proto.Unmarshal(resp.Body(), &data); err != nil { - return nil, fmt.Errorf("failed to unmarshal IGDB popular games response: %w", err) - } - - gameIDs := make([]uint64, 0, len(data.Popularityprimitives)) - for _, game := range data.Popularityprimitives { - gameIDs = append(gameIDs, uint64(game.GameId)) - } - - return gameIDs, nil -} diff --git a/popularity_primitives.go b/popularity_primitives.go new file mode 100644 index 0000000..deb96de --- /dev/null +++ b/popularity_primitives.go @@ -0,0 +1,57 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetPopularityPrimitives(query string) ([]*pb.PopularityPrimitive, error) { + resp, err := g.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 +} + +func (g *igdb) GetPopularityPrimitiveByID(id uint64) (*pb.PopularityPrimitive, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + popularityPrimitives, err := g.GetPopularityPrimitives(query) + if err != nil { + return nil, err + } + return popularityPrimitives[0], nil +} + +func (g *igdb) GetPopularityPrimitivesByIDs(ids []uint64) ([]*pb.PopularityPrimitive, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetPopularityPrimitives(idStr) +} + +// GetPopularityPrimitive retrieves popular IGDB game IDs based on a given popularity type. +// popularity_type = 1 IGDB Visits +// popularity_type = 2 IGDB Want to Play +// popularity_type = 3 IGDB Playing +// popularity_type = 4 IGDB Played +func (g *igdb) GetPopularityPrimitivesByPopularityType(popularityType, offset, limit int) ([]*pb.PopularityPrimitive, error) { + query := fmt.Sprintf("fields game_id,value,popularity_type; sort value desc; limit %d; offset %d; where popularity_type = %d;", limit, offset, popularityType) + return g.GetPopularityPrimitives(query) +} diff --git a/popularity_types.go b/popularity_types.go new file mode 100644 index 0000000..701b9dd --- /dev/null +++ b/popularity_types.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetPopularityTypes(query string) ([]*pb.PopularityType, error) { + resp, err := g.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 +} + +func (g *igdb) GetPopularityTypeByID(id uint64) (*pb.PopularityType, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + popularityTypes, err := g.GetPopularityTypes(query) + if err != nil { + return nil, err + } + return popularityTypes[0], nil +} + +func (g *igdb) GetPopularityTypesByIDs(ids []uint64) ([]*pb.PopularityType, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetPopularityTypes(idStr) +} diff --git a/regions.go b/regions.go new file mode 100644 index 0000000..48694ca --- /dev/null +++ b/regions.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetRegions(query string) ([]*pb.Region, error) { + resp, err := g.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 +} + +func (g *igdb) GetRegionByID(id uint64) (*pb.Region, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + regions, err := g.GetRegions(query) + if err != nil { + return nil, err + } + return regions[0], nil +} + +func (g *igdb) GetRegionsByIDs(ids []uint64) ([]*pb.Region, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetRegions(idStr) +} diff --git a/release_date_regions.go b/release_date_regions.go new file mode 100644 index 0000000..6d15a40 --- /dev/null +++ b/release_date_regions.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetReleaseDateRegions(query string) ([]*pb.ReleaseDateRegion, error) { + resp, err := g.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 +} + +func (g *igdb) GetReleaseDateRegionByID(id uint64) (*pb.ReleaseDateRegion, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + releaseDateRegions, err := g.GetReleaseDateRegions(query) + if err != nil { + return nil, err + } + return releaseDateRegions[0], nil +} + +func (g *igdb) GetReleaseDateRegionsByIDs(ids []uint64) ([]*pb.ReleaseDateRegion, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetReleaseDateRegions(idStr) +} diff --git a/release_date_statuses.go b/release_date_statuses.go new file mode 100644 index 0000000..2cfc579 --- /dev/null +++ b/release_date_statuses.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetReleaseDateStatuses(query string) ([]*pb.ReleaseDateStatus, error) { + resp, err := g.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 +} + +func (g *igdb) GetReleaseDateStatusByID(id uint64) (*pb.ReleaseDateStatus, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + releaseDateStatuses, err := g.GetReleaseDateStatuses(query) + if err != nil { + return nil, err + } + return releaseDateStatuses[0], nil +} + +func (g *igdb) GetReleaseDateStatusesByIDs(ids []uint64) ([]*pb.ReleaseDateStatus, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetReleaseDateStatuses(idStr) +} diff --git a/release_dates.go b/release_dates.go new file mode 100644 index 0000000..06e43d8 --- /dev/null +++ b/release_dates.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetReleaseDates(query string) ([]*pb.ReleaseDate, error) { + resp, err := g.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 +} + +func (g *igdb) GetReleaseDateByID(id uint64) (*pb.ReleaseDate, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + releaseDates, err := g.GetReleaseDates(query) + if err != nil { + return nil, err + } + return releaseDates[0], nil +} + +func (g *igdb) GetReleaseDatesByIDs(ids []uint64) ([]*pb.ReleaseDate, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetReleaseDates(idStr) +} diff --git a/screenshots.go b/screenshots.go new file mode 100644 index 0000000..51877de --- /dev/null +++ b/screenshots.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetScreenshots(query string) ([]*pb.Screenshot, error) { + resp, err := g.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 +} + +func (g *igdb) GetScreenshotByID(id uint64) (*pb.Screenshot, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + screenshots, err := g.GetScreenshots(query) + if err != nil { + return nil, err + } + return screenshots[0], nil +} + +func (g *igdb) GetScreenshotsByIDs(ids []uint64) ([]*pb.Screenshot, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetScreenshots(idStr) +} diff --git a/search.go b/search.go index bbcb7fd..349e6a7 100644 --- a/search.go +++ b/search.go @@ -3,7 +3,6 @@ package igdb import ( "encoding/json" "fmt" - "github/bestnite/go-igdb/constant" "io" "net/http" "net/url" @@ -17,34 +16,34 @@ import ( "google.golang.org/protobuf/proto" ) -func (g *igdb) SearchGame(query string) ([]*pb.Game, error) { - resp, err := g.Request(constant.IGDBGameURL, query) - if err != nil { - return nil, fmt.Errorf("failed to search: %s: %w", query, err) - } - - data := pb.GameResult{} - if err = proto.Unmarshal(resp.Body(), &data); err != nil { - return nil, fmt.Errorf("failed to parse IGDB search response: %w", err) - } - - if len(data.Games) != 0 && data.Games[0].Name == "" { - return g.WebSearchGame(query) - } - - return data.Games, nil -} - var webSearchCFCookies struct { cookies []*http.Cookie expires time.Time } -func (g *igdb) WebSearchGame(name string) ([]*pb.Game, error) { +func (g *igdb) Search(query string) ([]*pb.Search, error) { + resp, err := g.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 (g *igdb) WebSearchGames(name string) ([]*pb.Game, error) { params := url.Values{} params.Add("q", name) params.Add("utf8", "✓") - Url := fmt.Sprintf("%s?%s", constant.IGDBWebSearchURL, params.Encode()) + Url := fmt.Sprintf("%s?%s", "https://www.igdb.com/search", params.Encode()) f, err := g.getFlaresolverr() if err != nil { @@ -94,5 +93,5 @@ func (g *igdb) WebSearchGame(name string) ([]*pb.Game, error) { ids[i] = game.Id } - return g.GetGames(ids) + return g.GetGameByIDs(ids) } diff --git a/themes.go b/themes.go new file mode 100644 index 0000000..edeb213 --- /dev/null +++ b/themes.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetThemes(query string) ([]*pb.Theme, error) { + resp, err := g.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 +} + +func (g *igdb) GetThemeByID(id uint64) (*pb.Theme, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + themes, err := g.GetThemes(query) + if err != nil { + return nil, err + } + return themes[0], nil +} + +func (g *igdb) GetThemesByIDs(ids []uint64) ([]*pb.Theme, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetThemes(idStr) +} diff --git a/token.go b/token.go index f861967..89defca 100644 --- a/token.go +++ b/token.go @@ -3,7 +3,6 @@ package igdb import ( "encoding/json" "fmt" - "github/bestnite/go-igdb/constant" "net/url" "time" ) @@ -36,7 +35,7 @@ func (t *twitchToken) getToken() (string, error) { } func (t *twitchToken) loginTwitch() (string, time.Duration, error) { - baseURL, _ := url.Parse(constant.TwitchAuthURL) + baseURL, _ := url.Parse("https://id.twitch.tv/oauth2/token") params := url.Values{} params.Add("client_id", t.clientID) params.Add("client_secret", t.clientSecret) diff --git a/webhook.go b/webhook.go deleted file mode 100644 index 75d5aff..0000000 --- a/webhook.go +++ /dev/null @@ -1,37 +0,0 @@ -package igdb - -import ( - "fmt" - "github/bestnite/go-igdb/constant" - "net/http" - "net/url" -) - -// ActiveWebhook activates a webhook for a specific endpoint. -// -// https://api-docs.igdb.com/#webhooks -func (g *igdb) ActiveWebhook(endpoint, secret, callbackUrl string) error { - t, err := g.token.getToken() - if err != nil { - return fmt.Errorf("failed to get Twitch token: %w", err) - } - dataBody := url.Values{} - dataBody.Set("url", callbackUrl) - dataBody.Set("secret", secret) - dataBody.Set("method", "update") - resp, err := request().SetBody(dataBody.Encode()).SetHeaders(map[string]string{ - "Client-ID": g.clientID, - "Authorization": "Bearer " + t, - "User-Agent": "", - "Content-Type": "application/x-www-form-urlencoded", - }).Post(fmt.Sprintf(constant.IGDBWebhookURL, endpoint)) - - 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()) -} diff --git a/webhooks.go b/webhooks.go new file mode 100644 index 0000000..26c0cae --- /dev/null +++ b/webhooks.go @@ -0,0 +1,26 @@ +package igdb + +import ( + "fmt" + "net/http" + "net/url" + + "github/bestnite/go-igdb/endpoint" +) + +func (g *igdb) ActiveWebhook(endpoint endpoint.Endpoint, secret, callbackUrl string) error { + dataBody := url.Values{} + dataBody.Set("url", callbackUrl) + dataBody.Set("secret", secret) + dataBody.Set("method", "update") + resp, err := g.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()) +} diff --git a/website_types.go b/website_types.go new file mode 100644 index 0000000..7bf9e1a --- /dev/null +++ b/website_types.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetWebsiteTypes(query string) ([]*pb.WebsiteType, error) { + resp, err := g.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 +} + +func (g *igdb) GetWebsiteTypeByID(id uint64) (*pb.WebsiteType, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + websiteTypes, err := g.GetWebsiteTypes(query) + if err != nil { + return nil, err + } + return websiteTypes[0], nil +} + +func (g *igdb) GetWebsiteTypesByIDs(ids []uint64) ([]*pb.WebsiteType, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetWebsiteTypes(idStr) +} diff --git a/websites.go b/websites.go new file mode 100644 index 0000000..2c3f99c --- /dev/null +++ b/websites.go @@ -0,0 +1,47 @@ +package igdb + +import ( + "fmt" + pb "github/bestnite/go-igdb/proto" + "strings" + + "google.golang.org/protobuf/proto" +) + +func (g *igdb) GetWebsites(query string) ([]*pb.Website, error) { + resp, err := g.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 +} + +func (g *igdb) GetWebsiteByID(id uint64) (*pb.Website, error) { + query := fmt.Sprintf(`where id=%d; fields *;`, id) + websites, err := g.GetWebsites(query) + if err != nil { + return nil, err + } + return websites[0], nil +} + +func (g *igdb) GetWebsitesByIDs(ids []uint64) ([]*pb.Website, error) { + idStrSlice := make([]string, len(ids)) + for i, id := range ids { + idStrSlice[i] = fmt.Sprintf("%d", id) + } + + idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ",")) + + return g.GetWebsites(idStr) +}