8 Commits

Author SHA1 Message Date
35c27b28a3 u 2025-04-05 16:29:30 +11:00
dab30b4938 fix 2025-04-05 12:18:58 +11:00
4be44c4eb2 add limiter 2025-04-05 11:53:00 +11:00
e01d9805c6 README 2025-04-05 03:37:00 +11:00
76a3e977ba u 2025-04-05 03:30:18 +11:00
a0e24ca14b u 2025-04-05 03:14:04 +11:00
6ae7a18fd9 u 2025-04-05 03:10:28 +11:00
18dc9781b1 u 2025-04-05 02:42:09 +11:00
84 changed files with 5507 additions and 268 deletions

View File

@@ -1,14 +1,61 @@
# go-igdb
a go library to access IGDB API
A Go client library for the IGDB (Internet Game Database) API v4. This library provides a simple and efficient way to interact with IGDB's protobuf-based API.
## Usage
## Features
- Full support for IGDB API v4
- Protobuf-based communication for better performance
- Automatic token management for Twitch authentication
- Built-in retry mechanism for failed requests
- Optional Cloudflare bypass support via FlareSolverr
- All endpoints are supported
## Installation
```bash
go get github.com/bestnite/go-igdb
```
## Quick Start
```go
g := igdb.New("clientID", "clientSecret")
game, err := g.GetGame(325594)
// Create a new IGDB client
client := igdb.New("your-client-id", "your-client-secret")
// Get a game by ID
game, err := client.GetGameByID(1942)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Game: %s\n", game.Name)
// Search games with custom query
games, err := client.GetGames("search \"Zelda\"; fields name,rating,release_dates.*;")
if err != nil {
log.Fatal(err)
}
fmt.Println(game.Name)
```
## Advanced Usage
### Query Format
The library uses IGDB's query syntax. For example:
```go
// Get games released in 2023
games, err := client.GetGames("where release_dates.y = 2023; fields name,rating;")
// Get specific fields for a company
companies, err := client.GetCompanies("where id = 1234; fields name,description,country;")
```
## Requirements
- Go 1.24 or higher
- IGDB/Twitch API credentials (Client ID and Client Secret)
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.

73
age_rating_categories.go Normal file
View File

@@ -0,0 +1,73 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetAgeRatingCategoriesByOrganizationID(id uint64) ([]*pb.AgeRatingCategory, error) {
query := fmt.Sprintf(`where organization = %d; fields *;`, id)
return g.GetAgeRatingCategories(query)
}
func (g *Client) GetAgeRatingCategoriesByOrganizationIDs(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 organization = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetAgeRatingCategories(idStr)
}
func (g *Client) GetAgeRatingCategoriesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
ageRatingCategories, err := g.GetAgeRatingCategories(query)
if err != nil {
return 0, err
}
return int(ageRatingCategories[0].Id), nil
}

View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetAgeRatingContentDescriptionsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
ageRatingContentDescriptions, err := g.GetAgeRatingContentDescriptions(query)
if err != nil {
return 0, err
}
return int(ageRatingContentDescriptions[0].Id), nil
}

View File

@@ -0,0 +1,73 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetAgeRatingContentDescriptionsV2ByOrganizationID(id uint64) ([]*pb.AgeRatingContentDescriptionV2, error) {
query := fmt.Sprintf(`where organization = %d; fields *;`, id)
return g.GetAgeRatingContentDescriptionsV2(query)
}
func (g *Client) GetAgeRatingContentDescriptionsV2ByOrganizationIDs(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 organization = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetAgeRatingContentDescriptionsV2(idStr)
}
func (g *Client) GetAgeRatingContentDescriptionsV2Length() (int, error) {
query := `fields *; sort id desc; limit 1;`
ageRatingContentDescriptions, err := g.GetAgeRatingContentDescriptionsV2(query)
if err != nil {
return 0, err
}
return int(ageRatingContentDescriptions[0].Id), nil
}

View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetAgeRatingOrganizationsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
ageRatingOrganizations, err := g.GetAgeRatingOrganizations(query)
if err != nil {
return 0, err
}
return int(ageRatingOrganizations[0].Id), nil
}

89
age_ratings.go Normal file
View File

@@ -0,0 +1,89 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetAgeRatingsByOrganizationID(id uint64) ([]*pb.AgeRating, error) {
query := fmt.Sprintf(`where organization = %d; fields *;`, id)
return g.GetAgeRatings(query)
}
func (g *Client) GetAgeRatingsByOrganizationIDs(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 organization = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetAgeRatings(idStr)
}
func (g *Client) GetAgeRatingsByAgeRatingCategoryID(id uint64) ([]*pb.AgeRating, error) {
query := fmt.Sprintf(`where rating_category = %d; fields *;`, id)
return g.GetAgeRatings(query)
}
func (g *Client) GetAgeRatingsByAgeRatingCategoryIDs(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 rating_category = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetAgeRatings(idStr)
}
func (g *Client) GetAgeRatingsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
ageRatings, err := g.GetAgeRatings(query)
if err != nil {
return 0, err
}
return int(ageRatings[0].Id), nil
}

73
alternative_names.go Normal file
View File

@@ -0,0 +1,73 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetAlternativeNamesByGameID(id uint64) ([]*pb.AlternativeName, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetAlternativeNames(query)
}
func (g *Client) GetAlternativeNamesByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetAlternativeNames(idStr)
}
func (g *Client) GetAlternativeNamesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
alternativeNames, err := g.GetAlternativeNames(query)
if err != nil {
return 0, err
}
return int(alternativeNames[0].Id), nil
}

73
artworks.go Normal file
View File

@@ -0,0 +1,73 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetArtworksByGameID(id uint64) ([]*pb.Artwork, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetArtworks(query)
}
func (g *Client) GetArtworksByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetArtworks(idStr)
}
func (g *Client) GetArtworksLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
artworks, err := g.GetArtworks(query)
if err != nil {
return 0, err
}
return int(artworks[0].Id), nil
}

57
character_genders.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetCharacterGendersLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
characterGenders, err := g.GetCharacterGenders(query)
if err != nil {
return 0, err
}
return int(characterGenders[0].Id), nil
}

57
character_mug_shots.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetCharacterMugShotsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
characterMugShots, err := g.GetCharacterMugShots(query)
if err != nil {
return 0, err
}
return int(characterMugShots[0].Id), nil
}

57
character_species.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetCharacterSpeciesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
characterSpecies, err := g.GetCharacterSpecies(query)
if err != nil {
return 0, err
}
return int(characterSpecies[0].Id), nil
}

