Compare commits

...

13 Commits
v0.0.3 ... main

Author SHA1 Message Date
5cb4ab4c61 u 2025-04-09 17:10:53 +10:00
ecf81bcf79 u 2025-04-07 22:28:43 +10:00
cf1f68c2d8 u 2025-04-07 22:25:58 +10:00
fb58744928 u 2025-04-07 22:23:36 +10:00
3d28910178 README 2025-04-06 13:24:02 +10:00
a583940e21
Create LICENSE 2025-04-06 13:21:34 +10:00
194e84c258 u 2025-04-06 03:33:02 +10:00
a8e650e4d7 u 2025-04-06 03:24:50 +10:00
f88ba544c2 README 2025-04-06 00:28:55 +11:00
d550f859a7 u 2025-04-06 00:28:00 +11:00
7f5a09098a u 2025-04-05 18:45:17 +11:00
35c27b28a3 u 2025-04-05 16:29:30 +11:00
dab30b4938 fix 2025-04-05 12:18:58 +11:00
154 changed files with 3656 additions and 5447 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
*test.go *test.go
test/ test/
.vscode/
.idea/

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Nite
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

120
README.md
View File

@ -1,15 +1,15 @@
# go-igdb # go-igdb
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. A Go client library for the IGDB (Internet Game Database) API v4. This library provides a convenient way to interact with IGDB's protobuf-based API endpoints.
## Features ## Features
- Full support for IGDB API v4 - Full support for IGDB API v4 endpoints
- Protobuf-based communication for better performance - Protobuf-based communication for efficient data transfer
- Rate limiting support
- Automatic token management for Twitch authentication - Automatic token management for Twitch authentication
- Built-in retry mechanism for failed requests - Retry mechanism for failed requests
- Optional Cloudflare bypass support via FlareSolverr - Optional FlareSolverr integration for handling Cloudflare protection
- All endpoints are supported
## Installation ## Installation
@ -20,42 +20,94 @@ go get github.com/bestnite/go-igdb
## Quick Start ## Quick Start
```go ```go
// Create a new IGDB client package main
import (
"log"
"github.com/bestnite/go-igdb"
)
func Test1(c *igdb.Client) {
game, err := c.Games.GetByID(1942)
if err != nil {
log.Fatal(err)
}
log.Printf("Name of game %d: %s\n", 1942, game.Name)
}
func Test2(c *igdb.Client) {
games, err := c.Games.GetByIDs([]uint64{119171, 119133})
if err != nil {
log.Fatal(err)
}
log.Printf("Names of games %d and %d: %s and %s\n", 119171, 119133, games[0].Name, games[1].Name)
}
func Test3(c *igdb.Client) {
total, err := c.Games.Count()
if err != nil {
log.Fatal(err)
}
log.Printf("Total number of games: %d\n", total)
}
func Test4(c *igdb.Client) {
games, err := c.Games.Paginated(0, 10)
if err != nil {
log.Fatal(err)
}
log.Printf("Names of ids 0 to 10 games:\n")
for _, game := range games {
log.Println(game.Name)
}
}
func Test5(c *igdb.Client) {
game, err := c.Games.Query("fields name,rating; sort rating desc; limit 1;")
if err != nil {
log.Fatalf("failed to get game: %s", err)
}
log.Printf("Name of first game with highest rating: %s\n", game[0].Name)
}
func Test6(c *igdb.Client) {
games, err := c.Games.Query("fields *; where rating > 70; limit 10;")
if err != nil {
panic(err)
}
log.Printf("Names of games with rating > 70 limit 10:\n")
for _, game := range games {
log.Println(game.Name)
}
}
func main() {
client := igdb.New("your-client-id", "your-client-secret") client := igdb.New("your-client-id", "your-client-secret")
Test1(client)
// Get a game by ID Test2(client)
game, err := client.GetGameByID(1942) Test3(client)
if err != nil { Test4(client)
log.Fatal(err) Test5(client)
} Test6(client)
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)
} }
``` ```
## Advanced Usage ## Example Projects
### Query Format - [igdb-database](https://github.com/bestnite/igdb-database)
The library uses IGDB's query syntax. For example: ## Dependencies
```go - [go-resty/resty](https://github.com/go-resty/resty)
// Get games released in 2023 - [google/protobuf](https://github.com/google/protobuf)
games, err := client.GetGames("where release_dates.y = 2023; fields name,rating;") - [bestnite/go-flaresolverr](https://github.com/bestnite/go-flaresolverr)
- [PuerkitoBio/goquery](https://github.com/PuerkitoBio/goquery)
// 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 ## Contributing
Contributions are welcome! Please feel free to submit a Pull Request. Contributions are welcome! Please feel free to submit a Pull Request.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

View File

@ -1,72 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetAgeRatingCategories(query string) ([]*pb.AgeRatingCategory, error) {
resp, err := g.Request("https://api.igdb.com/v4/age_rating_categories.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.AgeRatingCategoryResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Ageratingcategories) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Ageratingcategories, nil
}
func (g *igdb) GetAgeRatingCategoryByID(id uint64) (*pb.AgeRatingCategory, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
ageRatingCategories, err := g.GetAgeRatingCategories(query)
if err != nil {
return nil, err
}
return ageRatingCategories[0], nil
}
func (g *igdb) GetAgeRatingCategoriesByIDs(ids []uint64) ([]*pb.AgeRatingCategory, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetAgeRatingCategories(idStr)
}
func (g *igdb) GetAgeRatingCategoriesByOrganizationID(id uint64) ([]*pb.AgeRatingCategory, error) {
query := fmt.Sprintf(`where organization = %d; fields *;`, id)
return g.GetAgeRatingCategories(query)
}
func (g *igdb) 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 *igdb) 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

@ -1,56 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetAgeRatingContentDescriptions(query string) ([]*pb.AgeRatingContentDescription, error) {
resp, err := g.Request("https://api.igdb.com/v4/age_rating_content_descriptions.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.AgeRatingContentDescriptionResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Ageratingcontentdescriptions) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Ageratingcontentdescriptions, nil
}
func (g *igdb) GetAgeRatingContentDescriptionByID(id uint64) (*pb.AgeRatingContentDescription, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
ageRatingContentDescriptions, err := g.GetAgeRatingContentDescriptions(query)
if err != nil {
return nil, err
}
return ageRatingContentDescriptions[0], nil
}
func (g *igdb) GetAgeRatingContentDescriptionsByIDs(ids []uint64) ([]*pb.AgeRatingContentDescription, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetAgeRatingContentDescriptions(idStr)
}
func (g *igdb) 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

@ -1,72 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetAgeRatingContentDescriptionsV2(query string) ([]*pb.AgeRatingContentDescriptionV2, error) {
resp, err := g.Request("https://api.igdb.com/v4/age_rating_content_descriptions_v2.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.AgeRatingContentDescriptionV2Result{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Ageratingcontentdescriptionsv2) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Ageratingcontentdescriptionsv2, nil
}
func (g *igdb) GetAgeRatingContentDescriptionV2ByID(id uint64) (*pb.AgeRatingContentDescriptionV2, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
ageRatingContentDescriptions, err := g.GetAgeRatingContentDescriptionsV2(query)
if err != nil {
return nil, err
}
return ageRatingContentDescriptions[0], nil
}
func (g *igdb) GetAgeRatingContentDescriptionsV2ByIDs(ids []uint64) ([]*pb.AgeRatingContentDescriptionV2, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetAgeRatingContentDescriptionsV2(idStr)
}
func (g *igdb) GetAgeRatingContentDescriptionsV2ByOrganizationID(id uint64) ([]*pb.AgeRatingContentDescriptionV2, error) {
query := fmt.Sprintf(`where organization = %d; fields *;`, id)
return g.GetAgeRatingContentDescriptionsV2(query)
}
func (g *igdb) 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 *igdb) 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

@ -1,56 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetAgeRatingOrganizations(query string) ([]*pb.AgeRatingOrganization, error) {
resp, err := g.Request("https://api.igdb.com/v4/age_rating_organizations.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.AgeRatingOrganizationResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Ageratingorganizations) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Ageratingorganizations, nil
}
func (g *igdb) GetAgeRatingOrganizationByID(id uint64) (*pb.AgeRatingOrganization, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
ageRatingOrganizations, err := g.GetAgeRatingOrganizations(query)
if err != nil {
return nil, err
}
return ageRatingOrganizations[0], nil
}
func (g *igdb) GetAgeRatingOrganizationsByIDs(ids []uint64) ([]*pb.AgeRatingOrganization, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetAgeRatingOrganizations(idStr)
}
func (g *igdb) 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
}

View File

@ -1,88 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetAgeRatings(query string) ([]*pb.AgeRating, error) {
resp, err := g.Request("https://api.igdb.com/v4/age_ratings.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.AgeRatingResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Ageratings) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Ageratings, nil
}
func (g *igdb) GetAgeRatingByID(id uint64) (*pb.AgeRating, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
ageRatings, err := g.GetAgeRatings(query)
if err != nil {
return nil, err
}
return ageRatings[0], nil
}
func (g *igdb) GetAgeRatingsByIDs(ids []uint64) ([]*pb.AgeRating, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetAgeRatings(idStr)
}
func (g *igdb) GetAgeRatingsByOrganizationID(id uint64) ([]*pb.AgeRating, error) {
query := fmt.Sprintf(`where organization = %d; fields *;`, id)
return g.GetAgeRatings(query)
}
func (g *igdb) 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 *igdb) GetAgeRatingsByAgeRatingCategoryID(id uint64) ([]*pb.AgeRating, error) {
query := fmt.Sprintf(`where rating_category = %d; fields *;`, id)
return g.GetAgeRatings(query)
}
func (g *igdb) 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 *igdb) 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
}

View File

@ -1,72 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetAlternativeNames(query string) ([]*pb.AlternativeName, error) {
resp, err := g.Request("https://api.igdb.com/v4/alternative_names.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.AlternativeNameResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Alternativenames) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Alternativenames, nil
}
func (g *igdb) GetAlternativeNameByID(id uint64) (*pb.AlternativeName, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
alternativeNames, err := g.GetAlternativeNames(query)
if err != nil {
return nil, err
}
return alternativeNames[0], nil
}
func (g *igdb) GetAlternativeNamesByIDs(ids []uint64) ([]*pb.AlternativeName, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetAlternativeNames(idStr)
}
func (g *igdb) GetAlternativeNamesByGameID(id uint64) ([]*pb.AlternativeName, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetAlternativeNames(query)
}
func (g *igdb) 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 *igdb) 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
}

View File

@ -1,73 +0,0 @@
package igdb
import (
"fmt"
"strings"
pb "github/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetArtworks(query string) ([]*pb.Artwork, error) {
resp, err := g.Request("https://api.igdb.com/v4/artworks.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.ArtworkResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Artworks) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Artworks, nil
}
func (g *igdb) GetArtworkByID(id uint64) (*pb.Artwork, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
artworks, err := g.GetArtworks(query)
if err != nil {
return nil, err
}
return artworks[0], nil
}
func (g *igdb) GetArtworksByIDs(ids []uint64) ([]*pb.Artwork, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetArtworks(idStr)
}
func (g *igdb) GetArtworksByGameID(id uint64) ([]*pb.Artwork, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetArtworks(query)
}
func (g *igdb) 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 *igdb) 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
}

View File

@ -1,56 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetCharacterGenders(query string) ([]*pb.CharacterGender, error) {
resp, err := g.Request("https://api.igdb.com/v4/character_genders.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CharacterGenderResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Charactergenders) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Charactergenders, nil
}
func (g *igdb) GetCharacterGenderByID(id uint64) (*pb.CharacterGender, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
characterGenders, err := g.GetCharacterGenders(query)
if err != nil {
return nil, err
}
return characterGenders[0], nil
}
func (g *igdb) GetCharacterGendersByIDs(ids []uint64) ([]*pb.CharacterGender, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCharacterGenders(idStr)
}
func (g *igdb) 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
}

View File

@ -1,56 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetCharacterMugShots(query string) ([]*pb.CharacterMugShot, error) {
resp, err := g.Request("https://api.igdb.com/v4/character_mug_shots.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CharacterMugShotResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Charactermugshots) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Charactermugshots, nil
}
func (g *igdb) GetCharacterMugShotByID(id uint64) (*pb.CharacterMugShot, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
characterMugShots, err := g.GetCharacterMugShots(query)
if err != nil {
return nil, err
}
return characterMugShots[0], nil
}
func (g *igdb) GetCharacterMugShotsByIDs(ids []uint64) ([]*pb.CharacterMugShot, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCharacterMugShots(idStr)
}
func (g *igdb) 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
}

View File

@ -1,56 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetCharacterSpecies(query string) ([]*pb.CharacterSpecie, error) {
resp, err := g.Request("https://api.igdb.com/v4/character_species.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CharacterSpecieResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Characterspecies) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Characterspecies, nil
}
func (g *igdb) GetCharacterSpecieByID(id uint64) (*pb.CharacterSpecie, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
characterSpecies, err := g.GetCharacterSpecies(query)
if err != nil {
return nil, err
}
return characterSpecies[0], nil
}
func (g *igdb) GetCharacterSpeciesByIDs(ids []uint64) ([]*pb.CharacterSpecie, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCharacterSpecies(idStr)
}
func (g *igdb) 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
}

View File

@ -1,105 +0,0 @@
package igdb
import (
"fmt"
"strings"
pb "github/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetCharacters(query string) ([]*pb.Character, error) {
resp, err := g.Request("https://api.igdb.com/v4/characters.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CharacterResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Characters) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Characters, nil
}
func (g *igdb) GetCharacterByID(id uint64) (*pb.Character, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
characters, err := g.GetCharacters(query)
if err != nil {
return nil, err
}
return characters[0], nil
}
func (g *igdb) GetCharactersByIDs(ids []uint64) ([]*pb.Character, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCharacters(idStr)
}
func (g *igdb) GetCharactersByCharacterGenderID(id uint64) ([]*pb.Character, error) {
query := fmt.Sprintf(`where character_gender = %d; fields *;`, id)
return g.GetCharacters(query)
}
func (g *igdb) 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 *igdb) GetCharactersByCharacterSpecieID(id uint64) ([]*pb.Character, error) {
query := fmt.Sprintf(`where character_species = %d; fields *;`, id)
return g.GetCharacters(query)
}
func (g *igdb) 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 *igdb) GetCharactersByMugShotID(id uint64) ([]*pb.Character, error) {
query := fmt.Sprintf(`where mug_shot = %d; fields *;`, id)
return g.GetCharacters(query)
}
func (g *igdb) 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 *igdb) 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
}

132
client.go Normal file
View File

@ -0,0 +1,132 @@
package igdb
import (
"fmt"
"strings"
"github.com/bestnite/go-flaresolverr"
"github.com/bestnite/go-igdb/endpoint"
"github.com/go-resty/resty/v2"
)
type Client struct {
clientID string
token *TwitchToken
flaresolverr *flaresolverr.Flaresolverr
limiter *rateLimiter
AgeRatingCategories *endpoint.AgeRatingCategories
AgeRatingContentDescriptions *endpoint.AgeRatingContentDescriptions
AgeRatingContentDescriptionsV2 *endpoint.AgeRatingContentDescriptionsV2
AgeRatingOrganizations *endpoint.AgeRatingOrganizations
AgeRatings *endpoint.AgeRatings
AlternativeNames *endpoint.AlternativeNames
Artworks *endpoint.Artworks
CharacterGenders *endpoint.CharacterGenders
CharacterMugShots *endpoint.CharacterMugShots
Characters *endpoint.Characters
CharacterSpecies *endpoint.CharacterSpecies
CollectionMemberships *endpoint.CollectionMemberships
CollectionMembershipTypes *endpoint.CollectionMembershipTypes
CollectionRelations *endpoint.CollectionRelations
CollectionRelationTypes *endpoint.CollectionRelationTypes
Collections *endpoint.Collections
CollectionTypes *endpoint.CollectionTypes
Companies *endpoint.Companies
CompanyLogos *endpoint.CompanyLogos
CompanyStatuses *endpoint.CompanyStatuses
CompanyWebsites *endpoint.CompanyWebsites
Covers *endpoint.Covers
DateFormats *endpoint.DateFormats
EventLogos *endpoint.EventLogos
EventNetworks *endpoint.EventNetworks
Events *endpoint.Events
ExternalGames *endpoint.ExternalGames
ExternalGameSources *endpoint.ExternalGameSources
Franchises *endpoint.Franchises
GameEngineLogos *endpoint.GameEngineLogos
GameEngines *endpoint.GameEngines
GameLocalizations *endpoint.GameLocalizations
GameModes *endpoint.GameModes
GameReleaseFormats *endpoint.GameReleaseFormats
Games *endpoint.Games
GameStatuses *endpoint.GameStatuses
GameTimeToBeats *endpoint.GameTimeToBeats
GameTypes *endpoint.GameTypes
GameVersionFeatures *endpoint.GameVersionFeatures
GameVersionFeatureValues *endpoint.GameVersionFeatureValues
GameVersions *endpoint.GameVersions
GameVideos *endpoint.GameVideos
Genres *endpoint.Genres
InvolvedCompanies *endpoint.InvolvedCompanies
Keywords *endpoint.Keywords
Languages *endpoint.Languages
LanguageSupports *endpoint.LanguageSupports
LanguageSupportTypes *endpoint.LanguageSupportTypes
MultiplayerModes *endpoint.MultiplayerModes
NetworkTypes *endpoint.NetworkTypes
PlatformFamilies *endpoint.PlatformFamilies
PlatformLogos *endpoint.PlatformLogos
Platforms *endpoint.Platforms
PlatformTypes *endpoint.PlatformTypes
PlatformVersionCompanies *endpoint.PlatformVersionCompanies
PlatformVersionReleaseDates *endpoint.PlatformVersionReleaseDates
PlatformVersions *endpoint.PlatformVersions
PlatformWebsites *endpoint.PlatformWebsites
PlayerPerspectives *endpoint.PlayerPerspectives
PopularityPrimitives *endpoint.PopularityPrimitives
PopularityTypes *endpoint.PopularityTypes
Regions *endpoint.Regions
ReleaseDateRegions *endpoint.ReleaseDateRegions
ReleaseDates *endpoint.ReleaseDates
ReleaseDateStatuses *endpoint.ReleaseDateStatuses
Screenshots *endpoint.Screenshots
Search *endpoint.Search
Themes *endpoint.Themes
Webhooks *endpoint.Webhooks
Websites *endpoint.Websites
WebsiteTypes *endpoint.WebsiteTypes
}
func New(clientID, clientSecret string) *Client {
c := &Client{
clientID: clientID,
limiter: newRateLimiter(4),
token: NewTwitchToken(clientID, clientSecret),
flaresolverr: nil,
}
registerAllEndpoints(c)
return c
}
type RequestFunc func(method string, URL string, dataBody any) (*resty.Response, error)
func NewWithFlaresolverr(clientID, clientSecret string, f *flaresolverr.Flaresolverr) *Client {
c := New(clientID, clientSecret)
c.flaresolverr = f
return c
}
func (g *Client) Request(method string, 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)
}
resp, err := request().SetBody(dataBody).SetHeaders(map[string]string{
"Client-ID": g.clientID,
"Authorization": "Bearer " + t,
"User-Agent": "",
"Content-Type": "text/plain",
}).Execute(strings.ToUpper(method), URL)
if err != nil {
return nil, fmt.Errorf("failed to request: %s: %w", URL, err)
}
return resp, nil
}

View File

@ -1,72 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetCollectionMembershipTypes(query string) ([]*pb.CollectionMembershipType, error) {
resp, err := g.Request("https://api.igdb.com/v4/collection_membership_types.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CollectionMembershipTypeResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Collectionmembershiptypes) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Collectionmembershiptypes, nil
}
func (g *igdb) GetCollectionMembershipTypeByID(id uint64) (*pb.CollectionMembershipType, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
collectionMembershipTypes, err := g.GetCollectionMembershipTypes(query)
if err != nil {
return nil, err
}
return collectionMembershipTypes[0], nil
}
func (g *igdb) GetCollectionMembershipTypesByIDs(ids []uint64) ([]*pb.CollectionMembershipType, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCollectionMembershipTypes(idStr)
}
func (g *igdb) GetCollectionMembershipTypesByAllowedCollectionTypeID(id uint64) ([]*pb.CollectionMembershipType, error) {
query := fmt.Sprintf(`where allowed_collection_type = %d; fields *;`, id)
return g.GetCollectionMembershipTypes(query)
}
func (g *igdb) 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 *igdb) 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
}

View File

@ -1,93 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetCollectionMemberships(query string) ([]*pb.CollectionMembership, error) {
resp, err := g.Request("https://api.igdb.com/v4/collection_memberships.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CollectionMembershipResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Collectionmemberships) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Collectionmemberships, nil
}
func (g *igdb) GetCollectionMembershipByID(id uint64) (*pb.CollectionMembership, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
collectionMemberships, err := g.GetCollectionMemberships(query)
if err != nil {
return nil, err
}
return collectionMemberships[0], nil
}
func (g *igdb) GetCollectionMembershipsByIDs(ids []uint64) ([]*pb.CollectionMembership, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCollectionMemberships(idStr)
}
func (g *igdb) GetCollectionMembershipsByGameID(id uint64) ([]*pb.CollectionMembership, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetCollectionMemberships(query)
}
func (g *igdb) 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 *igdb) GetCollectionMembershipsByCollectionID(id uint64) ([]*pb.CollectionMembership, error) {
query := fmt.Sprintf(`where collection = %d; fields *;`, id)
return g.GetCollectionMemberships(query)
}
func (g *igdb) GetCollectionMembershipsByCollectionMembershipTypeID(id uint64) ([]*pb.CollectionMembership, error) {
query := fmt.Sprintf(`where type = %d; fields *;`, id)
return g.GetCollectionMemberships(query)
}
func (g *igdb) 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 *igdb) 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

@ -1,88 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetCollectionRelationTypes(query string) ([]*pb.CollectionRelationType, error) {
resp, err := g.Request("https://api.igdb.com/v4/collection_relation_types.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CollectionRelationTypeResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Collectionrelationtypes) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Collectionrelationtypes, nil
}
func (g *igdb) GetCollectionRelationTypeByID(id uint64) (*pb.CollectionRelationType, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
collectionRelationTypes, err := g.GetCollectionRelationTypes(query)
if err != nil {
return nil, err
}
return collectionRelationTypes[0], nil
}
func (g *igdb) GetCollectionRelationTypesByIDs(ids []uint64) ([]*pb.CollectionRelationType, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCollectionRelationTypes(idStr)
}
func (g *igdb) GetCollectionRelationTypesByAllowedChildTypeID(id uint64) ([]*pb.CollectionRelationType, error) {
query := fmt.Sprintf(`where allowed_child_type = %d; fields *;`, id)
return g.GetCollectionRelationTypes(query)
}
func (g *igdb) 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 *igdb) GetCollectionRelationTypesByAllowedParentTypeID(id uint64) ([]*pb.CollectionRelationType, error) {
query := fmt.Sprintf(`where allowed_parent_type = %d; fields *;`, id)
return g.GetCollectionRelationTypes(query)
}
func (g *igdb) 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 *igdb) 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
}

View File

@ -1,104 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetCollectionRelations(query string) ([]*pb.CollectionRelation, error) {
resp, err := g.Request("https://api.igdb.com/v4/collection_relations.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CollectionRelationResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Collectionrelations) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Collectionrelations, nil
}
func (g *igdb) GetCollectionRelationByID(id uint64) (*pb.CollectionRelation, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
collectionRelations, err := g.GetCollectionRelations(query)
if err != nil {
return nil, err
}
return collectionRelations[0], nil
}
func (g *igdb) GetCollectionRelationsByIDs(ids []uint64) ([]*pb.CollectionRelation, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCollectionRelations(idStr)
}
func (g *igdb) GetCollectionRelationsByChildCollectionID(id uint64) ([]*pb.CollectionRelation, error) {
query := fmt.Sprintf(`where child_collection = %d; fields *;`, id)
return g.GetCollectionRelations(query)
}
func (g *igdb) 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 *igdb) GetCollectionRelationsByParentCollectionID(id uint64) ([]*pb.CollectionRelation, error) {
query := fmt.Sprintf(`where parent_collection = %d; fields *;`, id)
return g.GetCollectionRelations(query)
}
func (g *igdb) 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 *igdb) GetCollectionRelationsByCollectionRelationTypeID(id uint64) ([]*pb.CollectionRelation, error) {
query := fmt.Sprintf(`where type = %d; fields *;`, id)
return g.GetCollectionRelations(query)
}
func (g *igdb) 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 *igdb) 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
}

View File

@ -1,56 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetCollectionTypes(query string) ([]*pb.CollectionType, error) {
resp, err := g.Request("https://api.igdb.com/v4/collection_types.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CollectionTypeResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Collectiontypes) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Collectiontypes, nil
}
func (g *igdb) GetCollectionTypeByID(id uint64) (*pb.CollectionType, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
collectionTypes, err := g.GetCollectionTypes(query)
if err != nil {
return nil, err
}
return collectionTypes[0], nil
}
func (g *igdb) GetCollectionTypesByIDs(ids []uint64) ([]*pb.CollectionType, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCollectionTypes(idStr)
}
func (g *igdb) 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
}

View File

@ -1,73 +0,0 @@
package igdb
import (
"fmt"
"strings"
pb "github/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetCollections(query string) ([]*pb.Collection, error) {
resp, err := g.Request("https://api.igdb.com/v4/collections.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CollectionResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Collections) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Collections, nil
}
func (g *igdb) GetCollectionByID(id uint64) (*pb.Collection, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
collections, err := g.GetCollections(query)
if err != nil {
return nil, err
}
return collections[0], nil
}
func (g *igdb) GetCollectionsByIDs(ids []uint64) ([]*pb.Collection, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCollections(idStr)
}
func (g *igdb) GetCollectionsByCollectionTypeID(id uint64) ([]*pb.Collection, error) {
query := fmt.Sprintf(`where collection_type = %d; fields *;`, id)
return g.GetCollections(query)
}
func (g *igdb) 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 *igdb) 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
}

View File

@ -1,154 +0,0 @@
package igdb
import (
"errors"
"fmt"
"strings"
pb "github/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetCompanies(query string) ([]*pb.Company, error) {
resp, err := g.Request("https://api.igdb.com/v4/companies.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CompanyResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Companies) == 0 {
return nil, errors.New("no results")
}
return data.Companies, nil
}
func (g *igdb) GetCompanyByID(id uint64) (*pb.Company, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
companys, err := g.GetCompanies(query)
if err != nil {
return nil, err
}
return companys[0], nil
}
func (g *igdb) GetCompanyByIDs(ids []uint64) ([]*pb.Company, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCompanies(idStr)
}
func (g *igdb) GetCompanyByChangeDateFormatID(id uint64) ([]*pb.Company, error) {
query := fmt.Sprintf(`where change_date_format = %d; fields *;`, id)
return g.GetCompanies(query)
}
func (g *igdb) 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 *igdb) GetCompanyByChangedCompanyID(id uint64) ([]*pb.Company, error) {
query := fmt.Sprintf(`where changed_company_id = %d; fields *;`, id)
return g.GetCompanies(query)
}
func (g *igdb) 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 *igdb) GetCompanyByLogoID(id uint64) ([]*pb.Company, error) {
query := fmt.Sprintf(`where logo = %d; fields *;`, id)
return g.GetCompanies(query)
}
func (g *igdb) 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 *igdb) GetCompanyByParentID(id uint64) ([]*pb.Company, error) {
query := fmt.Sprintf(`where parent = %d; fields *;`, id)
return g.GetCompanies(query)
}
func (g *igdb) 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 *igdb) GetCompanyByStartDateFormatID(id uint64) ([]*pb.Company, error) {
query := fmt.Sprintf(`where start_date_format = %d; fields *;`, id)
return g.GetCompanies(query)
}
func (g *igdb) 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 *igdb) GetCompanyByStatusID(id uint64) ([]*pb.Company, error) {
query := fmt.Sprintf(`where status = %d; fields *;`, id)
return g.GetCompanies(query)
}
func (g *igdb) 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 *igdb) 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,56 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetCompanyLogos(query string) ([]*pb.CompanyLogo, error) {
resp, err := g.Request("https://api.igdb.com/v4/company_logos.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CompanyLogoResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Companylogos) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Companylogos, nil
}
func (g *igdb) GetCompanyLogoByID(id uint64) (*pb.CompanyLogo, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
companyLogos, err := g.GetCompanyLogos(query)
if err != nil {
return nil, err
}
return companyLogos[0], nil
}
func (g *igdb) GetCompanyLogosByIDs(ids []uint64) ([]*pb.CompanyLogo, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCompanyLogos(idStr)
}
func (g *igdb) 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
}

View File

@ -1,56 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetCompanyStatuses(query string) ([]*pb.CompanyStatus, error) {
resp, err := g.Request("https://api.igdb.com/v4/company_statuses.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CompanyStatusResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Companystatuses) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Companystatuses, nil
}
func (g *igdb) GetCompanyStatusByID(id uint64) (*pb.CompanyStatus, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
companyStatuses, err := g.GetCompanyStatuses(query)
if err != nil {
return nil, err
}
return companyStatuses[0], nil
}
func (g *igdb) GetCompanyStatusesByIDs(ids []uint64) ([]*pb.CompanyStatus, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCompanyStatuses(idStr)
}
func (g *igdb) 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
}

View File

@ -1,72 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetCompanyWebsites(query string) ([]*pb.CompanyWebsite, error) {
resp, err := g.Request("https://api.igdb.com/v4/company_websites.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CompanyWebsiteResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Companywebsites) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Companywebsites, nil
}
func (g *igdb) GetCompanyWebsiteByID(id uint64) (*pb.CompanyWebsite, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
companyWebsites, err := g.GetCompanyWebsites(query)
if err != nil {
return nil, err
}
return companyWebsites[0], nil
}
func (g *igdb) GetCompanyWebsitesByIDs(ids []uint64) ([]*pb.CompanyWebsite, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCompanyWebsites(idStr)
}
func (g *igdb) GetCompanyWebsitesByTypeID(id uint64) ([]*pb.CompanyWebsite, error) {
query := fmt.Sprintf(`where type = %d; fields *;`, id)
return g.GetCompanyWebsites(query)
}
func (g *igdb) 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 *igdb) 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,88 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetCovers(query string) ([]*pb.Cover, error) {
resp, err := g.Request("https://api.igdb.com/v4/covers.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CoverResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Covers) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Covers, nil
}
func (g *igdb) GetCoverByID(id uint64) (*pb.Cover, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
covers, err := g.GetCovers(query)
if err != nil {
return nil, err
}
return covers[0], nil
}
func (g *igdb) GetCoversByIDs(ids []uint64) ([]*pb.Cover, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetCovers(idStr)
}
func (g *igdb) GetCoversByGameID(id uint64) ([]*pb.Cover, error) {
query := fmt.Sprintf(`where game = %d; fields *;`, id)
return g.GetCovers(query)
}
func (g *igdb) 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 *igdb) GetCoversByGameLocalizationID(id uint64) ([]*pb.Cover, error) {
query := fmt.Sprintf(`where game_localization = %d; fields *;`, id)
return g.GetCovers(query)
}
func (g *igdb) 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 *igdb) 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
}

View File

@ -1,56 +0,0 @@
package igdb
import (
"fmt"
pb "github/bestnite/go-igdb/proto"
"strings"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetDateFormats(query string) ([]*pb.DateFormat, error) {
resp, err := g.Request("https://api.igdb.com/v4/date_formats.pb", query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.DateFormatResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Dateformats) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Dateformats, nil
}
func (g *igdb) GetDateFormatByID(id uint64) (*pb.DateFormat, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
dateFormats, err := g.GetDateFormats(query)
if err != nil {
return nil, err
}
return dateFormats[0], nil
}
func (g *igdb) GetDateFormatsByIDs(ids []uint64) ([]*pb.DateFormat, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
return g.GetDateFormats(idStr)
}
func (g *igdb) 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type AgeRatingCategories struct {
BaseEndpoint[pb.AgeRatingCategory]
}
func NewAgeRatingCategories(request RequestFunc) *AgeRatingCategories {
a := &AgeRatingCategories{
BaseEndpoint: BaseEndpoint[pb.AgeRatingCategory]{
endpointName: EPAgeRatingCategories,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *AgeRatingCategories) Query(query string) ([]*pb.AgeRatingCategory, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type AgeRatingContentDescriptions struct {
BaseEndpoint[pb.AgeRatingContentDescription]
}
func NewAgeRatingContentDescriptions(request RequestFunc) *AgeRatingContentDescriptions {
a := &AgeRatingContentDescriptions{
BaseEndpoint[pb.AgeRatingContentDescription]{
endpointName: EPAgeRatingContentDescriptions,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *AgeRatingContentDescriptions) Query(query string) ([]*pb.AgeRatingContentDescription, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type AgeRatingContentDescriptionsV2 struct {
BaseEndpoint[pb.AgeRatingContentDescriptionV2]
}
func NewAgeRatingContentDescriptionsV2(request RequestFunc) *AgeRatingContentDescriptionsV2 {
a := &AgeRatingContentDescriptionsV2{
BaseEndpoint[pb.AgeRatingContentDescriptionV2]{
endpointName: EPAgeRatingContentDescriptionsV2,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *AgeRatingContentDescriptionsV2) Query(query string) ([]*pb.AgeRatingContentDescriptionV2, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type AgeRatingOrganizations struct {
BaseEndpoint[pb.AgeRatingOrganization]
}
func NewAgeRatingOrganizations(request RequestFunc) *AgeRatingOrganizations {
a := &AgeRatingOrganizations{
BaseEndpoint[pb.AgeRatingOrganization]{
endpointName: EPAgeRatingOrganizations,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *AgeRatingOrganizations) Query(query string) ([]*pb.AgeRatingOrganization, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/age_ratings.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type AgeRatings struct {
BaseEndpoint[pb.AgeRating]
}
func NewAgeRatings(request RequestFunc) *AgeRatings {
a := &AgeRatings{
BaseEndpoint[pb.AgeRating]{
endpointName: EPAgeRatings,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *AgeRatings) Query(query string) ([]*pb.AgeRating, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type AlternativeNames struct {
BaseEndpoint[pb.AlternativeName]
}
func NewAlternativeNames(request RequestFunc) *AlternativeNames {
a := &AlternativeNames{
BaseEndpoint[pb.AlternativeName]{
endpointName: EPAlternativeNames,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *AlternativeNames) Query(query string) ([]*pb.AlternativeName, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/artworks.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Artworks struct {
BaseEndpoint[pb.Artwork]
}
func NewArtworks(request RequestFunc) *Artworks {
a := &Artworks{
BaseEndpoint[pb.Artwork]{
endpointName: EPArtworks,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Artworks) Query(query string) ([]*pb.Artwork, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

80
endpoint/base.go Normal file
View File

@ -0,0 +1,80 @@
package endpoint
import (
"fmt"
"strconv"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
"github.com/go-resty/resty/v2"
)
type RequestFunc func(method string, URL string, dataBody any) (*resty.Response, error)
type BaseEndpoint[T any] struct {
request RequestFunc
endpointName Name
queryFunc func(string) ([]*T, error)
}
func (b *BaseEndpoint[T]) GetEndpointName() Name {
return b.endpointName
}
func (b *BaseEndpoint[T]) Query(query string) ([]*T, error) {
if b.queryFunc == nil {
return nil, fmt.Errorf("query method must be implemented by specific endpoint")
}
return b.queryFunc(query)
}
func (b *BaseEndpoint[T]) GetByID(id uint64) (*T, error) {
res, err := b.Query(fmt.Sprintf("where id = %d; fields *;", id))
if err != nil {
return nil, err
}
if len(res) == 0 {
return nil, fmt.Errorf("no results")
}
return res[0], nil
}
func (b *BaseEndpoint[T]) GetByIDs(ids []uint64) ([]*T, error) {
builder := strings.Builder{}
for i, v := range ids {
if i > 0 {
builder.WriteByte(',')
}
builder.WriteString(strconv.FormatUint(v, 10))
}
return b.Query(fmt.Sprintf("where id = (%s); fields *;", builder.String()))
}
func (b *BaseEndpoint[T]) Count() (uint64, error) {
resp, err := b.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s/count.pb", b.endpointName), "")
if err != nil {
return 0, fmt.Errorf("failed to request: %w", err)
}
var res pb.Count
if err = proto.Unmarshal(resp.Body(), &res); err != nil {
return 0, fmt.Errorf("failed to unmarshal: %w", err)
}
return uint64(res.Count), nil
}
func (b *BaseEndpoint[T]) Paginated(offset, limit uint64) ([]*T, error) {
return b.Query(fmt.Sprintf("offset %d; limit %d; fields *; sort id asc;", offset, limit))
}
type EntityEndpoint[T any] interface {
GetEndpointName() Name
Query(string) ([]*T, error)
GetByID(uint64) (*T, error)
GetByIDs([]uint64) ([]*T, error)
Count() (uint64, error)
Paginated(uint64, uint64) ([]*T, error)
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CharacterGenders struct {
BaseEndpoint[pb.CharacterGender]
}
func NewCharacterGenders(request RequestFunc) *CharacterGenders {
a := &CharacterGenders{
BaseEndpoint[pb.CharacterGender]{
endpointName: EPCharacterGenders,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CharacterGenders) Query(query string) ([]*pb.CharacterGender, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CharacterMugShots struct {
BaseEndpoint[pb.CharacterMugShot]
}
func NewCharacterMugShots(request RequestFunc) *CharacterMugShots {
a := &CharacterMugShots{
BaseEndpoint[pb.CharacterMugShot]{
endpointName: EPCharacterMugShots,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CharacterMugShots) Query(query string) ([]*pb.CharacterMugShot, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CharacterSpecies struct {
BaseEndpoint[pb.CharacterSpecie]
}
func NewCharacterSpecies(request RequestFunc) *CharacterSpecies {
a := &CharacterSpecies{
BaseEndpoint[pb.CharacterSpecie]{
endpointName: EPCharacterSpecies,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CharacterSpecies) Query(query string) ([]*pb.CharacterSpecie, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/characters.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Characters struct {
BaseEndpoint[pb.Character]
}
func NewCharacters(request RequestFunc) *Characters {
a := &Characters{
BaseEndpoint[pb.Character]{
endpointName: EPCharacters,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Characters) Query(query string) ([]*pb.Character, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CollectionMembershipTypes struct {
BaseEndpoint[pb.CollectionMembershipType]
}
func NewCollectionMembershipTypes(request RequestFunc) *CollectionMembershipTypes {
a := &CollectionMembershipTypes{
BaseEndpoint[pb.CollectionMembershipType]{
endpointName: EPCollectionMembershipTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CollectionMembershipTypes) Query(query string) ([]*pb.CollectionMembershipType, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CollectionMemberships struct {
BaseEndpoint[pb.CollectionMembership]
}
func NewCollectionMemberships(request RequestFunc) *CollectionMemberships {
a := &CollectionMemberships{
BaseEndpoint[pb.CollectionMembership]{
endpointName: EPCollectionMemberships,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CollectionMemberships) Query(query string) ([]*pb.CollectionMembership, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CollectionRelationTypes struct {
BaseEndpoint[pb.CollectionRelationType]
}
func NewCollectionRelationTypes(request RequestFunc) *CollectionRelationTypes {
a := &CollectionRelationTypes{
BaseEndpoint[pb.CollectionRelationType]{
endpointName: EPCollectionRelationTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CollectionRelationTypes) Query(query string) ([]*pb.CollectionRelationType, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CollectionRelations struct {
BaseEndpoint[pb.CollectionRelation]
}
func NewCollectionRelations(request RequestFunc) *CollectionRelations {
a := &CollectionRelations{
BaseEndpoint[pb.CollectionRelation]{
endpointName: EPCollectionRelations,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CollectionRelations) Query(query string) ([]*pb.CollectionRelation, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CollectionTypes struct {
BaseEndpoint[pb.CollectionType]
}
func NewCollectionTypes(request RequestFunc) *CollectionTypes {
a := &CollectionTypes{
BaseEndpoint[pb.CollectionType]{
endpointName: EPCollectionTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CollectionTypes) Query(query string) ([]*pb.CollectionType, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/collections.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Collections struct {
BaseEndpoint[pb.Collection]
}
func NewCollections(request RequestFunc) *Collections {
a := &Collections{
BaseEndpoint[pb.Collection]{
endpointName: EPCollections,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Collections) Query(query string) ([]*pb.Collection, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

43
endpoint/companies.go Normal file
View File

@ -0,0 +1,43 @@
package endpoint
import (
"errors"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Companies struct {
BaseEndpoint[pb.Company]
}
func NewCompanies(request RequestFunc) *Companies {
a := &Companies{
BaseEndpoint[pb.Company]{
endpointName: EPCompanies,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Companies) Query(query string) ([]*pb.Company, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/company_logos.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CompanyLogos struct {
BaseEndpoint[pb.CompanyLogo]
}
func NewCompanyLogos(request RequestFunc) *CompanyLogos {
a := &CompanyLogos{
BaseEndpoint[pb.CompanyLogo]{
endpointName: EPCompanyLogos,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CompanyLogos) Query(query string) ([]*pb.CompanyLogo, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CompanyStatuses struct {
BaseEndpoint[pb.CompanyStatus]
}
func NewCompanyStatuses(request RequestFunc) *CompanyStatuses {
a := &CompanyStatuses{
BaseEndpoint[pb.CompanyStatus]{
endpointName: EPCompanyStatuses,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CompanyStatuses) Query(query string) ([]*pb.CompanyStatus, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CompanyWebsites struct {
BaseEndpoint[pb.CompanyWebsite]
}
func NewCompanyWebsites(request RequestFunc) *CompanyWebsites {
a := &CompanyWebsites{
BaseEndpoint[pb.CompanyWebsite]{
endpointName: EPCompanyWebsites,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CompanyWebsites) Query(query string) ([]*pb.CompanyWebsite, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/covers.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Covers struct {
BaseEndpoint[pb.Cover]
}
func NewCovers(request RequestFunc) *Covers {
a := &Covers{
BaseEndpoint[pb.Cover]{
endpointName: EPCovers,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Covers) Query(query string) ([]*pb.Cover, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/date_formats.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type DateFormats struct {
BaseEndpoint[pb.DateFormat]
}
func NewDateFormats(request RequestFunc) *DateFormats {
a := &DateFormats{
BaseEndpoint[pb.DateFormat]{
endpointName: EPDateFormats,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *DateFormats) Query(query string) ([]*pb.DateFormat, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

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

151
endpoint/endpoint_name.go Normal file
View File

@ -0,0 +1,151 @@
package endpoint
type Name string
var (
EPAgeRatingCategories Name = "age_rating_categories"
EPAgeRatingContentDescriptions Name = "age_rating_content_descriptions"
EPAgeRatingContentDescriptionsV2 Name = "age_rating_content_descriptions_v2"
EPAgeRatingOrganizations Name = "age_rating_organizations"
EPAgeRatings Name = "age_ratings"
EPAlternativeNames Name = "alternative_names"
EPArtworks Name = "artworks"
EPCharacterGenders Name = "character_genders"
EPCharacterMugShots Name = "character_mug_shots"
EPCharacters Name = "characters"
EPCharacterSpecies Name = "character_species"
EPCollectionMemberships Name = "collection_memberships"
EPCollectionMembershipTypes Name = "collection_membership_types"
EPCollectionRelations Name = "collection_relations"
EPCollectionRelationTypes Name = "collection_relation_types"
EPCollections Name = "collections"
EPCollectionTypes Name = "collection_types"
EPCompanies Name = "companies"
EPCompanyLogos Name = "company_logos"
EPCompanyStatuses Name = "company_statuses"
EPCompanyWebsites Name = "company_websites"
EPCovers Name = "covers"
EPDateFormats Name = "date_formats"
EPEventLogos Name = "event_logos"
EPEventNetworks Name = "event_networks"
EPEvents Name = "events"
EPExternalGames Name = "external_games"
EPExternalGameSources Name = "external_game_sources"
EPFranchises Name = "franchises"
EPGameEngineLogos Name = "game_engine_logos"
EPGameEngines Name = "game_engines"
EPGameLocalizations Name = "game_localizations"
EPGameModes Name = "game_modes"
EPGameReleaseFormats Name = "game_release_formats"
EPGames Name = "games"
EPGameStatuses Name = "game_statuses"
EPGameTimeToBeats Name = "game_time_to_beats"
EPGameTypes Name = "game_types"
EPGameVersionFeatures Name = "game_version_features"
EPGameVersionFeatureValues Name = "game_version_feature_values"
EPGameVersions Name = "game_versions"
EPGameVideos Name = "game_videos"
EPGenres Name = "genres"
EPInvolvedCompanies Name = "involved_companies"
EPKeywords Name = "keywords"
EPLanguages Name = "languages"
EPLanguageSupports Name = "language_supports"
EPLanguageSupportTypes Name = "language_support_types"
EPMultiplayerModes Name = "multiplayer_modes"
EPNetworkTypes Name = "network_types"
EPPlatformFamilies Name = "platform_families"
EPPlatformLogos Name = "platform_logos"
EPPlatforms Name = "platforms"
EPPlatformTypes Name = "platform_types"
EPPlatformVersionCompanies Name = "platform_version_companies"
EPPlatformVersionReleaseDates Name = "platform_version_release_dates"
EPPlatformVersions Name = "platform_versions"
EPPlatformWebsites Name = "platform_websites"
EPPlayerPerspectives Name = "player_perspectives"
EPPopularityPrimitives Name = "popularity_primitives"
EPPopularityTypes Name = "popularity_types"
EPRegions Name = "regions"
EPReleaseDateRegions Name = "release_date_regions"
EPReleaseDates Name = "release_dates"
EPReleaseDateStatuses Name = "release_date_statuses"
EPScreenshots Name = "screenshots"
EPSearch Name = "search"
EPThemes Name = "themes"
EPWebhooks Name = "webhooks"
EPWebsites Name = "websites"
EPWebsiteTypes Name = "website_types"
)
var AllNames = []Name{
EPAgeRatingCategories,
EPAgeRatingContentDescriptions,
EPAgeRatingContentDescriptionsV2,
EPAgeRatingOrganizations,
EPAgeRatings,
EPAlternativeNames,
EPArtworks,
EPCharacterGenders,
EPCharacterMugShots,
EPCharacters,
EPCharacterSpecies,
EPCollectionMemberships,
EPCollectionMembershipTypes,
EPCollectionRelations,
EPCollectionRelationTypes,
EPCollections,
EPCollectionTypes,
EPCompanies,
EPCompanyLogos,
EPCompanyStatuses,
EPCompanyWebsites,
EPCovers,
EPDateFormats,
EPEventLogos,
EPEventNetworks,
EPEvents,
EPExternalGames,
EPExternalGameSources,
EPFranchises,
EPGameEngineLogos,
EPGameEngines,
EPGameLocalizations,
EPGameModes,
EPGameReleaseFormats,
EPGames,
EPGameStatuses,
EPGameTimeToBeats,
EPGameTypes,
EPGameVersionFeatures,
EPGameVersionFeatureValues,
EPGameVersions,
EPGameVideos,
EPGenres,
EPInvolvedCompanies,
EPKeywords,
EPLanguages,
EPLanguageSupports,
EPLanguageSupportTypes,
EPMultiplayerModes,
EPNetworkTypes,
EPPlatformFamilies,
EPPlatformLogos,
EPPlatforms,
EPPlatformTypes,
EPPlatformVersionCompanies,
EPPlatformVersionReleaseDates,
EPPlatformVersions,
EPPlatformWebsites,
EPPlayerPerspectives,
EPPopularityPrimitives,
EPPopularityTypes,
EPRegions,
EPReleaseDateRegions,
EPReleaseDates,
EPReleaseDateStatuses,
EPScreenshots,
EPSearch,
EPThemes,
EPWebhooks,
EPWebsites,
EPWebsiteTypes,
}

42
endpoint/event_logos.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type EventLogos struct {
BaseEndpoint[pb.EventLogo]
}
func NewEventLogos(request RequestFunc) *EventLogos {
a := &EventLogos{
BaseEndpoint[pb.EventLogo]{
endpointName: EPEventLogos,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *EventLogos) Query(query string) ([]*pb.EventLogo, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type EventNetworks struct {
BaseEndpoint[pb.EventNetwork]
}
func NewEventNetworks(request RequestFunc) *EventNetworks {
a := &EventNetworks{
BaseEndpoint[pb.EventNetwork]{
endpointName: EPEventNetworks,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *EventNetworks) Query(query string) ([]*pb.EventNetwork, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/events.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Events struct {
BaseEndpoint[pb.Event]
}
func NewEvents(request RequestFunc) *Events {
a := &Events{
BaseEndpoint[pb.Event]{
endpointName: EPEvents,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Events) Query(query string) ([]*pb.Event, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type ExternalGameSources struct {
BaseEndpoint[pb.ExternalGameSource]
}
func NewExternalGameSources(request RequestFunc) *ExternalGameSources {
a := &ExternalGameSources{
BaseEndpoint[pb.ExternalGameSource]{
endpointName: EPExternalGameSources,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *ExternalGameSources) Query(query string) ([]*pb.ExternalGameSource, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type ExternalGames struct {
BaseEndpoint[pb.ExternalGame]
}
func NewExternalGames(request RequestFunc) *ExternalGames {
a := &ExternalGames{
BaseEndpoint[pb.ExternalGame]{
endpointName: EPExternalGames,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *ExternalGames) Query(query string) ([]*pb.ExternalGame, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/franchises.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Franchises struct {
BaseEndpoint[pb.Franchise]
}
func NewFranchises(request RequestFunc) *Franchises {
a := &Franchises{
BaseEndpoint[pb.Franchise]{
endpointName: EPFranchises,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Franchises) Query(query string) ([]*pb.Franchise, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameEngineLogos struct {
BaseEndpoint[pb.GameEngineLogo]
}
func NewGameEngineLogos(request RequestFunc) *GameEngineLogos {
a := &GameEngineLogos{
BaseEndpoint[pb.GameEngineLogo]{
endpointName: EPGameEngineLogos,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameEngineLogos) Query(query string) ([]*pb.GameEngineLogo, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/game_engines.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameEngines struct {
BaseEndpoint[pb.GameEngine]
}
func NewGameEngines(request RequestFunc) *GameEngines {
a := &GameEngines{
BaseEndpoint[pb.GameEngine]{
endpointName: EPGameEngines,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameEngines) Query(query string) ([]*pb.GameEngine, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameLocalizations struct {
BaseEndpoint[pb.GameLocalization]
}
func NewGameLocalizations(request RequestFunc) *GameLocalizations {
a := &GameLocalizations{
BaseEndpoint[pb.GameLocalization]{
endpointName: EPGameLocalizations,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameLocalizations) Query(query string) ([]*pb.GameLocalization, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/game_modes.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameModes struct {
BaseEndpoint[pb.GameMode]
}
func NewGameModes(request RequestFunc) *GameModes {
a := &GameModes{
BaseEndpoint[pb.GameMode]{
endpointName: EPGameModes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameModes) Query(query string) ([]*pb.GameMode, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameReleaseFormats struct {
BaseEndpoint[pb.GameReleaseFormat]
}
func NewGameReleaseFormats(request RequestFunc) *GameReleaseFormats {
a := &GameReleaseFormats{
BaseEndpoint[pb.GameReleaseFormat]{
endpointName: EPGameReleaseFormats,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameReleaseFormats) Query(query string) ([]*pb.GameReleaseFormat, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/game_statuses.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameStatuses struct {
BaseEndpoint[pb.GameStatus]
}
func NewGameStatuses(request RequestFunc) *GameStatuses {
a := &GameStatuses{
BaseEndpoint[pb.GameStatus]{
endpointName: EPGameStatuses,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameStatuses) Query(query string) ([]*pb.GameStatus, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameTimeToBeats struct {
BaseEndpoint[pb.GameTimeToBeat]
}
func NewGameTimeToBeats(request RequestFunc) *GameTimeToBeats {
a := &GameTimeToBeats{
BaseEndpoint[pb.GameTimeToBeat]{
endpointName: EPGameTimeToBeats,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameTimeToBeats) Query(query string) ([]*pb.GameTimeToBeat, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/game_types.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameTypes struct {
BaseEndpoint[pb.GameType]
}
func NewGameTypes(request RequestFunc) *GameTypes {
a := &GameTypes{
BaseEndpoint[pb.GameType]{
endpointName: EPGameTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameTypes) Query(query string) ([]*pb.GameType, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameVersionFeatureValues struct {
BaseEndpoint[pb.GameVersionFeatureValue]
}
func NewGameVersionFeatureValues(request RequestFunc) *GameVersionFeatureValues {
a := &GameVersionFeatureValues{
BaseEndpoint[pb.GameVersionFeatureValue]{
endpointName: EPGameVersionFeatureValues,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameVersionFeatureValues) Query(query string) ([]*pb.GameVersionFeatureValue, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameVersionFeatures struct {
BaseEndpoint[pb.GameVersionFeature]
}
func NewGameVersionFeatures(request RequestFunc) *GameVersionFeatures {
a := &GameVersionFeatures{
BaseEndpoint[pb.GameVersionFeature]{
endpointName: EPGameVersionFeatures,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameVersionFeatures) Query(query string) ([]*pb.GameVersionFeature, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/game_versions.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameVersions struct {
BaseEndpoint[pb.GameVersion]
}
func NewGameVersions(request RequestFunc) *GameVersions {
a := &GameVersions{
BaseEndpoint[pb.GameVersion]{
endpointName: EPGameVersions,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameVersions) Query(query string) ([]*pb.GameVersion, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/game_videos.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameVideos struct {
BaseEndpoint[pb.GameVideo]
}
func NewGameVideos(request RequestFunc) *GameVideos {
a := &GameVideos{
BaseEndpoint[pb.GameVideo]{
endpointName: EPGameVideos,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameVideos) Query(query string) ([]*pb.GameVideo, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/games.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Games struct {
BaseEndpoint[pb.Game]
}
func NewGames(request RequestFunc) *Games {
a := &Games{
BaseEndpoint[pb.Game]{
endpointName: EPGames,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Games) Query(query string) ([]*pb.Game, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/genres.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Genres struct {
BaseEndpoint[pb.Genre]
}
func NewGenres(request RequestFunc) *Genres {
a := &Genres{
BaseEndpoint[pb.Genre]{
endpointName: EPGenres,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Genres) Query(query string) ([]*pb.Genre, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type InvolvedCompanies struct {
BaseEndpoint[pb.InvolvedCompany]
}
func NewInvolvedCompanies(request RequestFunc) *InvolvedCompanies {
a := &InvolvedCompanies{
BaseEndpoint[pb.InvolvedCompany]{
endpointName: EPInvolvedCompanies,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *InvolvedCompanies) Query(query string) ([]*pb.InvolvedCompany, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/keywords.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Keywords struct {
BaseEndpoint[pb.Keyword]
}
func NewKeywords(request RequestFunc) *Keywords {
a := &Keywords{
BaseEndpoint[pb.Keyword]{
endpointName: EPKeywords,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Keywords) Query(query string) ([]*pb.Keyword, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type LanguageSupportTypes struct {
BaseEndpoint[pb.LanguageSupportType]
}
func NewLanguageSupportTypes(request RequestFunc) *LanguageSupportTypes {
a := &LanguageSupportTypes{
BaseEndpoint[pb.LanguageSupportType]{
endpointName: EPLanguageSupportTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *LanguageSupportTypes) Query(query string) ([]*pb.LanguageSupportType, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type LanguageSupports struct {
BaseEndpoint[pb.LanguageSupport]
}
func NewLanguageSupports(request RequestFunc) *LanguageSupports {
a := &LanguageSupports{
BaseEndpoint[pb.LanguageSupport]{
endpointName: EPLanguageSupports,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *LanguageSupports) Query(query string) ([]*pb.LanguageSupport, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/languages.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Languages struct {
BaseEndpoint[pb.Language]
}
func NewLanguages(request RequestFunc) *Languages {
a := &Languages{
BaseEndpoint[pb.Language]{
endpointName: EPLanguages,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Languages) Query(query string) ([]*pb.Language, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type MultiplayerModes struct {
BaseEndpoint[pb.MultiplayerMode]
}
func NewMultiplayerModes(request RequestFunc) *MultiplayerModes {
a := &MultiplayerModes{
BaseEndpoint[pb.MultiplayerMode]{
endpointName: EPMultiplayerModes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *MultiplayerModes) Query(query string) ([]*pb.MultiplayerMode, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/network_types.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type NetworkTypes struct {
BaseEndpoint[pb.NetworkType]
}
func NewNetworkTypes(request RequestFunc) *NetworkTypes {
a := &NetworkTypes{
BaseEndpoint[pb.NetworkType]{
endpointName: EPNetworkTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *NetworkTypes) Query(query string) ([]*pb.NetworkType, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlatformFamilies struct {
BaseEndpoint[pb.PlatformFamily]
}
func NewPlatformFamilies(request RequestFunc) *PlatformFamilies {
a := &PlatformFamilies{
BaseEndpoint[pb.PlatformFamily]{
endpointName: EPPlatformFamilies,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlatformFamilies) Query(query string) ([]*pb.PlatformFamily, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlatformLogos struct {
BaseEndpoint[pb.PlatformLogo]
}
func NewPlatformLogos(request RequestFunc) *PlatformLogos {
a := &PlatformLogos{
BaseEndpoint[pb.PlatformLogo]{
endpointName: EPPlatformLogos,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlatformLogos) Query(query string) ([]*pb.PlatformLogo, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlatformTypes struct {
BaseEndpoint[pb.PlatformType]
}
func NewPlatformTypes(request RequestFunc) *PlatformTypes {
a := &PlatformTypes{
BaseEndpoint[pb.PlatformType]{
endpointName: EPPlatformTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlatformTypes) Query(query string) ([]*pb.PlatformType, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlatformVersionCompanies struct {
BaseEndpoint[pb.PlatformVersionCompany]
}
func NewPlatformVersionCompanies(request RequestFunc) *PlatformVersionCompanies {
a := &PlatformVersionCompanies{
BaseEndpoint[pb.PlatformVersionCompany]{
endpointName: EPPlatformVersionCompanies,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlatformVersionCompanies) Query(query string) ([]*pb.PlatformVersionCompany, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlatformVersionReleaseDates struct {
BaseEndpoint[pb.PlatformVersionReleaseDate]
}
func NewPlatformVersionReleaseDates(request RequestFunc) *PlatformVersionReleaseDates {
a := &PlatformVersionReleaseDates{
BaseEndpoint[pb.PlatformVersionReleaseDate]{
endpointName: EPPlatformVersionReleaseDates,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlatformVersionReleaseDates) Query(query string) ([]*pb.PlatformVersionReleaseDate, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlatformVersions struct {
BaseEndpoint[pb.PlatformVersion]
}
func NewPlatformVersions(request RequestFunc) *PlatformVersions {
a := &PlatformVersions{
BaseEndpoint[pb.PlatformVersion]{
endpointName: EPPlatformVersions,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlatformVersions) Query(query string) ([]*pb.PlatformVersion, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlatformWebsites struct {
BaseEndpoint[pb.PlatformWebsite]
}
func NewPlatformWebsites(request RequestFunc) *PlatformWebsites {
a := &PlatformWebsites{
BaseEndpoint[pb.PlatformWebsite]{
endpointName: EPPlatformWebsites,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlatformWebsites) Query(query string) ([]*pb.PlatformWebsite, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

41
endpoint/platforms.go Normal file
View File

@ -0,0 +1,41 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Platforms struct {
BaseEndpoint[pb.Platform]
}
func NewPlatforms(request RequestFunc) *Platforms {
a := &Platforms{
BaseEndpoint[pb.Platform]{
endpointName: EPPlatforms,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Platforms) Query(query string) ([]*pb.Platform, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlayerPerspectives struct {
BaseEndpoint[pb.PlayerPerspective]
}
func NewPlayerPerspectives(request RequestFunc) *PlayerPerspectives {
a := &PlayerPerspectives{
BaseEndpoint[pb.PlayerPerspective]{
endpointName: EPPlayerPerspectives,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlayerPerspectives) Query(query string) ([]*pb.PlayerPerspective, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PopularityPrimitives struct {
BaseEndpoint[pb.PopularityPrimitive]
}
func NewPopularityPrimitives(request RequestFunc) *PopularityPrimitives {
a := &PopularityPrimitives{
BaseEndpoint[pb.PopularityPrimitive]{
endpointName: EPPopularityPrimitives,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PopularityPrimitives) Query(query string) ([]*pb.PopularityPrimitive, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PopularityTypes struct {
BaseEndpoint[pb.PopularityType]
}
func NewPopularityTypes(request RequestFunc) *PopularityTypes {
a := &PopularityTypes{
BaseEndpoint[pb.PopularityType]{
endpointName: EPPopularityTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PopularityTypes) Query(query string) ([]*pb.PopularityType, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/regions.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Regions struct {
BaseEndpoint[pb.Region]
}
func NewRegions(request RequestFunc) *Regions {
a := &Regions{
BaseEndpoint[pb.Region]{
endpointName: EPRegions,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Regions) Query(query string) ([]*pb.Region, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type ReleaseDateRegions struct {
BaseEndpoint[pb.ReleaseDateRegion]
}
func NewReleaseDateRegions(request RequestFunc) *ReleaseDateRegions {
a := &ReleaseDateRegions{
BaseEndpoint[pb.ReleaseDateRegion]{
endpointName: EPReleaseDateRegions,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *ReleaseDateRegions) Query(query string) ([]*pb.ReleaseDateRegion, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type ReleaseDateStatuses struct {
BaseEndpoint[pb.ReleaseDateStatus]
}
func NewReleaseDateStatuses(request RequestFunc) *ReleaseDateStatuses {
a := &ReleaseDateStatuses{
BaseEndpoint[pb.ReleaseDateStatus]{
endpointName: EPReleaseDateStatuses,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *ReleaseDateStatuses) Query(query string) ([]*pb.ReleaseDateStatus, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/release_dates.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type ReleaseDates struct {
BaseEndpoint[pb.ReleaseDate]
}
func NewReleaseDates(request RequestFunc) *ReleaseDates {
a := &ReleaseDates{
BaseEndpoint[pb.ReleaseDate]{
endpointName: EPReleaseDates,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *ReleaseDates) Query(query string) ([]*pb.ReleaseDate, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

42
endpoint/screenshots.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Screenshots struct {
BaseEndpoint[pb.Screenshot]
}
func NewScreenshots(request RequestFunc) *Screenshots {
a := &Screenshots{
BaseEndpoint[pb.Screenshot]{
endpointName: EPScreenshots,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Screenshots) Query(query string) ([]*pb.Screenshot, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

View File

@ -1,4 +1,4 @@
package igdb package endpoint
import ( import (
"encoding/json" "encoding/json"
@ -9,7 +9,7 @@ import (
"strings" "strings"
"time" "time"
pb "github/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"github.com/bestnite/go-flaresolverr" "github.com/bestnite/go-flaresolverr"
@ -21,8 +21,21 @@ var webSearchCFCookies struct {
expires time.Time expires time.Time
} }
func (g *igdb) Search(query string) ([]*pb.Search, error) { type Search struct {
resp, err := g.Request("https://api.igdb.com/v4/search.pb", query) endpointName Name
request RequestFunc
flaresolverr *flaresolverr.Flaresolverr
}
func NewSearch(request RequestFunc) *Search {
return &Search{
endpointName: EPSearch,
request: request,
}
}
func (a *Search) Search(query string) ([]*pb.Search, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }
@ -39,13 +52,20 @@ func (g *igdb) Search(query string) ([]*pb.Search, error) {
return data.Searches, nil return data.Searches, nil
} }
func (g *igdb) WebSearchGames(name string) ([]*pb.Game, error) { func (a *Search) getFlaresolverr() (*flaresolverr.Flaresolverr, error) {
if a.flaresolverr == nil {
return nil, fmt.Errorf("flaresolverr is not initialized")
}
return a.flaresolverr, nil
}
func (a *Search) WebSearchGameIDs(name string) ([]uint64, error) {
params := url.Values{} params := url.Values{}
params.Add("q", name) params.Add("q", name)
params.Add("utf8", "✓") params.Add("utf8", "✓")
Url := fmt.Sprintf("%s?%s", "https://www.igdb.com/search", params.Encode()) Url := fmt.Sprintf("%s?%s", "https://www.igdb.com/search", params.Encode())
f, err := g.getFlaresolverr() f, err := a.getFlaresolverr()
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get flaresolverr: %w", err) return nil, fmt.Errorf("failed to get flaresolverr: %w", err)
} }
@ -93,5 +113,5 @@ func (g *igdb) WebSearchGames(name string) ([]*pb.Game, error) {
ids[i] = game.Id ids[i] = game.Id
} }
return g.GetGameByIDs(ids) return ids, nil
} }

42
endpoint/themes.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Themes struct {
BaseEndpoint[pb.Theme]
}
func NewThemes(request RequestFunc) *Themes {
a := &Themes{
BaseEndpoint[pb.Theme]{
endpointName: EPThemes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Themes) Query(query string) ([]*pb.Theme, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

103
endpoint/webhooks.go Normal file
View File

@ -0,0 +1,103 @@
package endpoint
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
)
type Webhooks struct {
request RequestFunc
}
func NewWebhooks(request RequestFunc) *Webhooks {
return &Webhooks{
request: request,
}
}
type WebhookMethod string
const (
WebhookMethodUpdate WebhookMethod = "update"
WebhookMethodDelete WebhookMethod = "delete"
WebhookMethodCreate WebhookMethod = "create"
)
type WebhookResponse struct {
Id uint64 `json:"id"`
Url string `json:"url"`
Category uint64 `json:"category"`
SubCategory uint64 `json:"sub_category"`
Active bool `json:"active"`
ApiKey string `json:"api_key"`
Secret string `json:"secret"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
func (a *Webhooks) Register(endpoint Name, secret, callbackUrl string, method WebhookMethod) (*WebhookResponse, error) {
dataBody := url.Values{}
dataBody.Set("url", callbackUrl)
dataBody.Set("secret", secret)
dataBody.Set("method", string(method))
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s/webhooks/", endpoint), dataBody.Encode())
if err != nil {
return nil, fmt.Errorf("failed to make request: %s: %w", callbackUrl, err)
}
if resp.StatusCode() == http.StatusOK {
return nil, nil
}
var data WebhookResponse
if err = json.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
return &data, fmt.Errorf("failed to activate webhook: %s: %s", callbackUrl, resp.String())
}
func (a *Webhooks) Unregister(webhookId uint64) error {
resp, err := a.request("DELETE", fmt.Sprintf("https://api.igdb.com/v4/webhooks/%v", webhookId), "")
if err != nil {
return fmt.Errorf("failed to make request: %w", err)
}
if resp.StatusCode() == http.StatusOK {
return nil
}
return fmt.Errorf("failed to unregister webhook: %s", resp.String())
}
func (a *Webhooks) List() ([]*WebhookResponse, error) {
resp, err := a.request("GET", "https://api.igdb.com/v4/webhooks/", "")
if err != nil {
return nil, fmt.Errorf("failed to make request: %w", err)
}
var data []*WebhookResponse
if err = json.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
return data, nil
}
func (a *Webhooks) Get(webhookId uint64) (*WebhookResponse, error) {
resp, err := a.request("GET", fmt.Sprintf("https://api.igdb.com/v4/webhooks/%v", webhookId), "")
if err != nil {
return nil, fmt.Errorf("failed to make request: %w", err)
}
var data WebhookResponse
if err = json.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
return &data, nil
}

42
endpoint/website_types.go Normal file
View File

@ -0,0 +1,42 @@
package endpoint
import (
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type WebsiteTypes struct {
BaseEndpoint[pb.WebsiteType]
}
func NewWebsiteTypes(request RequestFunc) *WebsiteTypes {
a := &WebsiteTypes{
BaseEndpoint[pb.WebsiteType]{
endpointName: EPWebsiteTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *WebsiteTypes) Query(query string) ([]*pb.WebsiteType, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), 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
}

Some files were not shown because too many files have changed in this diff Show More