Coder Social home page Coder Social logo

henry-sarabia / igdb Goto Github PK

View Code? Open in Web Editor NEW
79.0 79.0 16.0 1.13 MB

Go client for the Internet Game Database API

Home Page: https://api.igdb.com/

License: MIT License

Go 100.00%
api api-client client game games go golang igdb igdb-api video-game

igdb's People

Contributors

dustyjewett avatar henrysarabia avatar kriztoph avatar lavos avatar mark-ignacio avatar sprak3000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

igdb's Issues

ServerError struct does not have Temporary method

When attempting to assert that the errors.Cause(err) of a returned error from a service is Temporary for the new ratelimiting requirements:

type temporary interface {
        Temporary() bool
}

func IsTemporary(err error) bool {
        te, ok := errors.Cause(err).(temporary)
        fmt.Printf("IS TEMPORARY %#v %t\n", errors.Cause(err), ok)
        return ok && te.Temporary()
}

This prints:

IS TEMPORARY igdb.ServerError{Status:429, Msg:"too many requests", Temp:true} false

errors.Cause() returns a plain igdb.ServerError, not *igdb.ServerError, and a plain igdb.ServerError does not implement temporary. Only *igdb.ServerError has the required Temporary method:

igdb/error.go

Line 72 in dcac61d