105
characters.go Normal file
View File

@@ -0,0 +1,105 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetCharactersByCharacterGenderID(id uint64) ([]*pb.Character, error) {
query := fmt.Sprintf(`where character_gender = %d; fields *;`, id)
return g.GetCharacters(query)
}
func (g *Client) GetCharactersByCharacterGenderIDs(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 character_gender = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCharacters(idStr)
}
func (g *Client) GetCharactersByCharacterSpecieID(id uint64) ([]*pb.Character, error) {
query := fmt.Sprintf(`where character_species = %d; fields *;`, id)
return g.GetCharacters(query)
}
func (g *Client) GetCharactersByCharacterSpecieIDs(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 character_species = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCharacters(idStr)
}
func (g *Client) GetCharactersByMugShotID(id uint64) ([]*pb.Character, error) {
query := fmt.Sprintf(`where mug_shot = %d; fields *;`, id)
return g.GetCharacters(query)
}
func (g *Client) GetCharactersByMugShotIDs(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 mug_shot = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCharacters(idStr)
}
func (g *Client) GetCharactersLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
characters, err := g.GetCharacters(query)
if err != nil {
return 0, err
}
return int(characters[0].Id), nil
}

View File

@@ -0,0 +1,73 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetCollectionMembershipTypesByAllowedCollectionTypeID(id uint64) ([]*pb.CollectionMembershipType, error) {
query := fmt.Sprintf(`where allowed_collection_type = %d; fields *;`, id)
return g.GetCollectionMembershipTypes(query)
}
func (g *Client) GetCollectionMembershipTypesByAllowedCollectionTypeIDs(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 allowed_collection_type = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCollectionMembershipTypes(idStr)
}
func (g *Client) GetCollectionMembershipTypesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
collectionMembershipTypes, err := g.GetCollectionMembershipTypes(query)
if err != nil {
return 0, err
}
return int(collectionMembershipTypes[0].Id), nil
}

94
collection_memberships.go Normal file
View File

@@ -0,0 +1,94 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetCollectionMembershipsByGameID(id uint64) ([]*pb.CollectionMembership, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetCollectionMemberships(query)
}
func (g *Client) GetCollectionMembershipsByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCollectionMemberships(idStr)
}
func (g *Client) GetCollectionMembershipsByCollectionID(id uint64) ([]*pb.CollectionMembership, error) {
query := fmt.Sprintf(`where collection = %d; fields *;`, id)
return g.GetCollectionMemberships(query)
}
func (g *Client) GetCollectionMembershipsByCollectionMembershipTypeID(id uint64) ([]*pb.CollectionMembership, error) {
query := fmt.Sprintf(`where type = %d; fields *;`, id)
return g.GetCollectionMemberships(query)
}
func (g *Client) GetCollectionMembershipsByCollectionMembershipTypeIDs(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 type = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCollectionMemberships(idStr)
}
func (g *Client) GetCollectionMembershipsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
collectionMemberships, err := g.GetCollectionMemberships(query)
if err != nil {
return 0, err
}
return int(collectionMemberships[0].Id), nil
}

View File

@@ -0,0 +1,89 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetCollectionRelationTypesByAllowedChildTypeID(id uint64) ([]*pb.CollectionRelationType, error) {
query := fmt.Sprintf(`where allowed_child_type = %d; fields *;`, id)
return g.GetCollectionRelationTypes(query)
}
func (g *Client) GetCollectionRelationTypesByAllowedChildTypeIDs(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 allowed_child_type = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCollectionRelationTypes(idStr)
}
func (g *Client) GetCollectionRelationTypesByAllowedParentTypeID(id uint64) ([]*pb.CollectionRelationType, error) {
query := fmt.Sprintf(`where allowed_parent_type = %d; fields *;`, id)
return g.GetCollectionRelationTypes(query)
}
func (g *Client) GetCollectionRelationTypesByAllowedParentTypeIDs(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 allowed_parent_type = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCollectionRelationTypes(idStr)
}
func (g *Client) GetCollectionRelationTypesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
collectionRelationTypes, err := g.GetCollectionRelationTypes(query)
if err != nil {
return 0, err
}
return int(collectionRelationTypes[0].Id), nil
}

105
collection_relations.go Normal file
View File

@@ -0,0 +1,105 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetCollectionRelationsByChildCollectionID(id uint64) ([]*pb.CollectionRelation, error) {
query := fmt.Sprintf(`where child_collection = %d; fields *;`, id)
return g.GetCollectionRelations(query)
}
func (g *Client) GetCollectionRelationsByChildCollectionIDs(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 child_collection = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCollectionRelations(idStr)
}
func (g *Client) GetCollectionRelationsByParentCollectionID(id uint64) ([]*pb.CollectionRelation, error) {
query := fmt.Sprintf(`where parent_collection = %d; fields *;`, id)
return g.GetCollectionRelations(query)
}
func (g *Client) GetCollectionRelationsByParentCollectionIDs(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 parent_collection = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCollectionRelations(idStr)
}
func (g *Client) GetCollectionRelationsByCollectionRelationTypeID(id uint64) ([]*pb.CollectionRelation, error) {
query := fmt.Sprintf(`where type = %d; fields *;`, id)
return g.GetCollectionRelations(query)
}
func (g *Client) GetCollectionRelationsByCollectionRelationTypeIDs(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 type = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCollectionRelations(idStr)
}
func (g *Client) GetCollectionRelationsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
collectionRelations, err := g.GetCollectionRelations(query)
if err != nil {
return 0, err
}
return int(collectionRelations[0].Id), nil
}

57
collection_types.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetCollectionTypesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
collectionTypes, err := g.GetCollectionTypes(query)
if err != nil {
return 0, err
}
return int(collectionTypes[0].Id), nil
}

73
collections.go Normal file
View File

@@ -0,0 +1,73 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetCollectionsByCollectionTypeID(id uint64) ([]*pb.Collection, error) {
query := fmt.Sprintf(`where collection_type = %d; fields *;`, id)
return g.GetCollections(query)
}
func (g *Client) GetCollectionsByCollectionTypeIDs(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 collection_type = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCollections(idStr)
}
func (g *Client) GetCollectionsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
collections, err := g.GetCollections(query)
if err != nil {
return 0, err
}
return int(collections[0].Id), nil
}

154
companies.go Normal file
View File

