Compare commits

..

No commits in common. "main" and "v0.0.8" have entirely different histories.
main ... v0.0.8

80 changed files with 364 additions and 372 deletions

1
.gitignore vendored
View File

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

21
LICENSE
View File

@ -1,21 +0,0 @@
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.

View File

@ -45,7 +45,7 @@ func Test2(c *igdb.Client) {
} }
func Test3(c *igdb.Client) { func Test3(c *igdb.Client) {
total, err := c.Games.Count() total, err := c.Games.GetLastOneId()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -93,21 +93,6 @@ func main() {
} }
``` ```
## Example Projects
- [igdb-database](https://github.com/bestnite/igdb-database)
## Dependencies
- [go-resty/resty](https://github.com/go-resty/resty)
- [google/protobuf](https://github.com/google/protobuf)
- [bestnite/go-flaresolverr](https://github.com/bestnite/go-flaresolverr)
- [PuerkitoBio/goquery](https://github.com/PuerkitoBio/goquery)
## 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.

41
assert.go Normal file
View File

@ -0,0 +1,41 @@
package igdb
import "fmt"
func AssertSingle[T any](data any, err error) (*T, error) {
if err != nil {
return nil, err
}
if data == nil {
return nil, fmt.Errorf("data is nil")
}
datas, ok := data.([]*T)
if !ok {
return nil, fmt.Errorf("failed to convert to []*T")
}
if len(datas) == 0 {
return nil, fmt.Errorf("no results")
}
return datas[0], nil
}
func AssertSlice[T any](data any, err error) ([]*T, error) {
if err != nil {
return nil, err
}
if data == nil {
return nil, fmt.Errorf("data is nil")
}
datas, ok := data.([]*T)
if !ok {
return nil, fmt.Errorf("failed to convert to []*T")
}
return datas, nil
}

View File

@ -2,7 +2,6 @@ package igdb
import ( import (
"fmt" "fmt"
"strings"
"github.com/bestnite/go-flaresolverr" "github.com/bestnite/go-flaresolverr"
"github.com/bestnite/go-igdb/endpoint" "github.com/bestnite/go-igdb/endpoint"
@ -12,7 +11,7 @@ import (
type Client struct { type Client struct {
clientID string clientID string
token *TwitchToken token *twitchToken
flaresolverr *flaresolverr.Flaresolverr flaresolverr *flaresolverr.Flaresolverr
limiter *rateLimiter limiter *rateLimiter
@ -102,15 +101,13 @@ func New(clientID, clientSecret string) *Client {
return c return c
} }
type RequestFunc func(method string, URL string, dataBody any) (*resty.Response, error)
func NewWithFlaresolverr(clientID, clientSecret string, f *flaresolverr.Flaresolverr) *Client { func NewWithFlaresolverr(clientID, clientSecret string, f *flaresolverr.Flaresolverr) *Client {
c := New(clientID, clientSecret) c := New(clientID, clientSecret)
c.flaresolverr = f c.flaresolverr = f
return c return c
} }
func (g *Client) Request(method string, URL string, dataBody any) (*resty.Response, error) { func (g *Client) Request(URL string, dataBody any) (*resty.Response, error) {
g.limiter.wait() g.limiter.wait()
t, err := g.token.getToken() t, err := g.token.getToken()
@ -123,7 +120,7 @@ func (g *Client) Request(method string, URL string, dataBody any) (*resty.Respon
"Authorization": "Bearer " + t, "Authorization": "Bearer " + t,
"User-Agent": "", "User-Agent": "",
"Content-Type": "text/plain", "Content-Type": "text/plain",
}).Execute(strings.ToUpper(method), URL) }).Post(URL)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to request: %s: %w", URL, err) return nil, fmt.Errorf("failed to request: %s: %w", URL, err)

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type AgeRatingCategories struct {
BaseEndpoint[pb.AgeRatingCategory] BaseEndpoint[pb.AgeRatingCategory]
} }
func NewAgeRatingCategories(request RequestFunc) *AgeRatingCategories { func NewAgeRatingCategories(request func(URL string, dataBody any) (*resty.Response, error)) *AgeRatingCategories {
a := &AgeRatingCategories{ a := &AgeRatingCategories{
BaseEndpoint: BaseEndpoint[pb.AgeRatingCategory]{ BaseEndpoint: BaseEndpoint[pb.AgeRatingCategory]{
endpointName: EPAgeRatingCategories, endpointName: EPAgeRatingCategories,
@ -24,7 +25,7 @@ func NewAgeRatingCategories(request RequestFunc) *AgeRatingCategories {
} }
func (a *AgeRatingCategories) Query(query string) ([]*pb.AgeRatingCategory, error) { 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) resp, err := a.request("https://api.igdb.com/v4/age_rating_categories.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type AgeRatingContentDescriptions struct {
BaseEndpoint[pb.AgeRatingContentDescription] BaseEndpoint[pb.AgeRatingContentDescription]
} }
func NewAgeRatingContentDescriptions(request RequestFunc) *AgeRatingContentDescriptions { func NewAgeRatingContentDescriptions(request func(URL string, dataBody any) (*resty.Response, error)) *AgeRatingContentDescriptions {
a := &AgeRatingContentDescriptions{ a := &AgeRatingContentDescriptions{
BaseEndpoint[pb.AgeRatingContentDescription]{ BaseEndpoint[pb.AgeRatingContentDescription]{
endpointName: EPAgeRatingContentDescriptions, endpointName: EPAgeRatingContentDescriptions,
@ -24,7 +25,7 @@ func NewAgeRatingContentDescriptions(request RequestFunc) *AgeRatingContentDescr
} }
func (a *AgeRatingContentDescriptions) Query(query string) ([]*pb.AgeRatingContentDescription, error) { 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) resp, err := a.request("https://api.igdb.com/v4/age_rating_content_descriptions.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type AgeRatingContentDescriptionsV2 struct {
BaseEndpoint[pb.AgeRatingContentDescriptionV2] BaseEndpoint[pb.AgeRatingContentDescriptionV2]
} }
func NewAgeRatingContentDescriptionsV2(request RequestFunc) *AgeRatingContentDescriptionsV2 { func NewAgeRatingContentDescriptionsV2(request func(URL string, dataBody any) (*resty.Response, error)) *AgeRatingContentDescriptionsV2 {
a := &AgeRatingContentDescriptionsV2{ a := &AgeRatingContentDescriptionsV2{
BaseEndpoint[pb.AgeRatingContentDescriptionV2]{ BaseEndpoint[pb.AgeRatingContentDescriptionV2]{
endpointName: EPAgeRatingContentDescriptionsV2, endpointName: EPAgeRatingContentDescriptionsV2,
@ -24,7 +25,7 @@ func NewAgeRatingContentDescriptionsV2(request RequestFunc) *AgeRatingContentDes
} }
func (a *AgeRatingContentDescriptionsV2) Query(query string) ([]*pb.AgeRatingContentDescriptionV2, error) { 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) resp, err := a.request("https://api.igdb.com/v4/age_rating_content_descriptions_v2.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type AgeRatingOrganizations struct {
BaseEndpoint[pb.AgeRatingOrganization] BaseEndpoint[pb.AgeRatingOrganization]
} }
func NewAgeRatingOrganizations(request RequestFunc) *AgeRatingOrganizations { func NewAgeRatingOrganizations(request func(URL string, dataBody any) (*resty.Response, error)) *AgeRatingOrganizations {
a := &AgeRatingOrganizations{ a := &AgeRatingOrganizations{
BaseEndpoint[pb.AgeRatingOrganization]{ BaseEndpoint[pb.AgeRatingOrganization]{
endpointName: EPAgeRatingOrganizations, endpointName: EPAgeRatingOrganizations,
@ -24,7 +25,7 @@ func NewAgeRatingOrganizations(request RequestFunc) *AgeRatingOrganizations {
} }
func (a *AgeRatingOrganizations) Query(query string) ([]*pb.AgeRatingOrganization, error) { 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) resp, err := a.request("https://api.igdb.com/v4/age_rating_organizations.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type AgeRatings struct {
BaseEndpoint[pb.AgeRating] BaseEndpoint[pb.AgeRating]
} }
func NewAgeRatings(request RequestFunc) *AgeRatings { func NewAgeRatings(request func(URL string, dataBody any) (*resty.Response, error)) *AgeRatings {
a := &AgeRatings{ a := &AgeRatings{
BaseEndpoint[pb.AgeRating]{ BaseEndpoint[pb.AgeRating]{
endpointName: EPAgeRatings, endpointName: EPAgeRatings,
@ -24,7 +25,7 @@ func NewAgeRatings(request RequestFunc) *AgeRatings {
} }
func (a *AgeRatings) Query(query string) ([]*pb.AgeRating, error) { 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) resp, err := a.request("https://api.igdb.com/v4/age_ratings.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type AlternativeNames struct {
BaseEndpoint[pb.AlternativeName] BaseEndpoint[pb.AlternativeName]
} }
func NewAlternativeNames(request RequestFunc) *AlternativeNames { func NewAlternativeNames(request func(URL string, dataBody any) (*resty.Response, error)) *AlternativeNames {
a := &AlternativeNames{ a := &AlternativeNames{
BaseEndpoint[pb.AlternativeName]{ BaseEndpoint[pb.AlternativeName]{
endpointName: EPAlternativeNames, endpointName: EPAlternativeNames,
@ -24,7 +25,7 @@ func NewAlternativeNames(request RequestFunc) *AlternativeNames {
} }
func (a *AlternativeNames) Query(query string) ([]*pb.AlternativeName, error) { 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) resp, err := a.request("https://api.igdb.com/v4/alternative_names.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type Artworks struct {
BaseEndpoint[pb.Artwork] BaseEndpoint[pb.Artwork]
} }
func NewArtworks(request RequestFunc) *Artworks { func NewArtworks(request func(URL string, dataBody any) (*resty.Response, error)) *Artworks {
a := &Artworks{ a := &Artworks{
BaseEndpoint[pb.Artwork]{ BaseEndpoint[pb.Artwork]{
endpointName: EPArtworks, endpointName: EPArtworks,
@ -24,7 +25,7 @@ func NewArtworks(request RequestFunc) *Artworks {
} }
func (a *Artworks) Query(query string) ([]*pb.Artwork, error) { 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) resp, err := a.request("https://api.igdb.com/v4/artworks.pb", 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)
} }

View File

@ -5,27 +5,22 @@ import (
"strconv" "strconv"
"strings" "strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
) )
type RequestFunc func(method string, URL string, dataBody any) (*resty.Response, error)
type BaseEndpoint[T any] struct { type BaseEndpoint[T any] struct {
request RequestFunc request func(URL string, dataBody any) (*resty.Response, error)
endpointName Name endpointName EndpointName
queryFunc func(string) ([]*T, error) queryFunc func(string) ([]*T, error)
} }
func (b *BaseEndpoint[T]) GetEndpointName() Name { func (b *BaseEndpoint[T]) GetEndpointName() EndpointName {
return b.endpointName return b.endpointName
} }
func (b *BaseEndpoint[T]) Query(query string) ([]*T, error) { func (b *BaseEndpoint[T]) Query(query string) ([]*T, error) {
if b.queryFunc == nil { if b.queryFunc == nil {
return nil, fmt.Errorf("query method must be implemented by specific endpoint") return nil, fmt.Errorf("Query method must be implemented by specific endpoint")
} }
return b.queryFunc(query) return b.queryFunc(query)
} }
@ -52,29 +47,24 @@ func (b *BaseEndpoint[T]) GetByIDs(ids []uint64) ([]*T, error) {
return b.Query(fmt.Sprintf("where id = (%s); fields *;", builder.String())) return b.Query(fmt.Sprintf("where id = (%s); fields *;", builder.String()))
} }
func (b *BaseEndpoint[T]) Count() (uint64, error) { func (b *BaseEndpoint[T]) GetLastOneId() (uint64, error) {
resp, err := b.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s/count.pb", b.endpointName), "") res, err := b.Query("fields *; sort id desc; limit 1;")
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to request: %w", err) return 0, err
} }
if len(res) == 0 {
var res pb.Count return 0, fmt.Errorf("no results")
if err = proto.Unmarshal(resp.Body(), &res); err != nil {
return 0, fmt.Errorf("failed to unmarshal: %w", err)
} }
type IdGetter interface {
return uint64(res.Count), nil GetId() uint64
}
item, ok := any(res[0]).(IdGetter)
if !ok {
return 0, fmt.Errorf("invalid type")
}
return item.GetId(), nil
} }
func (b *BaseEndpoint[T]) Paginated(offset, limit uint64) ([]*T, error) { 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)) 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

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type CharacterGenders struct {
BaseEndpoint[pb.CharacterGender] BaseEndpoint[pb.CharacterGender]
} }
func NewCharacterGenders(request RequestFunc) *CharacterGenders { func NewCharacterGenders(request func(URL string, dataBody any) (*resty.Response, error)) *CharacterGenders {
a := &CharacterGenders{ a := &CharacterGenders{
BaseEndpoint[pb.CharacterGender]{ BaseEndpoint[pb.CharacterGender]{
endpointName: EPCharacterGenders, endpointName: EPCharacterGenders,
@ -24,7 +25,7 @@ func NewCharacterGenders(request RequestFunc) *CharacterGenders {
} }
func (a *CharacterGenders) Query(query string) ([]*pb.CharacterGender, error) { 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) resp, err := a.request("https://api.igdb.com/v4/character_genders.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type CharacterMugShots struct {
BaseEndpoint[pb.CharacterMugShot] BaseEndpoint[pb.CharacterMugShot]
} }
func NewCharacterMugShots(request RequestFunc) *CharacterMugShots { func NewCharacterMugShots(request func(URL string, dataBody any) (*resty.Response, error)) *CharacterMugShots {
a := &CharacterMugShots{ a := &CharacterMugShots{
BaseEndpoint[pb.CharacterMugShot]{ BaseEndpoint[pb.CharacterMugShot]{
endpointName: EPCharacterMugShots, endpointName: EPCharacterMugShots,
@ -24,7 +25,7 @@ func NewCharacterMugShots(request RequestFunc) *CharacterMugShots {
} }
func (a *CharacterMugShots) Query(query string) ([]*pb.CharacterMugShot, error) { 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) resp, err := a.request("https://api.igdb.com/v4/character_mug_shots.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type CharacterSpecies struct {
BaseEndpoint[pb.CharacterSpecie] BaseEndpoint[pb.CharacterSpecie]
} }
func NewCharacterSpecies(request RequestFunc) *CharacterSpecies { func NewCharacterSpecies(request func(URL string, dataBody any) (*resty.Response, error)) *CharacterSpecies {
a := &CharacterSpecies{ a := &CharacterSpecies{
BaseEndpoint[pb.CharacterSpecie]{ BaseEndpoint[pb.CharacterSpecie]{
endpointName: EPCharacterSpecies, endpointName: EPCharacterSpecies,
@ -24,7 +25,7 @@ func NewCharacterSpecies(request RequestFunc) *CharacterSpecies {
} }
func (a *CharacterSpecies) Query(query string) ([]*pb.CharacterSpecie, error) { 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) resp, err := a.request("https://api.igdb.com/v4/character_species.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type Characters struct {
BaseEndpoint[pb.Character] BaseEndpoint[pb.Character]
} }
func NewCharacters(request RequestFunc) *Characters { func NewCharacters(request func(URL string, dataBody any) (*resty.Response, error)) *Characters {
a := &Characters{ a := &Characters{
BaseEndpoint[pb.Character]{ BaseEndpoint[pb.Character]{
endpointName: EPCharacters, endpointName: EPCharacters,
@ -24,7 +25,7 @@ func NewCharacters(request RequestFunc) *Characters {
} }
func (a *Characters) Query(query string) ([]*pb.Character, error) { 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) resp, err := a.request("https://api.igdb.com/v4/characters.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type CollectionMembershipTypes struct {
BaseEndpoint[pb.CollectionMembershipType] BaseEndpoint[pb.CollectionMembershipType]
} }
func NewCollectionMembershipTypes(request RequestFunc) *CollectionMembershipTypes { func NewCollectionMembershipTypes(request func(URL string, dataBody any) (*resty.Response, error)) *CollectionMembershipTypes {
a := &CollectionMembershipTypes{ a := &CollectionMembershipTypes{
BaseEndpoint[pb.CollectionMembershipType]{ BaseEndpoint[pb.CollectionMembershipType]{
endpointName: EPCollectionMembershipTypes, endpointName: EPCollectionMembershipTypes,
@ -24,7 +25,7 @@ func NewCollectionMembershipTypes(request RequestFunc) *CollectionMembershipType
} }
func (a *CollectionMembershipTypes) Query(query string) ([]*pb.CollectionMembershipType, error) { 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) resp, err := a.request("https://api.igdb.com/v4/collection_membership_types.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type CollectionMemberships struct {
BaseEndpoint[pb.CollectionMembership] BaseEndpoint[pb.CollectionMembership]
} }
func NewCollectionMemberships(request RequestFunc) *CollectionMemberships { func NewCollectionMemberships(request func(URL string, dataBody any) (*resty.Response, error)) *CollectionMemberships {
a := &CollectionMemberships{ a := &CollectionMemberships{
BaseEndpoint[pb.CollectionMembership]{ BaseEndpoint[pb.CollectionMembership]{
endpointName: EPCollectionMemberships, endpointName: EPCollectionMemberships,
@ -24,7 +25,7 @@ func NewCollectionMemberships(request RequestFunc) *CollectionMemberships {
} }
func (a *CollectionMemberships) Query(query string) ([]*pb.CollectionMembership, error) { 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) resp, err := a.request("https://api.igdb.com/v4/collection_memberships.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type CollectionRelationTypes struct {
BaseEndpoint[pb.CollectionRelationType] BaseEndpoint[pb.CollectionRelationType]
} }
func NewCollectionRelationTypes(request RequestFunc) *CollectionRelationTypes { func NewCollectionRelationTypes(request func(URL string, dataBody any) (*resty.Response, error)) *CollectionRelationTypes {
a := &CollectionRelationTypes{ a := &CollectionRelationTypes{
BaseEndpoint[pb.CollectionRelationType]{ BaseEndpoint[pb.CollectionRelationType]{
endpointName: EPCollectionRelationTypes, endpointName: EPCollectionRelationTypes,
@ -24,7 +25,7 @@ func NewCollectionRelationTypes(request RequestFunc) *CollectionRelationTypes {
} }
func (a *CollectionRelationTypes) Query(query string) ([]*pb.CollectionRelationType, error) { 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) resp, err := a.request("https://api.igdb.com/v4/collection_relation_types.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type CollectionRelations struct {
BaseEndpoint[pb.CollectionRelation] BaseEndpoint[pb.CollectionRelation]
} }
func NewCollectionRelations(request RequestFunc) *CollectionRelations { func NewCollectionRelations(request func(URL string, dataBody any) (*resty.Response, error)) *CollectionRelations {
a := &CollectionRelations{ a := &CollectionRelations{
BaseEndpoint[pb.CollectionRelation]{ BaseEndpoint[pb.CollectionRelation]{
endpointName: EPCollectionRelations, endpointName: EPCollectionRelations,
@ -24,7 +25,7 @@ func NewCollectionRelations(request RequestFunc) *CollectionRelations {
} }
func (a *CollectionRelations) Query(query string) ([]*pb.CollectionRelation, error) { 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) resp, err := a.request("https://api.igdb.com/v4/collection_relations.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type CollectionTypes struct {
BaseEndpoint[pb.CollectionType] BaseEndpoint[pb.CollectionType]
} }
func NewCollectionTypes(request RequestFunc) *CollectionTypes { func NewCollectionTypes(request func(URL string, dataBody any) (*resty.Response, error)) *CollectionTypes {
a := &CollectionTypes{ a := &CollectionTypes{
BaseEndpoint[pb.CollectionType]{ BaseEndpoint[pb.CollectionType]{
endpointName: EPCollectionTypes, endpointName: EPCollectionTypes,
@ -24,7 +25,7 @@ func NewCollectionTypes(request RequestFunc) *CollectionTypes {
} }
func (a *CollectionTypes) Query(query string) ([]*pb.CollectionType, error) { 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) resp, err := a.request("https://api.igdb.com/v4/collection_types.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type Collections struct {
BaseEndpoint[pb.Collection] BaseEndpoint[pb.Collection]
} }
func NewCollections(request RequestFunc) *Collections { func NewCollections(request func(URL string, dataBody any) (*resty.Response, error)) *Collections {
a := &Collections{ a := &Collections{
BaseEndpoint[pb.Collection]{ BaseEndpoint[pb.Collection]{
endpointName: EPCollections, endpointName: EPCollections,
@ -24,7 +25,7 @@ func NewCollections(request RequestFunc) *Collections {
} }
func (a *Collections) Query(query string) ([]*pb.Collection, error) { 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) resp, err := a.request("https://api.igdb.com/v4/collections.pb", 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)
} }

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -13,7 +14,7 @@ type Companies struct {
BaseEndpoint[pb.Company] BaseEndpoint[pb.Company]
} }
func NewCompanies(request RequestFunc) *Companies { func NewCompanies(request func(URL string, dataBody any) (*resty.Response, error)) *Companies {
a := &Companies{ a := &Companies{
BaseEndpoint[pb.Company]{ BaseEndpoint[pb.Company]{
endpointName: EPCompanies, endpointName: EPCompanies,
@ -25,7 +26,7 @@ func NewCompanies(request RequestFunc) *Companies {
} }
func (a *Companies) Query(query string) ([]*pb.Company, error) { 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) resp, err := a.request("https://api.igdb.com/v4/companies.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type CompanyLogos struct {
BaseEndpoint[pb.CompanyLogo] BaseEndpoint[pb.CompanyLogo]
} }
func NewCompanyLogos(request RequestFunc) *CompanyLogos { func NewCompanyLogos(request func(URL string, dataBody any) (*resty.Response, error)) *CompanyLogos {
a := &CompanyLogos{ a := &CompanyLogos{
BaseEndpoint[pb.CompanyLogo]{ BaseEndpoint[pb.CompanyLogo]{
endpointName: EPCompanyLogos, endpointName: EPCompanyLogos,
@ -24,7 +25,7 @@ func NewCompanyLogos(request RequestFunc) *CompanyLogos {
} }
func (a *CompanyLogos) Query(query string) ([]*pb.CompanyLogo, error) { 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) resp, err := a.request("https://api.igdb.com/v4/company_logos.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type CompanyStatuses struct {
BaseEndpoint[pb.CompanyStatus] BaseEndpoint[pb.CompanyStatus]
} }
func NewCompanyStatuses(request RequestFunc) *CompanyStatuses { func NewCompanyStatuses(request func(URL string, dataBody any) (*resty.Response, error)) *CompanyStatuses {
a := &CompanyStatuses{ a := &CompanyStatuses{
BaseEndpoint[pb.CompanyStatus]{ BaseEndpoint[pb.CompanyStatus]{
endpointName: EPCompanyStatuses, endpointName: EPCompanyStatuses,
@ -24,7 +25,7 @@ func NewCompanyStatuses(request RequestFunc) *CompanyStatuses {
} }
func (a *CompanyStatuses) Query(query string) ([]*pb.CompanyStatus, error) { 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) resp, err := a.request("https://api.igdb.com/v4/company_statuses.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type CompanyWebsites struct {
BaseEndpoint[pb.CompanyWebsite] BaseEndpoint[pb.CompanyWebsite]
} }
func NewCompanyWebsites(request RequestFunc) *CompanyWebsites { func NewCompanyWebsites(request func(URL string, dataBody any) (*resty.Response, error)) *CompanyWebsites {
a := &CompanyWebsites{ a := &CompanyWebsites{
BaseEndpoint[pb.CompanyWebsite]{ BaseEndpoint[pb.CompanyWebsite]{
endpointName: EPCompanyWebsites, endpointName: EPCompanyWebsites,
@ -24,7 +25,7 @@ func NewCompanyWebsites(request RequestFunc) *CompanyWebsites {
} }
func (a *CompanyWebsites) Query(query string) ([]*pb.CompanyWebsite, error) { 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) resp, err := a.request("https://api.igdb.com/v4/company_websites.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type Covers struct {
BaseEndpoint[pb.Cover] BaseEndpoint[pb.Cover]
} }
func NewCovers(request RequestFunc) *Covers { func NewCovers(request func(URL string, dataBody any) (*resty.Response, error)) *Covers {
a := &Covers{ a := &Covers{
BaseEndpoint[pb.Cover]{ BaseEndpoint[pb.Cover]{
endpointName: EPCovers, endpointName: EPCovers,
@ -24,7 +25,7 @@ func NewCovers(request RequestFunc) *Covers {
} }
func (a *Covers) Query(query string) ([]*pb.Cover, error) { 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) resp, err := a.request("https://api.igdb.com/v4/covers.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type DateFormats struct {
BaseEndpoint[pb.DateFormat] BaseEndpoint[pb.DateFormat]
} }
func NewDateFormats(request RequestFunc) *DateFormats { func NewDateFormats(request func(URL string, dataBody any) (*resty.Response, error)) *DateFormats {
a := &DateFormats{ a := &DateFormats{
BaseEndpoint[pb.DateFormat]{ BaseEndpoint[pb.DateFormat]{
endpointName: EPDateFormats, endpointName: EPDateFormats,
@ -24,7 +25,7 @@ func NewDateFormats(request RequestFunc) *DateFormats {
} }
func (a *DateFormats) Query(query string) ([]*pb.DateFormat, error) { 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) resp, err := a.request("https://api.igdb.com/v4/date_formats.pb", 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)
} }

View File

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

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type EventLogos struct {
BaseEndpoint[pb.EventLogo] BaseEndpoint[pb.EventLogo]
} }
func NewEventLogos(request RequestFunc) *EventLogos { func NewEventLogos(request func(URL string, dataBody any) (*resty.Response, error)) *EventLogos {
a := &EventLogos{ a := &EventLogos{
BaseEndpoint[pb.EventLogo]{ BaseEndpoint[pb.EventLogo]{
endpointName: EPEventLogos, endpointName: EPEventLogos,
@ -24,7 +25,7 @@ func NewEventLogos(request RequestFunc) *EventLogos {
} }
func (a *EventLogos) Query(query string) ([]*pb.EventLogo, error) { 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) resp, err := a.request("https://api.igdb.com/v4/event_logos.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type EventNetworks struct {
BaseEndpoint[pb.EventNetwork] BaseEndpoint[pb.EventNetwork]
} }
func NewEventNetworks(request RequestFunc) *EventNetworks { func NewEventNetworks(request func(URL string, dataBody any) (*resty.Response, error)) *EventNetworks {
a := &EventNetworks{ a := &EventNetworks{
BaseEndpoint[pb.EventNetwork]{ BaseEndpoint[pb.EventNetwork]{
endpointName: EPEventNetworks, endpointName: EPEventNetworks,
@ -24,7 +25,7 @@ func NewEventNetworks(request RequestFunc) *EventNetworks {
} }
func (a *EventNetworks) Query(query string) ([]*pb.EventNetwork, error) { 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) resp, err := a.request("https://api.igdb.com/v4/event_networks.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type Events struct {
BaseEndpoint[pb.Event] BaseEndpoint[pb.Event]
} }
func NewEvents(request RequestFunc) *Events { func NewEvents(request func(URL string, dataBody any) (*resty.Response, error)) *Events {
a := &Events{ a := &Events{
BaseEndpoint[pb.Event]{ BaseEndpoint[pb.Event]{
endpointName: EPEvents, endpointName: EPEvents,
@ -24,7 +25,7 @@ func NewEvents(request RequestFunc) *Events {
} }
func (a *Events) Query(query string) ([]*pb.Event, error) { 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) resp, err := a.request("https://api.igdb.com/v4/events.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type ExternalGameSources struct {
BaseEndpoint[pb.ExternalGameSource] BaseEndpoint[pb.ExternalGameSource]
} }
func NewExternalGameSources(request RequestFunc) *ExternalGameSources { func NewExternalGameSources(request func(URL string, dataBody any) (*resty.Response, error)) *ExternalGameSources {
a := &ExternalGameSources{ a := &ExternalGameSources{
BaseEndpoint[pb.ExternalGameSource]{ BaseEndpoint[pb.ExternalGameSource]{
endpointName: EPExternalGameSources, endpointName: EPExternalGameSources,
@ -24,7 +25,7 @@ func NewExternalGameSources(request RequestFunc) *ExternalGameSources {
} }
func (a *ExternalGameSources) Query(query string) ([]*pb.ExternalGameSource, error) { 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) resp, err := a.request("https://api.igdb.com/v4/external_game_sources.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type ExternalGames struct {
BaseEndpoint[pb.ExternalGame] BaseEndpoint[pb.ExternalGame]
} }
func NewExternalGames(request RequestFunc) *ExternalGames { func NewExternalGames(request func(URL string, dataBody any) (*resty.Response, error)) *ExternalGames {
a := &ExternalGames{ a := &ExternalGames{
BaseEndpoint[pb.ExternalGame]{ BaseEndpoint[pb.ExternalGame]{
endpointName: EPExternalGames, endpointName: EPExternalGames,
@ -24,7 +25,7 @@ func NewExternalGames(request RequestFunc) *ExternalGames {
} }
func (a *ExternalGames) Query(query string) ([]*pb.ExternalGame, error) { 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) resp, err := a.request("https://api.igdb.com/v4/external_games.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type Franchises struct {
BaseEndpoint[pb.Franchise] BaseEndpoint[pb.Franchise]
} }
func NewFranchises(request RequestFunc) *Franchises { func NewFranchises(request func(URL string, dataBody any) (*resty.Response, error)) *Franchises {
a := &Franchises{ a := &Franchises{
BaseEndpoint[pb.Franchise]{ BaseEndpoint[pb.Franchise]{
endpointName: EPFranchises, endpointName: EPFranchises,
@ -24,7 +25,7 @@ func NewFranchises(request RequestFunc) *Franchises {
} }
func (a *Franchises) Query(query string) ([]*pb.Franchise, error) { 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) resp, err := a.request("https://api.igdb.com/v4/franchises.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type GameEngineLogos struct {
BaseEndpoint[pb.GameEngineLogo] BaseEndpoint[pb.GameEngineLogo]
} }
func NewGameEngineLogos(request RequestFunc) *GameEngineLogos { func NewGameEngineLogos(request func(URL string, dataBody any) (*resty.Response, error)) *GameEngineLogos {
a := &GameEngineLogos{ a := &GameEngineLogos{
BaseEndpoint[pb.GameEngineLogo]{ BaseEndpoint[pb.GameEngineLogo]{
endpointName: EPGameEngineLogos, endpointName: EPGameEngineLogos,
@ -24,7 +25,7 @@ func NewGameEngineLogos(request RequestFunc) *GameEngineLogos {
} }
func (a *GameEngineLogos) Query(query string) ([]*pb.GameEngineLogo, error) { 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) resp, err := a.request("https://api.igdb.com/v4/game_engine_logos.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type GameEngines struct {
BaseEndpoint[pb.GameEngine] BaseEndpoint[pb.GameEngine]
} }
func NewGameEngines(request RequestFunc) *GameEngines { func NewGameEngines(request func(URL string, dataBody any) (*resty.Response, error)) *GameEngines {
a := &GameEngines{ a := &GameEngines{
BaseEndpoint[pb.GameEngine]{ BaseEndpoint[pb.GameEngine]{
endpointName: EPGameEngines, endpointName: EPGameEngines,
@ -24,7 +25,7 @@ func NewGameEngines(request RequestFunc) *GameEngines {
} }
func (a *GameEngines) Query(query string) ([]*pb.GameEngine, error) { 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) resp, err := a.request("https://api.igdb.com/v4/game_engines.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type GameLocalizations struct {
BaseEndpoint[pb.GameLocalization] BaseEndpoint[pb.GameLocalization]
} }
func NewGameLocalizations(request RequestFunc) *GameLocalizations { func NewGameLocalizations(request func(URL string, dataBody any) (*resty.Response, error)) *GameLocalizations {
a := &GameLocalizations{ a := &GameLocalizations{
BaseEndpoint[pb.GameLocalization]{ BaseEndpoint[pb.GameLocalization]{
endpointName: EPGameLocalizations, endpointName: EPGameLocalizations,
@ -24,7 +25,7 @@ func NewGameLocalizations(request RequestFunc) *GameLocalizations {
} }
func (a *GameLocalizations) Query(query string) ([]*pb.GameLocalization, error) { 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) resp, err := a.request("https://api.igdb.com/v4/game_localizations.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type GameModes struct {
BaseEndpoint[pb.GameMode] BaseEndpoint[pb.GameMode]
} }
func NewGameModes(request RequestFunc) *GameModes { func NewGameModes(request func(URL string, dataBody any) (*resty.Response, error)) *GameModes {
a := &GameModes{ a := &GameModes{
BaseEndpoint[pb.GameMode]{ BaseEndpoint[pb.GameMode]{
endpointName: EPGameModes, endpointName: EPGameModes,
@ -24,7 +25,7 @@ func NewGameModes(request RequestFunc) *GameModes {
} }
func (a *GameModes) Query(query string) ([]*pb.GameMode, error) { 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) resp, err := a.request("https://api.igdb.com/v4/game_modes.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type GameReleaseFormats struct {
BaseEndpoint[pb.GameReleaseFormat] BaseEndpoint[pb.GameReleaseFormat]
} }
func NewGameReleaseFormats(request RequestFunc) *GameReleaseFormats { func NewGameReleaseFormats(request func(URL string, dataBody any) (*resty.Response, error)) *GameReleaseFormats {
a := &GameReleaseFormats{ a := &GameReleaseFormats{
BaseEndpoint[pb.GameReleaseFormat]{ BaseEndpoint[pb.GameReleaseFormat]{
endpointName: EPGameReleaseFormats, endpointName: EPGameReleaseFormats,
@ -24,7 +25,7 @@ func NewGameReleaseFormats(request RequestFunc) *GameReleaseFormats {
} }
func (a *GameReleaseFormats) Query(query string) ([]*pb.GameReleaseFormat, error) { 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) resp, err := a.request("https://api.igdb.com/v4/game_release_formats.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type GameStatuses struct {
BaseEndpoint[pb.GameStatus] BaseEndpoint[pb.GameStatus]
} }
func NewGameStatuses(request RequestFunc) *GameStatuses { func NewGameStatuses(request func(URL string, dataBody any) (*resty.Response, error)) *GameStatuses {
a := &GameStatuses{ a := &GameStatuses{
BaseEndpoint[pb.GameStatus]{ BaseEndpoint[pb.GameStatus]{
endpointName: EPGameStatuses, endpointName: EPGameStatuses,
@ -24,7 +25,7 @@ func NewGameStatuses(request RequestFunc) *GameStatuses {
} }
func (a *GameStatuses) Query(query string) ([]*pb.GameStatus, error) { 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) resp, err := a.request("https://api.igdb.com/v4/game_statuses.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type GameTimeToBeats struct {
BaseEndpoint[pb.GameTimeToBeat] BaseEndpoint[pb.GameTimeToBeat]
} }
func NewGameTimeToBeats(request RequestFunc) *GameTimeToBeats { func NewGameTimeToBeats(request func(URL string, dataBody any) (*resty.Response, error)) *GameTimeToBeats {
a := &GameTimeToBeats{ a := &GameTimeToBeats{
BaseEndpoint[pb.GameTimeToBeat]{ BaseEndpoint[pb.GameTimeToBeat]{
endpointName: EPGameTimeToBeats, endpointName: EPGameTimeToBeats,
@ -24,7 +25,7 @@ func NewGameTimeToBeats(request RequestFunc) *GameTimeToBeats {
} }
func (a *GameTimeToBeats) Query(query string) ([]*pb.GameTimeToBeat, error) { 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) resp, err := a.request("https://api.igdb.com/v4/game_time_to_beats.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type GameTypes struct {
BaseEndpoint[pb.GameType] BaseEndpoint[pb.GameType]
} }
func NewGameTypes(request RequestFunc) *GameTypes { func NewGameTypes(request func(URL string, dataBody any) (*resty.Response, error)) *GameTypes {
a := &GameTypes{ a := &GameTypes{
BaseEndpoint[pb.GameType]{ BaseEndpoint[pb.GameType]{
endpointName: EPGameTypes, endpointName: EPGameTypes,
@ -24,7 +25,7 @@ func NewGameTypes(request RequestFunc) *GameTypes {
} }
func (a *GameTypes) Query(query string) ([]*pb.GameType, error) { 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) resp, err := a.request("https://api.igdb.com/v4/game_types.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type GameVersionFeatureValues struct {
BaseEndpoint[pb.GameVersionFeatureValue] BaseEndpoint[pb.GameVersionFeatureValue]
} }
func NewGameVersionFeatureValues(request RequestFunc) *GameVersionFeatureValues { func NewGameVersionFeatureValues(request func(URL string, dataBody any) (*resty.Response, error)) *GameVersionFeatureValues {
a := &GameVersionFeatureValues{ a := &GameVersionFeatureValues{
BaseEndpoint[pb.GameVersionFeatureValue]{ BaseEndpoint[pb.GameVersionFeatureValue]{
endpointName: EPGameVersionFeatureValues, endpointName: EPGameVersionFeatureValues,
@ -24,7 +25,7 @@ func NewGameVersionFeatureValues(request RequestFunc) *GameVersionFeatureValues
} }
func (a *GameVersionFeatureValues) Query(query string) ([]*pb.GameVersionFeatureValue, error) { 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) resp, err := a.request("https://api.igdb.com/v4/game_version_feature_values.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type GameVersionFeatures struct {
BaseEndpoint[pb.GameVersionFeature] BaseEndpoint[pb.GameVersionFeature]
} }
func NewGameVersionFeatures(request RequestFunc) *GameVersionFeatures { func NewGameVersionFeatures(request func(URL string, dataBody any) (*resty.Response, error)) *GameVersionFeatures {
a := &GameVersionFeatures{ a := &GameVersionFeatures{
BaseEndpoint[pb.GameVersionFeature]{ BaseEndpoint[pb.GameVersionFeature]{
endpointName: EPGameVersionFeatures, endpointName: EPGameVersionFeatures,
@ -24,7 +25,7 @@ func NewGameVersionFeatures(request RequestFunc) *GameVersionFeatures {
} }
func (a *GameVersionFeatures) Query(query string) ([]*pb.GameVersionFeature, error) { 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) resp, err := a.request("https://api.igdb.com/v4/game_version_features.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type GameVersions struct {
BaseEndpoint[pb.GameVersion] BaseEndpoint[pb.GameVersion]
} }
func NewGameVersions(request RequestFunc) *GameVersions { func NewGameVersions(request func(URL string, dataBody any) (*resty.Response, error)) *GameVersions {
a := &GameVersions{ a := &GameVersions{
BaseEndpoint[pb.GameVersion]{ BaseEndpoint[pb.GameVersion]{
endpointName: EPGameVersions, endpointName: EPGameVersions,
@ -24,7 +25,7 @@ func NewGameVersions(request RequestFunc) *GameVersions {
} }
func (a *GameVersions) Query(query string) ([]*pb.GameVersion, error) { 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) resp, err := a.request("https://api.igdb.com/v4/game_versions.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type GameVideos struct {
BaseEndpoint[pb.GameVideo] BaseEndpoint[pb.GameVideo]
} }
func NewGameVideos(request RequestFunc) *GameVideos { func NewGameVideos(request func(URL string, dataBody any) (*resty.Response, error)) *GameVideos {
a := &GameVideos{ a := &GameVideos{
BaseEndpoint[pb.GameVideo]{ BaseEndpoint[pb.GameVideo]{
endpointName: EPGameVideos, endpointName: EPGameVideos,
@ -24,7 +25,7 @@ func NewGameVideos(request RequestFunc) *GameVideos {
} }
func (a *GameVideos) Query(query string) ([]*pb.GameVideo, error) { 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) resp, err := a.request("https://api.igdb.com/v4/game_videos.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type Games struct {
BaseEndpoint[pb.Game] BaseEndpoint[pb.Game]
} }
func NewGames(request RequestFunc) *Games { func NewGames(request func(URL string, dataBody any) (*resty.Response, error)) *Games {
a := &Games{ a := &Games{
BaseEndpoint[pb.Game]{ BaseEndpoint[pb.Game]{
endpointName: EPGames, endpointName: EPGames,
@ -24,7 +25,7 @@ func NewGames(request RequestFunc) *Games {
} }
func (a *Games) Query(query string) ([]*pb.Game, error) { 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) resp, err := a.request("https://api.igdb.com/v4/games.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type Genres struct {
BaseEndpoint[pb.Genre] BaseEndpoint[pb.Genre]
} }
func NewGenres(request RequestFunc) *Genres { func NewGenres(request func(URL string, dataBody any) (*resty.Response, error)) *Genres {
a := &Genres{ a := &Genres{
BaseEndpoint[pb.Genre]{ BaseEndpoint[pb.Genre]{
endpointName: EPGenres, endpointName: EPGenres,
@ -24,7 +25,7 @@ func NewGenres(request RequestFunc) *Genres {
} }
func (a *Genres) Query(query string) ([]*pb.Genre, error) { 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) resp, err := a.request("https://api.igdb.com/v4/genres.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type InvolvedCompanies struct {
BaseEndpoint[pb.InvolvedCompany] BaseEndpoint[pb.InvolvedCompany]
} }
func NewInvolvedCompanies(request RequestFunc) *InvolvedCompanies { func NewInvolvedCompanies(request func(URL string, dataBody any) (*resty.Response, error)) *InvolvedCompanies {
a := &InvolvedCompanies{ a := &InvolvedCompanies{
BaseEndpoint[pb.InvolvedCompany]{ BaseEndpoint[pb.InvolvedCompany]{
endpointName: EPInvolvedCompanies, endpointName: EPInvolvedCompanies,
@ -24,7 +25,7 @@ func NewInvolvedCompanies(request RequestFunc) *InvolvedCompanies {
} }
func (a *InvolvedCompanies) Query(query string) ([]*pb.InvolvedCompany, error) { 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) resp, err := a.request("https://api.igdb.com/v4/involved_companies.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type Keywords struct {
BaseEndpoint[pb.Keyword] BaseEndpoint[pb.Keyword]
} }
func NewKeywords(request RequestFunc) *Keywords { func NewKeywords(request func(URL string, dataBody any) (*resty.Response, error)) *Keywords {
a := &Keywords{ a := &Keywords{
BaseEndpoint[pb.Keyword]{ BaseEndpoint[pb.Keyword]{
endpointName: EPKeywords, endpointName: EPKeywords,
@ -24,7 +25,7 @@ func NewKeywords(request RequestFunc) *Keywords {
} }
func (a *Keywords) Query(query string) ([]*pb.Keyword, error) { 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) resp, err := a.request("https://api.igdb.com/v4/keywords.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type LanguageSupportTypes struct {
BaseEndpoint[pb.LanguageSupportType] BaseEndpoint[pb.LanguageSupportType]
} }
func NewLanguageSupportTypes(request RequestFunc) *LanguageSupportTypes { func NewLanguageSupportTypes(request func(URL string, dataBody any) (*resty.Response, error)) *LanguageSupportTypes {
a := &LanguageSupportTypes{ a := &LanguageSupportTypes{
BaseEndpoint[pb.LanguageSupportType]{ BaseEndpoint[pb.LanguageSupportType]{
endpointName: EPLanguageSupportTypes, endpointName: EPLanguageSupportTypes,
@ -24,7 +25,7 @@ func NewLanguageSupportTypes(request RequestFunc) *LanguageSupportTypes {
} }
func (a *LanguageSupportTypes) Query(query string) ([]*pb.LanguageSupportType, error) { 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) resp, err := a.request("https://api.igdb.com/v4/language_support_types.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type LanguageSupports struct {
BaseEndpoint[pb.LanguageSupport] BaseEndpoint[pb.LanguageSupport]
} }
func NewLanguageSupports(request RequestFunc) *LanguageSupports { func NewLanguageSupports(request func(URL string, dataBody any) (*resty.Response, error)) *LanguageSupports {
a := &LanguageSupports{ a := &LanguageSupports{
BaseEndpoint[pb.LanguageSupport]{ BaseEndpoint[pb.LanguageSupport]{
endpointName: EPLanguageSupports, endpointName: EPLanguageSupports,
@ -24,7 +25,7 @@ func NewLanguageSupports(request RequestFunc) *LanguageSupports {
} }
func (a *LanguageSupports) Query(query string) ([]*pb.LanguageSupport, error) { 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) resp, err := a.request("https://api.igdb.com/v4/language_supports.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type Languages struct {
BaseEndpoint[pb.Language] BaseEndpoint[pb.Language]
} }
func NewLanguages(request RequestFunc) *Languages { func NewLanguages(request func(URL string, dataBody any) (*resty.Response, error)) *Languages {
a := &Languages{ a := &Languages{
BaseEndpoint[pb.Language]{ BaseEndpoint[pb.Language]{
endpointName: EPLanguages, endpointName: EPLanguages,
@ -24,7 +25,7 @@ func NewLanguages(request RequestFunc) *Languages {
} }
func (a *Languages) Query(query string) ([]*pb.Language, error) { 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) resp, err := a.request("https://api.igdb.com/v4/languages.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type MultiplayerModes struct {
BaseEndpoint[pb.MultiplayerMode] BaseEndpoint[pb.MultiplayerMode]
} }
func NewMultiplayerModes(request RequestFunc) *MultiplayerModes { func NewMultiplayerModes(request func(URL string, dataBody any) (*resty.Response, error)) *MultiplayerModes {
a := &MultiplayerModes{ a := &MultiplayerModes{
BaseEndpoint[pb.MultiplayerMode]{ BaseEndpoint[pb.MultiplayerMode]{
endpointName: EPMultiplayerModes, endpointName: EPMultiplayerModes,
@ -24,7 +25,7 @@ func NewMultiplayerModes(request RequestFunc) *MultiplayerModes {
} }
func (a *MultiplayerModes) Query(query string) ([]*pb.MultiplayerMode, error) { 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) resp, err := a.request("https://api.igdb.com/v4/multiplayer_modes.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type NetworkTypes struct {
BaseEndpoint[pb.NetworkType] BaseEndpoint[pb.NetworkType]
} }
func NewNetworkTypes(request RequestFunc) *NetworkTypes { func NewNetworkTypes(request func(URL string, dataBody any) (*resty.Response, error)) *NetworkTypes {
a := &NetworkTypes{ a := &NetworkTypes{
BaseEndpoint[pb.NetworkType]{ BaseEndpoint[pb.NetworkType]{
endpointName: EPNetworkTypes, endpointName: EPNetworkTypes,
@ -24,7 +25,7 @@ func NewNetworkTypes(request RequestFunc) *NetworkTypes {
} }
func (a *NetworkTypes) Query(query string) ([]*pb.NetworkType, error) { 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) resp, err := a.request("https://api.igdb.com/v4/network_types.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type PlatformFamilies struct {
BaseEndpoint[pb.PlatformFamily] BaseEndpoint[pb.PlatformFamily]
} }
func NewPlatformFamilies(request RequestFunc) *PlatformFamilies { func NewPlatformFamilies(request func(URL string, dataBody any) (*resty.Response, error)) *PlatformFamilies {
a := &PlatformFamilies{ a := &PlatformFamilies{
BaseEndpoint[pb.PlatformFamily]{ BaseEndpoint[pb.PlatformFamily]{
endpointName: EPPlatformFamilies, endpointName: EPPlatformFamilies,
@ -24,7 +25,7 @@ func NewPlatformFamilies(request RequestFunc) *PlatformFamilies {
} }
func (a *PlatformFamilies) Query(query string) ([]*pb.PlatformFamily, error) { 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) resp, err := a.request("https://api.igdb.com/v4/platform_families.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type PlatformLogos struct {
BaseEndpoint[pb.PlatformLogo] BaseEndpoint[pb.PlatformLogo]
} }
func NewPlatformLogos(request RequestFunc) *PlatformLogos { func NewPlatformLogos(request func(URL string, dataBody any) (*resty.Response, error)) *PlatformLogos {
a := &PlatformLogos{ a := &PlatformLogos{
BaseEndpoint[pb.PlatformLogo]{ BaseEndpoint[pb.PlatformLogo]{
endpointName: EPPlatformLogos, endpointName: EPPlatformLogos,
@ -24,7 +25,7 @@ func NewPlatformLogos(request RequestFunc) *PlatformLogos {
} }
func (a *PlatformLogos) Query(query string) ([]*pb.PlatformLogo, error) { 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) resp, err := a.request("https://api.igdb.com/v4/platform_logos.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type PlatformTypes struct {
BaseEndpoint[pb.PlatformType] BaseEndpoint[pb.PlatformType]
} }
func NewPlatformTypes(request RequestFunc) *PlatformTypes { func NewPlatformTypes(request func(URL string, dataBody any) (*resty.Response, error)) *PlatformTypes {
a := &PlatformTypes{ a := &PlatformTypes{
BaseEndpoint[pb.PlatformType]{ BaseEndpoint[pb.PlatformType]{
endpointName: EPPlatformTypes, endpointName: EPPlatformTypes,
@ -24,7 +25,7 @@ func NewPlatformTypes(request RequestFunc) *PlatformTypes {
} }
func (a *PlatformTypes) Query(query string) ([]*pb.PlatformType, error) { 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) resp, err := a.request("https://api.igdb.com/v4/platform_types.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type PlatformVersionCompanies struct {
BaseEndpoint[pb.PlatformVersionCompany] BaseEndpoint[pb.PlatformVersionCompany]
} }
func NewPlatformVersionCompanies(request RequestFunc) *PlatformVersionCompanies { func NewPlatformVersionCompanies(request func(URL string, dataBody any) (*resty.Response, error)) *PlatformVersionCompanies {
a := &PlatformVersionCompanies{ a := &PlatformVersionCompanies{
BaseEndpoint[pb.PlatformVersionCompany]{ BaseEndpoint[pb.PlatformVersionCompany]{
endpointName: EPPlatformVersionCompanies, endpointName: EPPlatformVersionCompanies,
@ -24,7 +25,7 @@ func NewPlatformVersionCompanies(request RequestFunc) *PlatformVersionCompanies
} }
func (a *PlatformVersionCompanies) Query(query string) ([]*pb.PlatformVersionCompany, error) { 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) resp, err := a.request("https://api.igdb.com/v4/platform_version_companies.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type PlatformVersionReleaseDates struct {
BaseEndpoint[pb.PlatformVersionReleaseDate] BaseEndpoint[pb.PlatformVersionReleaseDate]
} }
func NewPlatformVersionReleaseDates(request RequestFunc) *PlatformVersionReleaseDates { func NewPlatformVersionReleaseDates(request func(URL string, dataBody any) (*resty.Response, error)) *PlatformVersionReleaseDates {
a := &PlatformVersionReleaseDates{ a := &PlatformVersionReleaseDates{
BaseEndpoint[pb.PlatformVersionReleaseDate]{ BaseEndpoint[pb.PlatformVersionReleaseDate]{
endpointName: EPPlatformVersionReleaseDates, endpointName: EPPlatformVersionReleaseDates,
@ -24,7 +25,7 @@ func NewPlatformVersionReleaseDates(request RequestFunc) *PlatformVersionRelease
} }
func (a *PlatformVersionReleaseDates) Query(query string) ([]*pb.PlatformVersionReleaseDate, error) { 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) resp, err := a.request("https://api.igdb.com/v4/platform_version_release_dates.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type PlatformVersions struct {
BaseEndpoint[pb.PlatformVersion] BaseEndpoint[pb.PlatformVersion]
} }
func NewPlatformVersions(request RequestFunc) *PlatformVersions { func NewPlatformVersions(request func(URL string, dataBody any) (*resty.Response, error)) *PlatformVersions {
a := &PlatformVersions{ a := &PlatformVersions{
BaseEndpoint[pb.PlatformVersion]{ BaseEndpoint[pb.PlatformVersion]{
endpointName: EPPlatformVersions, endpointName: EPPlatformVersions,
@ -24,7 +25,7 @@ func NewPlatformVersions(request RequestFunc) *PlatformVersions {
} }
func (a *PlatformVersions) Query(query string) ([]*pb.PlatformVersion, error) { 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) resp, err := a.request("https://api.igdb.com/v4/platform_versions.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type PlatformWebsites struct {
BaseEndpoint[pb.PlatformWebsite] BaseEndpoint[pb.PlatformWebsite]
} }
func NewPlatformWebsites(request RequestFunc) *PlatformWebsites { func NewPlatformWebsites(request func(URL string, dataBody any) (*resty.Response, error)) *PlatformWebsites {
a := &PlatformWebsites{ a := &PlatformWebsites{
BaseEndpoint[pb.PlatformWebsite]{ BaseEndpoint[pb.PlatformWebsite]{
endpointName: EPPlatformWebsites, endpointName: EPPlatformWebsites,
@ -24,7 +25,7 @@ func NewPlatformWebsites(request RequestFunc) *PlatformWebsites {
} }
func (a *PlatformWebsites) Query(query string) ([]*pb.PlatformWebsite, error) { 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) resp, err := a.request("https://api.igdb.com/v4/platform_websites.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type Platforms struct {
BaseEndpoint[pb.Platform] BaseEndpoint[pb.Platform]
} }
func NewPlatforms(request RequestFunc) *Platforms { func NewPlatforms(request func(URL string, dataBody any) (*resty.Response, error)) *Platforms {
a := &Platforms{ a := &Platforms{
BaseEndpoint[pb.Platform]{ BaseEndpoint[pb.Platform]{
endpointName: EPPlatforms, endpointName: EPPlatforms,
@ -24,7 +25,7 @@ func NewPlatforms(request RequestFunc) *Platforms {
} }
func (a *Platforms) Query(query string) ([]*pb.Platform, error) { 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) resp, err := a.request("https://api.igdb.com/v4/platforms.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type PlayerPerspectives struct {
BaseEndpoint[pb.PlayerPerspective] BaseEndpoint[pb.PlayerPerspective]
} }
func NewPlayerPerspectives(request RequestFunc) *PlayerPerspectives { func NewPlayerPerspectives(request func(URL string, dataBody any) (*resty.Response, error)) *PlayerPerspectives {
a := &PlayerPerspectives{ a := &PlayerPerspectives{
BaseEndpoint[pb.PlayerPerspective]{ BaseEndpoint[pb.PlayerPerspective]{
endpointName: EPPlayerPerspectives, endpointName: EPPlayerPerspectives,
@ -24,7 +25,7 @@ func NewPlayerPerspectives(request RequestFunc) *PlayerPerspectives {
} }
func (a *PlayerPerspectives) Query(query string) ([]*pb.PlayerPerspective, error) { 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) resp, err := a.request("https://api.igdb.com/v4/player_perspectives.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type PopularityPrimitives struct {
BaseEndpoint[pb.PopularityPrimitive] BaseEndpoint[pb.PopularityPrimitive]
} }
func NewPopularityPrimitives(request RequestFunc) *PopularityPrimitives { func NewPopularityPrimitives(request func(URL string, dataBody any) (*resty.Response, error)) *PopularityPrimitives {
a := &PopularityPrimitives{ a := &PopularityPrimitives{
BaseEndpoint[pb.PopularityPrimitive]{ BaseEndpoint[pb.PopularityPrimitive]{
endpointName: EPPopularityPrimitives, endpointName: EPPopularityPrimitives,
@ -24,7 +25,7 @@ func NewPopularityPrimitives(request RequestFunc) *PopularityPrimitives {
} }
func (a *PopularityPrimitives) Query(query string) ([]*pb.PopularityPrimitive, error) { 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) resp, err := a.request("https://api.igdb.com/v4/popularity_primitives.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type PopularityTypes struct {
BaseEndpoint[pb.PopularityType] BaseEndpoint[pb.PopularityType]
} }
func NewPopularityTypes(request RequestFunc) *PopularityTypes { func NewPopularityTypes(request func(URL string, dataBody any) (*resty.Response, error)) *PopularityTypes {
a := &PopularityTypes{ a := &PopularityTypes{
BaseEndpoint[pb.PopularityType]{ BaseEndpoint[pb.PopularityType]{
endpointName: EPPopularityTypes, endpointName: EPPopularityTypes,
@ -24,7 +25,7 @@ func NewPopularityTypes(request RequestFunc) *PopularityTypes {
} }
func (a *PopularityTypes) Query(query string) ([]*pb.PopularityType, error) { 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) resp, err := a.request("https://api.igdb.com/v4/popularity_types.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type Regions struct {
BaseEndpoint[pb.Region] BaseEndpoint[pb.Region]
} }
func NewRegions(request RequestFunc) *Regions { func NewRegions(request func(URL string, dataBody any) (*resty.Response, error)) *Regions {
a := &Regions{ a := &Regions{
BaseEndpoint[pb.Region]{ BaseEndpoint[pb.Region]{
endpointName: EPRegions, endpointName: EPRegions,
@ -24,7 +25,7 @@ func NewRegions(request RequestFunc) *Regions {
} }
func (a *Regions) Query(query string) ([]*pb.Region, error) { 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) resp, err := a.request("https://api.igdb.com/v4/regions.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type ReleaseDateRegions struct {
BaseEndpoint[pb.ReleaseDateRegion] BaseEndpoint[pb.ReleaseDateRegion]
} }
func NewReleaseDateRegions(request RequestFunc) *ReleaseDateRegions { func NewReleaseDateRegions(request func(URL string, dataBody any) (*resty.Response, error)) *ReleaseDateRegions {
a := &ReleaseDateRegions{ a := &ReleaseDateRegions{
BaseEndpoint[pb.ReleaseDateRegion]{ BaseEndpoint[pb.ReleaseDateRegion]{
endpointName: EPReleaseDateRegions, endpointName: EPReleaseDateRegions,
@ -24,7 +25,7 @@ func NewReleaseDateRegions(request RequestFunc) *ReleaseDateRegions {
} }
func (a *ReleaseDateRegions) Query(query string) ([]*pb.ReleaseDateRegion, error) { 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) resp, err := a.request("https://api.igdb.com/v4/release_date_regions.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type ReleaseDateStatuses struct {
BaseEndpoint[pb.ReleaseDateStatus] BaseEndpoint[pb.ReleaseDateStatus]
} }
func NewReleaseDateStatuses(request RequestFunc) *ReleaseDateStatuses { func NewReleaseDateStatuses(request func(URL string, dataBody any) (*resty.Response, error)) *ReleaseDateStatuses {
a := &ReleaseDateStatuses{ a := &ReleaseDateStatuses{
BaseEndpoint[pb.ReleaseDateStatus]{ BaseEndpoint[pb.ReleaseDateStatus]{
endpointName: EPReleaseDateStatuses, endpointName: EPReleaseDateStatuses,
@ -24,7 +25,7 @@ func NewReleaseDateStatuses(request RequestFunc) *ReleaseDateStatuses {
} }
func (a *ReleaseDateStatuses) Query(query string) ([]*pb.ReleaseDateStatus, error) { 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) resp, err := a.request("https://api.igdb.com/v4/release_date_statuses.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type ReleaseDates struct {
BaseEndpoint[pb.ReleaseDate] BaseEndpoint[pb.ReleaseDate]
} }
func NewReleaseDates(request RequestFunc) *ReleaseDates { func NewReleaseDates(request func(URL string, dataBody any) (*resty.Response, error)) *ReleaseDates {
a := &ReleaseDates{ a := &ReleaseDates{
BaseEndpoint[pb.ReleaseDate]{ BaseEndpoint[pb.ReleaseDate]{
endpointName: EPReleaseDates, endpointName: EPReleaseDates,
@ -24,7 +25,7 @@ func NewReleaseDates(request RequestFunc) *ReleaseDates {
} }
func (a *ReleaseDates) Query(query string) ([]*pb.ReleaseDate, error) { 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) resp, err := a.request("https://api.igdb.com/v4/release_dates.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type Screenshots struct {
BaseEndpoint[pb.Screenshot] BaseEndpoint[pb.Screenshot]
} }
func NewScreenshots(request RequestFunc) *Screenshots { func NewScreenshots(request func(URL string, dataBody any) (*resty.Response, error)) *Screenshots {
a := &Screenshots{ a := &Screenshots{
BaseEndpoint[pb.Screenshot]{ BaseEndpoint[pb.Screenshot]{
endpointName: EPScreenshots, endpointName: EPScreenshots,
@ -24,7 +25,7 @@ func NewScreenshots(request RequestFunc) *Screenshots {
} }
func (a *Screenshots) Query(query string) ([]*pb.Screenshot, error) { 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) resp, err := a.request("https://api.igdb.com/v4/screenshots.pb", 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)
} }

View File

@ -10,6 +10,7 @@ import (
"time" "time"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"github.com/bestnite/go-flaresolverr" "github.com/bestnite/go-flaresolverr"
@ -22,20 +23,18 @@ var webSearchCFCookies struct {
} }
type Search struct { type Search struct {
endpointName Name request func(URL string, dataBody any) (*resty.Response, error)
request RequestFunc
flaresolverr *flaresolverr.Flaresolverr flaresolverr *flaresolverr.Flaresolverr
} }
func NewSearch(request RequestFunc) *Search { func NewSearch(request func(URL string, dataBody any) (*resty.Response, error)) *Search {
return &Search{ return &Search{
endpointName: EPSearch,
request: request, request: request,
} }
} }
func (a *Search) Search(query string) ([]*pb.Search, error) { 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) resp, err := a.request("https://api.igdb.com/v4/search.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type Themes struct {
BaseEndpoint[pb.Theme] BaseEndpoint[pb.Theme]
} }
func NewThemes(request RequestFunc) *Themes { func NewThemes(request func(URL string, dataBody any) (*resty.Response, error)) *Themes {
a := &Themes{ a := &Themes{
BaseEndpoint[pb.Theme]{ BaseEndpoint[pb.Theme]{
endpointName: EPThemes, endpointName: EPThemes,
@ -24,7 +25,7 @@ func NewThemes(request RequestFunc) *Themes {
} }
func (a *Themes) Query(query string) ([]*pb.Theme, error) { 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) resp, err := a.request("https://api.igdb.com/v4/themes.pb", 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)
} }

View File

@ -1,103 +1,36 @@
package endpoint package endpoint
import ( import (
"encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
"github.com/go-resty/resty/v2"
) )
type Webhooks struct { type Webhooks struct {
request RequestFunc request func(URL string, dataBody any) (*resty.Response, error)
} }
func NewWebhooks(request RequestFunc) *Webhooks { func NewWebhooks(request func(URL string, dataBody any) (*resty.Response, error)) *Webhooks {
return &Webhooks{ return &Webhooks{
request: request, request: request,
} }
} }
type WebhookMethod string func (a *Webhooks) Register(endpoint EndpointName, secret, callbackUrl string) error {
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 := url.Values{}
dataBody.Set("url", callbackUrl) dataBody.Set("url", callbackUrl)
dataBody.Set("secret", secret) dataBody.Set("secret", secret)
dataBody.Set("method", string(method)) dataBody.Set("method", "update")
resp, err := a.request(fmt.Sprintf("https://api.igdb.com/v4/%s/webhooks/", endpoint), dataBody.Encode())
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s/webhooks/", endpoint), dataBody.Encode())
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to make request: %s: %w", callbackUrl, err) return 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 { if resp.StatusCode() == http.StatusOK {
return nil return nil
} }
return fmt.Errorf("failed to activate webhook: %s: %s", callbackUrl, resp.String())
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
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type WebsiteTypes struct {
BaseEndpoint[pb.WebsiteType] BaseEndpoint[pb.WebsiteType]
} }
func NewWebsiteTypes(request RequestFunc) *WebsiteTypes { func NewWebsiteTypes(request func(URL string, dataBody any) (*resty.Response, error)) *WebsiteTypes {
a := &WebsiteTypes{ a := &WebsiteTypes{
BaseEndpoint[pb.WebsiteType]{ BaseEndpoint[pb.WebsiteType]{
endpointName: EPWebsiteTypes, endpointName: EPWebsiteTypes,
@ -24,7 +25,7 @@ func NewWebsiteTypes(request RequestFunc) *WebsiteTypes {
} }
func (a *WebsiteTypes) Query(query string) ([]*pb.WebsiteType, error) { 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) resp, err := a.request("https://api.igdb.com/v4/website_types.pb", 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)
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
"github.com/go-resty/resty/v2"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -12,7 +13,7 @@ type Websites struct {
BaseEndpoint[pb.Website] BaseEndpoint[pb.Website]
} }
func NewWebsites(request RequestFunc) *Websites { func NewWebsites(request func(URL string, dataBody any) (*resty.Response, error)) *Websites {
a := &Websites{ a := &Websites{
BaseEndpoint[pb.Website]{ BaseEndpoint[pb.Website]{
endpointName: EPWebsites, endpointName: EPWebsites,
@ -24,7 +25,7 @@ func NewWebsites(request RequestFunc) *Websites {
} }
func (a *Websites) Query(query string) ([]*pb.Website, error) { func (a *Websites) Query(query string) ([]*pb.Website, error) {
resp, err := a.request("POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query) resp, err := a.request("https://api.igdb.com/v4/websites.pb", 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)
} }

View File

@ -24,6 +24,6 @@ func request() *resty.Request {
type disableLogger struct{} type disableLogger struct{}
func (d disableLogger) Errorf(string, ...interface{}) {} func (d disableLogger) Errorf(format string, v ...interface{}) {}
func (d disableLogger) Warnf(string, ...interface{}) {} func (d disableLogger) Warnf(format string, v ...interface{}) {}
func (d disableLogger) Debugf(string, ...interface{}) {} func (d disableLogger) Debugf(format string, v ...interface{}) {}

View File

@ -7,21 +7,21 @@ import (
"time" "time"
) )
type TwitchToken struct { type twitchToken struct {
clientID string clientID string
clientSecret string clientSecret string
token string token string
expires time.Time expires time.Time
} }
func NewTwitchToken(clientID, clientSecret string) *TwitchToken { func NewTwitchToken(clientID, clientSecret string) *twitchToken {
return &TwitchToken{ return &twitchToken{
clientID: clientID, clientID: clientID,
clientSecret: clientSecret, clientSecret: clientSecret,
} }
} }
func (t *TwitchToken) getToken() (string, error) { func (t *twitchToken) getToken() (string, error) {
if t.token != "" && time.Now().Before(t.expires) { if t.token != "" && time.Now().Before(t.expires) {
return t.token, nil return t.token, nil
} }
@ -34,7 +34,7 @@ func (t *TwitchToken) getToken() (string, error) {
return token, nil return token, nil
} }
func (t *TwitchToken) loginTwitch() (string, time.Duration, error) { func (t *twitchToken) loginTwitch() (string, time.Duration, error) {
baseURL, _ := url.Parse("https://id.twitch.tv/oauth2/token") baseURL, _ := url.Parse("https://id.twitch.tv/oauth2/token")
params := url.Values{} params := url.Values{}
params.Add("client_id", t.clientID) params.Add("client_id", t.clientID)