func (e *ServerError) Temporary() bool {

Is there any reason we can't define this method on igdb.ServerError as that will cover both plain struct and pointer?

Replace Client's get method with post method

igdb/igdb.go

Lines 188 to 202 in 1a22d94

// Get sends a GET request to the provided endpoint with the provided options and
// stores the results in the value pointed to by result.
func (c *Client) get(end endpoint, result interface{}, opts ...Option) error {
req, err := c.request(end, opts...)
if err != nil {
return err
}
err = c.send(req, result)
if err != nil {
return errors.Wrap(err, "cannot make GET request")
}
return nil
}

The current get method should instead be a post method.

error.go needs renaming, refactoring, and tests

  1. The custom Error messages sent from the IGDB servers should have a more descriptive name like ServerError to differentiate it from regular errors.
  2. checkResults function needs refactoring and tests.
  3. checkResponse tests need to be updated to match current standards.

README does not reflect the v3 migration update

The current README has examples and information that no longer reflects the current state of the repository due to the API v3 migration. The README should be updated with appropriate examples and information.

Package should have tagged releases

Adopting semantic versioning using git tags will allow users to differentiate versions of the package and, more importantly, identify when the package has made a breaking change.

ts.Client undefined

Hey! I'm new to using this project and looks like it will be perfect if I can get it running.

When getting the project from github (and when trying to build my own project) I'm getting the following error:

../../../../../github.com/Henry-Sarabia/igdb/testing.go:44: ts.Client undefined (type *httptest.Server has no field or method Client)

I pulled the latest about an hour ago.

Thanks!

Update authentication

The API will stop accepting the user-key header for authentication.

Instead, the following headers will be expected:

  • Client-ID: Twitch Developer Application Client ID
  • Authorization: Twitch Developer Application Access Token

Replace DeepEqual error checking

igdb/endpoints_test.go

Lines 32 to 34 in 1a22d94

if !reflect.DeepEqual(errors.Cause(err), test.wantErr) {
t.Errorf("got: <%v>, want: <%v>", errors.Cause(err), test.wantErr)
}

The reflect.DeepEqual method should not be used with errors as it is here and in other files.
Instead, the error checking should be performed conventionally: errors.Cause(err) != test.wantErr

The following files need these changes:

  • endpoints_test.go
  • error_test.go ๐Ÿค”
  • tag_test.go

Refactor SizedImageURL to remove DPR ratio

SizedImageURL has an integer parameter for the DPR ratio of the requested image. The issue is that there is only 2 possible ratios allowed for the image service. So, the DPR ratio can either be factored out into two distinct functions or be changed to a boolean parameter.

Change GET requests to POST

The IGDB API will stop accepting GET requests with a body.
The current code is compliant with the Apicalypse schema which writes to the request body.
As such, these GET requests must change to use the POST method.

Migrate to IGDB v3

IGDB has updated from version 2 to version 3 of their API. With this update comes several changes that need to be adopted in this package.

  • Data structure changes including field renaming.
  • Expand parameter is deprecated.
  • Sroll API is deprecated.
  • Filters are now facilitated through the Apicalypse query language.
  • New error messages

Migration from v2 to v3 will make breaking changes.

Remove unsupported TestDummy endpoint

With the update to IGDB API v4, the TestDummy endpoint seems to have been dropped.
Client support for the defunct TestDummy endpoint should also be dropped.

The following files need to be altered:

  • endpoints.go
  • igdb.go

The following files should be deleted:

  • testdummy.go
  • testdummy_test.go
  • testdummyenum_string.go
  • test_data/testdummy_get.json
  • test_data/testdummy_list.json

Error messages should be organized and standardized

As of now, there are errors scattered around the repository instead of either being consolidated in one file or logically grouped together. Certain errors messages are also redundant and should be updated to match the rest.

Expanding fields breaks JSON decoding

The IGDB API now supports field expansion. Field expansion allows a user to denote subfields to retrieve in addition to the regular fields of a request. Because Go is a statically typed language, when additional subfields are sent back in the JSON object, the object will no longer match the defined struct and the JSON decoder will return an error.

Here are three options for dealing with this problem.

  1. Ignore the issue and simply let the package return a JSON decoder error when expansion is used.
  2. Take a half-measure and fail early. Document the lack of expansion support and check for any expanded fields before sending the request. If an expanded field is found, return an error explaining the lack of expansion support.
  3. Take a half-measure and return an untyped object. Add an extra function for each endpoint that allows expansion but will return an untyped map of the JSON object instead of a proper populated Go struct type.

Image tests will not compile

Image tests are currently being ignored using build tags. If unignored, the tests will not compile. This should be fixed.

Function equalSlice should be replaced

equalSlice is a function used to check if the contents of two slices are equal. It it primarily used in the unit tests of many functions. It is designed to work with slices of any type. As such, the function makes use of reflection and empty interfaces. This should be replaced by a more type-safe and faster alternative.

equalSlice is used in place of reflect.DeepEqual because the output of the functions being tested do not always produce slices in the same order. To replace equalSlice, these slices should instead simply be sorted before being tested for equality.

Implement Temporary errors

The API has a rate limit of 4 per second. If exceeded, returns status 429 Too Many Requests.
If an error of this nature is received by the client, it is, by definition, temporary.

The error returned to the user should implement the Temporary behavior.
See this article for more info.

Why is client.Games.List ids required now?

Hello.

IDs where nil and my script worked fine. Now the ids are required. Why?
My script is getting game realeases between two dates where ids are not existing. Is there other way i could achieve that after update.

Implement Search endpoint

With the API v3 update, Search got its own endpoint. This endpoint should be fully supported to search for Characters, Collections, Games, People, Platforms, and Themes.

Implement private IGDB endpoints

IGDB has a set of private endpoints meant for pro tier users. Three of these endpoints are listed under the regular list of endpoints so they are already implemented, but there still remains a dozen unimplemented endpoints.

Improve test coverage

Test coverage has dropped to 92% after the most recent pull request. It would be prudent to reevaluate the current suite of tests to raise the overall test coverage.

Exported types and variables missing documentation

Several exported variables, constants, and groups of variables and constants are still missing documentation. In addition, most if not all of the private endpoint types are still missing documentation.

Private endpoints may need additional authorization

There may be an additional required header to be sent in each request for pro and enterprise tier users. If this is the case, the auth token must be supported in the NewClient function or another function entirely.

Option Exclude is missing

With the update to API v3 and the introduction of Apicalypse, a new option for excluding fields for a request has been added. The package is still missing this functionality.

Some endpoints are still unsupported

I seem to have missed several endpoints when migrating to IGDBv3.

These are the unsupported endpoints:

  • Product Family
  • Pulse
  • Pulse Group
  • Pulse Source
  • Pulse URL

Update struct fields

The following objects have had their fields altered by the API:

  • Game
  • Platform
  • Search

See this for full changes.

The respective structs should be updated accordingly.

Outdated tier information

IGDB has removed the tier system. Instead, everyone gets the formerly pro-tier permissions.

Tier information can be found in the following:

  • Achievements
  • AchievementIcons
  • ExternalGames
  • Options

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.