@@ -0,0 +1,154 @@
package igdb
import (
"errors"
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetCompanyByChangeDateFormatID(id uint64) ([]*pb.Company, error) {
query := fmt.Sprintf(`where change_date_format = %d; fields *;`, id)
return g.GetCompanies(query)
}
func (g *Client) GetCompanyByChangeDateFormatsIDs(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 change_date_format = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCompanies(idStr)
}
func (g *Client) GetCompanyByChangedCompanyID(id uint64) ([]*pb.Company, error) {
query := fmt.Sprintf(`where changed_company_id = %d; fields *;`, id)
return g.GetCompanies(query)
}
func (g *Client) GetCompanyByChangedCompanyIDs(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 changed_company_id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCompanies(idStr)
}
func (g *Client) GetCompanyByLogoID(id uint64) ([]*pb.Company, error) {
query := fmt.Sprintf(`where logo = %d; fields *;`, id)
return g.GetCompanies(query)
}
func (g *Client) GetCompanyByLogoIDs(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 logo = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCompanies(idStr)
}
func (g *Client) GetCompanyByParentID(id uint64) ([]*pb.Company, error) {
query := fmt.Sprintf(`where parent = %d; fields *;`, id)
return g.GetCompanies(query)
}
func (g *Client) GetCompanyByParentIDs(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 parent = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCompanies(idStr)
}
func (g *Client) GetCompanyByStartDateFormatID(id uint64) ([]*pb.Company, error) {
query := fmt.Sprintf(`where start_date_format = %d; fields *;`, id)
return g.GetCompanies(query)
}
func (g *Client) GetCompanyByStartDateFormatsIDs(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 start_date_format = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCompanies(idStr)
}
func (g *Client) GetCompanyByStatusID(id uint64) ([]*pb.Company, error) {
query := fmt.Sprintf(`where status = %d; fields *;`, id)
return g.GetCompanies(query)
}
func (g *Client) GetCompanyByStatusIDs(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 status = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCompanies(idStr)
}
func (g *Client) GetCompaniesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
companies, err := g.GetCompanies(query)
if err != nil {
return 0, err
}
return int(companies[0].Id), nil
}

View File

@@ -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
}

57
company_logos.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetCompanyLogosLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
companyLogos, err := g.GetCompanyLogos(query)
if err != nil {
return 0, err
}
return int(companyLogos[0].Id), nil
}

57
company_statuses.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetCompanyStatusesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
companyStatuses, err := g.GetCompanyStatuses(query)
if err != nil {
return 0, err
}
return int(companyStatuses[0].Id), nil
}

73
company_websites.go Normal file
View File

@@ -0,0 +1,73 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetCompanyWebsitesByTypeID(id uint64) ([]*pb.CompanyWebsite, error) {
query := fmt.Sprintf(`where type = %d; fields *;`, id)
return g.GetCompanyWebsites(query)
}
func (g *Client) GetCompanyWebsitesByTypeIDs(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 type = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCompanyWebsites(idStr)
}
func (g *Client) GetCompanyWebsitesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
companyWebsites, err := g.GetCompanyWebsites(query)
if err != nil {
return 0, err
}
return int(companyWebsites[0].Id), nil
}

View File

@@ -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"
)

89
covers.go Normal file
View File

@@ -0,0 +1,89 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetCoversByGameID(id uint64) ([]*pb.Cover, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetCovers(query)
}
func (g *Client) GetCoversByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCovers(idStr)
}
func (g *Client) GetCoversByGameLocalizationID(id uint64) ([]*pb.Cover, error) {
query := fmt.Sprintf(`where game_localization = %d; fields *;`, id)
return g.GetCovers(query)
}
func (g *Client) GetCoversByGameLocalizationIDs(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 game_localization = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCovers(idStr)
}
func (g *Client) GetCoversLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
covers, err := g.GetCovers(query)
if err != nil {
return 0, err
}
return int(covers[0].Id), nil
}

57
date_formats.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetDateFormatsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
dateFormats, err := g.GetDateFormats(query)
if err != nil {
return 0, err
}
return int(dateFormats[0].Id), nil
}

151
endpoint/endpoint.go Normal file
View File

@@ -0,0 +1,151 @@
package endpoint
type Endpoint string
var (
AgeRatingCategories Endpoint = "age_rating_categories"
AgeRatingContentDescriptions Endpoint = "age_rating_content_descriptions"
AgeRatingContentDescriptionsV2 Endpoint = "age_rating_content_descriptions_v2"
AgeRatingOrganizations Endpoint = "age_rating_organizations"
AgeRatings Endpoint = "age_ratings"
AlternativeNames Endpoint = "alternative_names"
Artworks Endpoint = "artworks"
CharacterGenders Endpoint = "character_genders"
CharacterMugShots Endpoint = "character_mug_shots"
Characters Endpoint = "characters"
CharacterSpecies Endpoint = "character_species"
CollectionMemberships Endpoint = "collection_memberships"
CollectionMembershipTypes Endpoint = "collection_membership_types"
CollectionRelations Endpoint = "collection_relations"
CollectionRelationTypes Endpoint = "collection_relation_types"
Collections Endpoint = "collections"
CollectionTypes Endpoint = "collection_types"
Companies Endpoint = "companies"
CompanyLogos Endpoint = "company_logos"
CompanyStatuses Endpoint = "company_statuses"
CompanyWebsites Endpoint = "company_websites"
Covers Endpoint = "covers"
DateFormats Endpoint = "date_formats"
EventLogos Endpoint = "event_logos"
EventNetworks Endpoint = "event_networks"
Events Endpoint = "events"
ExternalGames Endpoint = "external_games"
ExternalGameSources Endpoint = "external_game_sources"
Franchises Endpoint = "franchises"
GameEngineLogos Endpoint = "game_engine_logos"
GameEngines Endpoint = "game_engines"
GameLocalizations Endpoint = "game_localizations"
GameModes Endpoint = "game_modes"
GameReleaseFormats Endpoint = "game_release_formats"
Games Endpoint = "games"
GameStatuses Endpoint = "game_statuses"
GameTimeToBeats Endpoint = "game_time_to_beats"
GameTypes Endpoint = "game_types"
GameVersionFeatures Endpoint = "game_version_features"
GameVersionFeatureValues Endpoint = "game_version_feature_values"
GameVersions Endpoint = "game_versions"
GameVideos Endpoint = "game_videos"
Genres Endpoint = "genres"
InvolvedCompanies Endpoint = "involved_companies"
Keywords Endpoint = "keywords"
Languages Endpoint = "languages"
LanguageSupports Endpoint = "language_supports"
LanguageSupportTypes Endpoint = "language_support_types"
MultiplayerModes Endpoint = "multiplayer_modes"
NetworkTypes Endpoint = "network_types"
PlatformFamilies Endpoint = "platform_families"
PlatformLogos Endpoint = "platform_logos"
Platforms Endpoint = "platforms"
PlatformTypes Endpoint = "platform_types"
PlatformVersionCompanies Endpoint = "platform_version_companies"
PlatformVersionReleaseDates Endpoint = "platform_version_release_dates"
PlatformVersions Endpoint = "platform_versions"
PlatformWebsites Endpoint = "platform_websites"
PlayerPerspectives Endpoint = "player_perspectives"
PopularityPrimitives Endpoint = "popularity_primitives"
PopularityTypes Endpoint = "popularity_types"
Regions Endpoint = "regions"
ReleaseDateRegions Endpoint = "release_date_regions"
ReleaseDates Endpoint = "release_dates"
ReleaseDateStatuses Endpoint = "release_date_statuses"
Screenshots Endpoint = "screenshots"
Search Endpoint = "search"
Themes Endpoint = "themes"
Webhooks Endpoint = "webhooks"
Websites Endpoint = "websites"
WebsiteTypes Endpoint = "website_types"
)
var AllEndpoints = []Endpoint{
AgeRatingCategories,
AgeRatingContentDescriptions,
AgeRatingContentDescriptionsV2,
AgeRatingOrganizations,
AgeRatings,
AlternativeNames,
Artworks,
CharacterGenders,
CharacterMugShots,
Characters,
CharacterSpecies,
CollectionMemberships,
CollectionMembershipTypes,
CollectionRelations,
CollectionRelationTypes,
Collections,
CollectionTypes,
Companies,
CompanyLogos,
CompanyStatuses,
CompanyWebsites,
Covers,
DateFormats,
EventLogos,
EventNetworks,
Events,
ExternalGames,
ExternalGameSources,
Franchises,
GameEngineLogos,
GameEngines,
GameLocalizations,
GameModes,
GameReleaseFormats,
Games,
GameStatuses,
GameTimeToBeats,
GameTypes,
GameVersionFeatures,
GameVersionFeatureValues,
GameVersions,
GameVideos,
Genres,
InvolvedCompanies,
Keywords,
Languages,
LanguageSupports,
LanguageSupportTypes,
MultiplayerModes,
NetworkTypes,
PlatformFamilies,
PlatformLogos,
Platforms,
PlatformTypes,
PlatformVersionCompanies,
PlatformVersionReleaseDates,
PlatformVersions,
PlatformWebsites,
PlayerPerspectives,
PopularityPrimitives,
PopularityTypes,
Regions,
ReleaseDateRegions,
ReleaseDates,
ReleaseDateStatuses,
Screenshots,
Search,
Themes,
Webhooks,
Websites,
WebsiteTypes,
}

73
event_logos.go Normal file
View File

@@ -0,0 +1,73 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetEventLogosByEventID(id uint64) ([]*pb.EventLogo, error) {
query := fmt.Sprintf(`where event = %d; fields *;`, id)
return g.GetEventLogos(query)
}
func (g *Client) GetEventLogosByEventIDs(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 event = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetEventLogos(idStr)
}
func (g *Client) GetEventLogosLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
eventLogos, err := g.GetEventLogos(query)
if err != nil {
return 0, err
}
return int(eventLogos[0].Id), nil
}

89
event_networks.go Normal file
View File

@@ -0,0 +1,89 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetEventNetworksByEventID(id uint64) ([]*pb.EventNetwork, error) {
query := fmt.Sprintf(`where event = %d; fields *;`, id)
return g.GetEventNetworks(query)
}
func (g *Client) GetEventNetworksByEventIDs(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 event = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetEventNetworks(idStr)
}
func (g *Client) GetEventNetworksByNetworkTypeID(id uint64) ([]*pb.EventNetwork, error) {
query := fmt.Sprintf(`where network_type = %d; fields *;`, id)
return g.GetEventNetworks(query)
}
func (g *Client) GetEventNetworksByNetworkTypeIDs(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 network_type = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetEventNetworks(idStr)
}
func (g *Client) GetEventNetworksLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
eventNetworks, err := g.GetEventNetworks(query)
if err != nil {
return 0, err
}
return int(eventNetworks[0].Id), nil
}

73
events.go Normal file
View File

@@ -0,0 +1,73 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetEventsByEventLogoID(id uint64) ([]*pb.Event, error) {
query := fmt.Sprintf(`where event_logo = %d; fields *;`, id)
return g.GetEvents(query)
}
func (g *Client) GetEventsByEventLogoIDs(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 event_logo = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetEvents(idStr)
}
func (g *Client) GetEventsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
events, err := g.GetEvents(query)
if err != nil {
return 0, err
}
return int(events[0].Id), nil
}

57
external_game_sources.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetExternalGameSourcesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
externalGameSources, err := g.GetExternalGameSources(query)
if err != nil {
return 0, err
}
return int(externalGameSources[0].Id), nil
}

129
external_games.go Normal file
View File

@@ -0,0 +1,129 @@
package igdb
import (
"fmt"
"strconv"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetExternalGamesByGameID(id uint64) ([]*pb.ExternalGame, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetExternalGames(query)
}
func (g *Client) GetExternalGamesByExternalGameSourceID(id uint64) ([]*pb.ExternalGame, error) {
query := fmt.Sprintf(`where external_game_source = %d; fields *;`, id)
return g.GetExternalGames(query)
}
func (g *Client) GetExternalGamesByExternalGameSourceIDs(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 external_game_source = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetExternalGames(idStr)
}
func (g *Client) GetExternalGamesByGameReleaseFormatID(id uint64) ([]*pb.ExternalGame, error) {
query := fmt.Sprintf(`where game_release_format = %d; fields *;`, id)
return g.GetExternalGames(query)
}
func (g *Client) GetExternalGamesByGameReleaseFormatIDs(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 game_release_format = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetExternalGames(idStr)
}
func (g *Client) GetExternalGamesByPlatformVersionID(id uint64) ([]*pb.ExternalGame, error) {
query := fmt.Sprintf(`where platform_version = %d; fields *;`, id)
return g.GetExternalGames(query)
}
func (g *Client) GetExternalGamesByPlatformVersionIDs(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 platform_version = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetExternalGames(idStr)
}
func (g *Client) GetExternalGamesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
externalGames, err := g.GetExternalGames(query)
if err != nil {
return 0, err
}
return int(externalGames[0].Id), nil
}

57
franchises.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetFranchisesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
franchises, err := g.GetFranchises(query)
if err != nil {
return 0, err
}
return int(franchises[0].Id), nil
}

63
game.go
View File

@@ -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
}

57
game_engine_logos.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetGameEngineLogosLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
gameEngineLogos, err := g.GetGameEngineLogos(query)
if err != nil {
return 0, err
}
return int(gameEngineLogos[0].Id), nil
}

89
game_engines.go Normal file
View File

@@ -0,0 +1,89 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetGameEnginesByGameID(id uint64) ([]*pb.GameEngine, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetGameEngines(query)
}
func (g *Client) GetGameEnginesByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGameEngines(idStr)
}
func (g *Client) GetGameEnginesByLogoID(id uint64) ([]*pb.GameEngine, error) {
query := fmt.Sprintf(`where logo = %d; fields *;`, id)
return g.GetGameEngines(query)
}
func (g *Client) GetGameEnginesByLogoIDs(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 logo = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGameEngines(idStr)
}
func (g *Client) GetGameEnginesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
gameEngines, err := g.GetGameEngines(query)
if err != nil {
return 0, err
}
return int(gameEngines[0].Id), nil
}

105
game_localizations.go Normal file
View File

@@ -0,0 +1,105 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetGameLocalizationsByGameID(id uint64) ([]*pb.GameLocalization, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetGameLocalizations(query)
}
func (g *Client) GetGameLocalizationsByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGameLocalizations(idStr)
}
func (g *Client) GetGameLocalizationsByCoverID(id uint64) ([]*pb.GameLocalization, error) {
query := fmt.Sprintf(`where cover = %d; fields *;`, id)
return g.GetGameLocalizations(query)
}
func (g *Client) GetGameLocalizationsByCoverIDs(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 cover = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGameLocalizations(idStr)
}
func (g *Client) GetGameLocalizationsByRegionID(id uint64) ([]*pb.GameLocalization, error) {
query := fmt.Sprintf(`where region = %d; fields *;`, id)
return g.GetGameLocalizations(query)
}
func (g *Client) GetGameLocalizationsByRegionIDs(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 region = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGameLocalizations(idStr)
}
func (g *Client) GetGameLocalizationsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
gameLocalizations, err := g.GetGameLocalizations(query)
if err != nil {
return 0, err
}
return int(gameLocalizations[0].Id), nil
}

57
game_modes.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetGameModesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
gameModes, err := g.GetGameModes(query)
if err != nil {
return 0, err
}
return int(gameModes[0].Id), nil
}

57
game_release_formats.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetGameReleaseFormatsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
gameReleaseFormats, err := g.GetGameReleaseFormats(query)
if err != nil {
return 0, err
}
return int(gameReleaseFormats[0].Id), nil
}

57
game_statuses.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetGameStatusesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
gameStatuses, err := g.GetGameStatuses(query)
if err != nil {
return 0, err
}
return int(gameStatuses[0].Id), nil
}

73
game_time_to_beats.go Normal file
View File

@@ -0,0 +1,73 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetGameTimeToBeatsByGameID(id uint64) ([]*pb.GameTimeToBeat, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetGameTimeToBeats(query)
}
func (g *Client) GetGameTimeToBeatsByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGameTimeToBeats(idStr)
}
func (g *Client) GetGameTimeToBeatsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
gameTimeToBeats, err := g.GetGameTimeToBeats(query)
if err != nil {
return 0, err
}
return int(gameTimeToBeats[0].Id), nil
}

57
game_types.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetGameTypesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
gameTypes, err := g.GetGameTypes(query)
if err != nil {
return 0, err
}
return int(gameTypes[0].Id), nil
}

View File

@@ -0,0 +1,89 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetGameVersionFeatureValuesByGameID(id uint64) ([]*pb.GameVersionFeatureValue, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetGameVersionFeatureValues(query)
}
func (g *Client) GetGameVersionFeatureValuesByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGameVersionFeatureValues(idStr)
}
func (g *Client) GetGameVersionFeatureValuesByGameVersionFeatureID(id uint64) ([]*pb.GameVersionFeatureValue, error) {
query := fmt.Sprintf(`where game_version_feature = %d; fields *;`, id)
return g.GetGameVersionFeatureValues(query)
}
func (g *Client) GetGameVersionFeatureValuesByGameVersionFeatureIDs(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 game_version_feature = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGameVersionFeatureValues(idStr)
}
func (g *Client) GetGameVersionFeatureValuesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
gameVersionFeatureValues, err := g.GetGameVersionFeatureValues(query)
if err != nil {
return 0, err
}
return int(gameVersionFeatureValues[0].Id), nil
}

57
game_version_features.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetGameVersionFeaturesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
gameVersionFeatures, err := g.GetGameVersionFeatures(query)
if err != nil {
return 0, err
}
return int(gameVersionFeatures[0].Id), nil
}

73
game_versions.go Normal file
View File

@@ -0,0 +1,73 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetGameVersionsByGameID(id uint64) ([]*pb.GameVersion, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetGameVersions(query)
}
func (g *Client) GetGameVersionsByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGameVersions(idStr)
}
func (g *Client) GetGameVersionsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
gameVersions, err := g.GetGameVersions(query)
if err != nil {
return 0, err
}
return int(gameVersions[0].Id), nil
}

73
game_videos.go Normal file
View File

@@ -0,0 +1,73 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetGameVideosByGameID(id uint64) ([]*pb.GameVideo, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetGameVideos(query)
}
func (g *Client) GetGameVideosByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGameVideos(idStr)
}
func (g *Client) GetGameVideosLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
gameVideos, err := g.GetGameVideos(query)
if err != nil {
return 0, err
}
return int(gameVideos[0].Id), nil
}

169
games.go Normal file
View File

@@ -0,0 +1,169 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetGameByCollectionID(id uint64) ([]*pb.Game, error) {
query := fmt.Sprintf(`where collection = %d; fields *;`, id)
return g.GetGames(query)
}
func (g *Client) GetGamesByCollectionIDs(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 collection = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGames(idStr)
}
func (g *Client) GetGameByCoverID(id uint64) ([]*pb.Game, error) {
query := fmt.Sprintf(`where cover = %d; fields *;`, id)
return g.GetGames(query)
}
func (g *Client) GetGamesByCoverIDs(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 cover = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGames(idStr)
}
func (g *Client) GetGameByFranchiseID(id uint64) ([]*pb.Game, error) {
query := fmt.Sprintf(`where franchise = %d; fields *;`, id)
return g.GetGames(query)
}
func (g *Client) GetGamesByFranchiseIDs(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 franchise = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGames(idStr)
}
func (g *Client) GetGameByGameStatusID(id uint64) ([]*pb.Game, error) {
query := fmt.Sprintf(`where game_status = %d; fields *;`, id)
return g.GetGames(query)
}
func (g *Client) GetGamesByGameStatusIDs(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 game_status = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGames(idStr)
}
func (g *Client) GetGameByGameTypeID(id uint64) ([]*pb.Game, error) {
query := fmt.Sprintf(`where game_type = %d; fields *;`, id)
return g.GetGames(query)
}
func (g *Client) GetGamesByGameTypeIDs(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 game_type = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGames(idStr)
}
func (g *Client) GetGameByParentGameID(id uint64) ([]*pb.Game, error) {
query := fmt.Sprintf(`where parent_game = %d; fields *;`, id)
return g.GetGames(query)
}
func (g *Client) GetGamesByParentGameIDs(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 parent_game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGames(idStr)
}
func (g *Client) GetGameByVersionParentGameID(id uint64) ([]*pb.Game, error) {
query := fmt.Sprintf(`where version_parent = %d; fields *;`, id)
return g.GetGames(query)
}
func (g *Client) GetGamesByVersionParentGameIDs(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 version_parent = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetGames(idStr)
}
func (g *Client) GetGamesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
games, err := g.GetGames(query)
if err != nil {
return 0, err
}
return int(games[0].Id), nil
}

57
genres.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetGenresLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
genres, err := g.GetGenres(query)
if err != nil {
return 0, err
}
return int(genres[0].Id), nil
}

2
go.mod
View File

@@ -1,4 +1,4 @@
module github/bestnite/go-igdb
module github.com/bestnite/go-igdb
go 1.24.1

49
id.go
View File

@@ -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)
}

23
igdb.go
View File

@@ -7,32 +7,37 @@ import (
"github.com/go-resty/resty/v2"
)
type igdb struct {
type Client struct {
clientID string
token *twitchToken
flaresolverr *flaresolverr.Flaresolverr
limiter *rateLimiter
}
func New(clientID, clientSecret string) *igdb {
return &igdb{
func New(clientID, clientSecret string) *Client {
return &Client{
clientID: clientID,
limiter: newRateLimiter(4),
token: NewTwitchToken(clientID, clientSecret),
flaresolverr: nil,
}
}
func NewWithFlaresolverr(clientID, clientSecret string, f *flaresolverr.Flaresolverr) *igdb {
return &igdb{
func NewWithFlaresolverr(clientID, clientSecret string, f *flaresolverr.Flaresolverr) *Client {
return &Client{
clientID: clientID,
limiter: newRateLimiter(4),
token: NewTwitchToken(clientID, clientSecret),
flaresolverr: f,
}
}
func (g *igdb) Request(URL string, dataBody any) (*resty.Response, error) {
func (g *Client) Request(URL string, dataBody any) (*resty.Response, error) {
g.limiter.wait()
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,12 +48,12 @@ 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
}
func (g *igdb) getFlaresolverr() (*flaresolverr.Flaresolverr, error) {
func (g *Client) getFlaresolverr() (*flaresolverr.Flaresolverr, error) {
if g.flaresolverr == nil {
return nil, fmt.Errorf("flaresolverr is not initialized")
}

89
involved_companies.go Normal file
View File

@@ -0,0 +1,89 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetInvolvedCompaniesByGameID(id uint64) ([]*pb.InvolvedCompany, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetInvolvedCompanies(query)
}
func (g *Client) GetInvolvedCompaniesByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetInvolvedCompanies(idStr)
}
func (g *Client) GetInvolvedCompaniesByCompanyID(id uint64) ([]*pb.InvolvedCompany, error) {
query := fmt.Sprintf(`where company = %d; fields *;`, id)
return g.GetInvolvedCompanies(query)
}
func (g *Client) GetInvolvedCompaniesByCompanyIDs(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 company = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetInvolvedCompanies(idStr)
}
func (g *Client) GetInvolvedCompaniesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
involvedCompanies, err := g.GetInvolvedCompanies(query)
if err != nil {
return 0, err
}
return int(involvedCompanies[0].Id), nil
}

57
keywords.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetKeywordsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
keywords, err := g.GetKeywords(query)
if err != nil {
return 0, err
}
return int(keywords[0].Id), nil
}

57
language_support_types.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetLanguageSupportTypesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
languageSupportTypes, err := g.GetLanguageSupportTypes(query)
if err != nil {
return 0, err
}
return int(languageSupportTypes[0].Id), nil
}

105
language_supports.go Normal file
View File

@@ -0,0 +1,105 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetLanguageSupportsByGameID(id uint64) ([]*pb.LanguageSupport, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetLanguageSupports(query)
}
func (g *Client) GetLanguageSupportsByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetLanguageSupports(idStr)
}
func (g *Client) GetLanguageSupportsByLanguageID(id uint64) ([]*pb.LanguageSupport, error) {
query := fmt.Sprintf(`where language = %d; fields *;`, id)
return g.GetLanguageSupports(query)
}
func (g *Client) GetLanguageSupportsByLanguageIDs(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 language = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetLanguageSupports(idStr)
}
func (g *Client) GetLanguageSupportsByLanguageSupportTypeID(id uint64) ([]*pb.LanguageSupport, error) {
query := fmt.Sprintf(`where language_support_type = %d; fields *;`, id)
return g.GetLanguageSupports(query)
}
func (g *Client) GetLanguageSupportsByLanguageSupportTypeIDs(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 language_support_type = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetLanguageSupports(idStr)
}
func (g *Client) GetLanguageSupportsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
languageSupports, err := g.GetLanguageSupports(query)
if err != nil {
return 0, err
}
return int(languageSupports[0].Id), nil
}

57
languages.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetLanguagesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
languages, err := g.GetLanguages(query)
if err != nil {
return 0, err
}
return int(languages[0].Id), nil
}

89
multiplayer_modes.go Normal file
View File

@@ -0,0 +1,89 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetMultiplayerModesByGameID(id uint64) ([]*pb.MultiplayerMode, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetMultiplayerModes(query)
}
func (g *Client) GetMultiplayerModesByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetMultiplayerModes(idStr)
}
func (g *Client) GetMultiplayerModesByPlatformID(id uint64) ([]*pb.MultiplayerMode, error) {
query := fmt.Sprintf(`where platform = %d; fields *;`, id)
return g.GetMultiplayerModes(query)
}
func (g *Client) GetMultiplayerModesByPlatformIDs(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 platform = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetMultiplayerModes(idStr)
}
func (g *Client) GetMultiplayerModesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
multiplayerModes, err := g.GetMultiplayerModes(query)
if err != nil {
return 0, err
}
return int(multiplayerModes[0].Id), nil
}

57
network_types.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetNetworkTypesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
networkTypes, err := g.GetNetworkTypes(query)
if err != nil {
return 0, err
}
return int(networkTypes[0].Id), nil
}

View File

@@ -4,22 +4,22 @@ import (
"fmt"
)
func (g *igdb) GetParentGameID(id uint64) (uint64, error) {
detail, err := g.GetGame(id)
func (g *Client) GetParentGameID(id uint64) (uint64, error) {
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)
}

57
platform_families.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetPlatformFamiliesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
platformFamilies, err := g.GetPlatformFamilies(query)
if err != nil {
return 0, err
}
return int(platformFamilies[0].Id), nil
}

57
platform_logos.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetPlatformLogosLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
platformLogos, err := g.GetPlatformLogos(query)
if err != nil {
return 0, err
}
return int(platformLogos[0].Id), nil
}

57
platform_types.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetPlatformTypesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
platformTypes, err := g.GetPlatformTypes(query)
if err != nil {
return 0, err
}
return int(platformTypes[0].Id), nil
}

View File

@@ -0,0 +1,73 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetPlatformVersionCompaniesByCompanyID(id uint64) ([]*pb.PlatformVersionCompany, error) {
query := fmt.Sprintf(`where company = %d; fields *;`, id)
return g.GetPlatformVersionCompanies(query)
}
func (g *Client) GetPlatformVersionCompaniesByCompanyIDs(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 company = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetPlatformVersionCompanies(idStr)
}
func (g *Client) GetPlatformVersionCompaniesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
platformVersionCompanies, err := g.GetPlatformVersionCompanies(query)
if err != nil {
return 0, err
}
return int(platformVersionCompanies[0].Id), nil
}

View File

@@ -0,0 +1,105 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetPlatformVersionReleaseDatesByPlatformVersionID(id uint64) ([]*pb.PlatformVersionReleaseDate, error) {
query := fmt.Sprintf(`where platform_version = %d; fields *;`, id)
return g.GetPlatformVersionReleaseDates(query)
}
func (g *Client) GetPlatformVersionReleaseDatesByPlatformVersionIDs(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 platform_version = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetPlatformVersionReleaseDates(idStr)
}
func (g *Client) GetPlatformVersionReleaseDatesByReleaseRegionID(id uint64) ([]*pb.PlatformVersionReleaseDate, error) {
query := fmt.Sprintf(`where release_region = %d; fields *;`, id)
return g.GetPlatformVersionReleaseDates(query)
}
func (g *Client) GetPlatformVersionReleaseDatesByReleaseRegionIDs(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 release_region = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetPlatformVersionReleaseDates(idStr)
}
func (g *Client) GetPlatformVersionReleaseDatesByDateFormatID(id uint64) ([]*pb.PlatformVersionReleaseDate, error) {
query := fmt.Sprintf(`where date_format = %d; fields *;`, id)
return g.GetPlatformVersionReleaseDates(query)
}
func (g *Client) GetPlatformVersionReleaseDatesByDateFormatIDs(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 date_format = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetPlatformVersionReleaseDates(idStr)
}
func (g *Client) GetPlatformVersionReleaseDatesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
platformVersionReleaseDates, err := g.GetPlatformVersionReleaseDates(query)
if err != nil {
return 0, err
}
return int(platformVersionReleaseDates[0].Id), nil
}

89
platform_versions.go Normal file
View File

@@ -0,0 +1,89 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetPlatformVersionsByMainManufacturerID(id uint64) ([]*pb.PlatformVersion, error) {
query := fmt.Sprintf(`where main_manufacturer = %d; fields *;`, id)
return g.GetPlatformVersions(query)
}
func (g *Client) GetPlatformVersionsByMainManufacturerIDs(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 main_manufacturer = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetPlatformVersions(idStr)
}
func (g *Client) GetPlatformVersionsByPlatformLogoID(id uint64) ([]*pb.PlatformVersion, error) {
query := fmt.Sprintf(`where platform_logo = %d; fields *;`, id)
return g.GetPlatformVersions(query)
}
func (g *Client) GetPlatformVersionsByPlatformLogoIDs(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 platform_logo = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetPlatformVersions(idStr)
}
func (g *Client) GetPlatformVersionsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
platformVersions, err := g.GetPlatformVersions(query)
if err != nil {
return 0, err
}
return int(platformVersions[0].Id), nil
}

57
platform_websites.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetPlatformWebsitesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
platformWebsites, err := g.GetPlatformWebsites(query)
if err != nil {
return 0, err
}
return int(platformWebsites[0].Id), nil
}

104
platforms.go Normal file
View File

@@ -0,0 +1,104 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetPlatformsByPlatformFamilyID(id uint64) ([]*pb.Platform, error) {
query := fmt.Sprintf(`where platform_family = %d; fields *;`, id)
return g.GetPlatforms(query)
}
func (g *Client) GetPlatformsByPlatformFamilyIDs(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 platform_family = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetPlatforms(idStr)
}
func (g *Client) GetPlatformsByPlatformLogoID(id uint64) ([]*pb.Platform, error) {
query := fmt.Sprintf(`where platform_logo = %d; fields *;`, id)
return g.GetPlatforms(query)
}
func (g *Client) GetPlatformsByPlatformLogoIDs(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 platform_logo = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetPlatforms(idStr)
}
func (g *Client) GetPlatformsByPlatformTypeID(id uint64) ([]*pb.Platform, error) {
query := fmt.Sprintf(`where platform_type = %d; fields *;`, id)
return g.GetPlatforms(query)
}
func (g *Client) GetPlatformsByPlatformTypeIDs(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 platform_type = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetPlatforms(idStr)
}
func (g *Client) GetPlatformsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
platforms, err := g.GetPlatforms(query)
if err != nil {
return 0, err
}
return int(platforms[0].Id), nil
}

57
player_perspectives.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetPlayerPerspectivesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
playerPerspectives, err := g.GetPlayerPerspectives(query)
if err != nil {
return 0, err
}
return int(playerPerspectives[0].Id), nil
}

View File

@@ -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
}

83
popularity_primitives.go Normal file
View File

@@ -0,0 +1,83 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetPopularityPrimitivesByExternalPopularitySourceID(id uint64) ([]*pb.PopularityPrimitive, error) {
query := fmt.Sprintf(`where external_popularity_source = %d; fields *;`, id)
return g.GetPopularityPrimitives(query)
}
func (g *Client) GetPopularityPrimitivesByExternalPopularitySourceIDs(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 external_popularity_source = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetPopularityPrimitives(idStr)
}
func (g *Client) GetPopularityPrimitivesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
popularityPrimitives, err := g.GetPopularityPrimitives(query)
if err != nil {
return 0, err
}
return int(popularityPrimitives[0].Id), nil
}

73
popularity_types.go Normal file
View File

@@ -0,0 +1,73 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetPopularityTypesByExternalPopularitySourceID(id uint64) ([]*pb.PopularityType, error) {
query := fmt.Sprintf(`where external_popularity_source = %d; fields *;`, id)
return g.GetPopularityTypes(query)
}
func (g *Client) GetPopularityTypesByExternalPopularitySourceIDs(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 external_popularity_source = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetPopularityTypes(idStr)
}
func (g *Client) GetPopularityTypesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
popularityTypes, err := g.GetPopularityTypes(query)
if err != nil {
return 0, err
}
return int(popularityTypes[0].Id), nil
}

48
rate_limiter.go Normal file
View File

@@ -0,0 +1,48 @@
package igdb
import (
"sync"
"time"
)
type rateLimiter struct {
mu sync.Mutex
rate int
interval time.Duration
tokens int
lastRefill time.Time
}
func newRateLimiter(rate int) *rateLimiter {
return &rateLimiter{
rate: rate,
interval: time.Second,
tokens: rate,
lastRefill: time.Now(),
}
}
func (r *rateLimiter) wait() {
r.mu.Lock()
defer r.mu.Unlock()
now := time.Now()
elapsed := now.Sub(r.lastRefill)
if elapsed >= r.interval {
r.tokens = r.rate
r.lastRefill = now
}
if r.tokens <= 0 {
waitTime := r.interval - elapsed
r.mu.Unlock()
time.Sleep(waitTime)
r.mu.Lock()
r.tokens = r.rate - 1
r.lastRefill = time.Now()
return
}
r.tokens--
}

57
regions.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetRegionsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
regions, err := g.GetRegions(query)
if err != nil {
return 0, err
}
return int(regions[0].Id), nil
}

57
release_date_regions.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetReleaseDateRegionsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
releaseDateRegions, err := g.GetReleaseDateRegions(query)
if err != nil {
return 0, err
}
return int(releaseDateRegions[0].Id), nil
}

57
release_date_statuses.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetReleaseDateStatusesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
releaseDateStatuses, err := g.GetReleaseDateStatuses(query)
if err != nil {
return 0, err
}
return int(releaseDateStatuses[0].Id), nil
}

121
release_dates.go Normal file
View File

@@ -0,0 +1,121 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetReleaseDatesByGameID(id uint64) ([]*pb.ReleaseDate, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetReleaseDates(query)
}
func (g *Client) GetReleaseDatesByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetReleaseDates(idStr)
}
func (g *Client) GetReleaseDatesByPlatformID(id uint64) ([]*pb.ReleaseDate, error) {
query := fmt.Sprintf(`where platform = %d; fields *;`, id)
return g.GetReleaseDates(query)
}
func (g *Client) GetReleaseDatesByPlatformIDs(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 platform = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetReleaseDates(idStr)
}
func (g *Client) GetReleaseDatesByReleaseRegionID(id uint64) ([]*pb.ReleaseDate, error) {
query := fmt.Sprintf(`where release_region = %d; fields *;`, id)
return g.GetReleaseDates(query)
}
func (g *Client) GetReleaseDatesByReleaseRegionIDs(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 release_region = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetReleaseDates(idStr)
}
func (g *Client) GetReleaseDatesByStatusID(id uint64) ([]*pb.ReleaseDate, error) {
query := fmt.Sprintf(`where status = %d; fields *;`, id)
return g.GetReleaseDates(query)
}
func (g *Client) GetReleaseDatesByStatusIDs(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 status = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetReleaseDates(idStr)
}
func (g *Client) GetReleaseDatesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
releaseDates, err := g.GetReleaseDates(query)
if err != nil {
return 0, err
}
return int(releaseDates[0].Id), nil
}

73
screenshots.go Normal file
View File

@@ -0,0 +1,73 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetScreenshotsByGameID(id uint64) ([]*pb.Screenshot, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetScreenshots(query)
}
func (g *Client) GetScreenshotsByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetScreenshots(idStr)
}
func (g *Client) GetScreenshotsLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
screenshots, err := g.GetScreenshots(query)
if err != nil {
return 0, err
}
return int(screenshots[0].Id), nil
}

View File

@@ -3,48 +3,47 @@ package igdb
import (
"encoding/json"
"fmt"
"github/bestnite/go-igdb/constant"
"io"
"net/http"
"net/url"
"strings"
"time"
pb "github/bestnite/go-igdb/proto"
pb "github.com/bestnite/go-igdb/proto"
"github.com/PuerkitoBio/goquery"
"github.com/bestnite/go-flaresolverr"
"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 *Client) 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 *Client) 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)
}

57
themes.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetThemesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
themes, err := g.GetThemes(query)
if err != nil {
return 0, err
}
return int(themes[0].Id), nil
}

View File

@@ -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)

View File

@@ -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())
}

26
webhooks.go Normal file
View File

@@ -0,0 +1,26 @@
package igdb
import (
"fmt"
"net/http"
"net/url"
"github.com/bestnite/go-igdb/endpoint"
)
func (g *Client) 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())
}

57
website_types.go Normal file
View File

@@ -0,0 +1,57 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetWebsiteTypesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
websiteTypes, err := g.GetWebsiteTypes(query)
if err != nil {
return 0, err
}
return int(websiteTypes[0].Id), nil
}

89
websites.go Normal file
View File

@@ -0,0 +1,89 @@
package igdb
import (
"fmt"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *Client) 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 *Client) 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 *Client) 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)
}
func (g *Client) GetWebsitesByGameID(id uint64) ([]*pb.Website, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetWebsites(query)
}
func (g *Client) GetWebsitesByGameIDs(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 game = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetWebsites(idStr)
}
func (g *Client) GetWebsitesByTypeID(id uint64) ([]*pb.Website, error) {
query := fmt.Sprintf(`where type = %d; fields *;`, id)
return g.GetWebsites(query)
}
func (g *Client) GetWebsitesByTypeIDs(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 type = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetWebsites(idStr)
}
func (g *Client) GetWebsitesLength() (int, error) {
query := `fields *; sort id desc; limit 1;`
websites, err := g.GetWebsites(query)
if err != nil {
return 0, err
}
return int(websites[0].Id), nil
}