Coder Social home page Coder Social logo

igdb-api-node's People

Contributors

dependabot[bot] avatar dsibilly avatar dustyjewett avatar husnjak avatar krazyjakee 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

igdb-api-node's Issues

Unable to perform expanded filtered query.

The two 'where' statements below are straight from the filters section of the igdb documentation. One works, the commented out one doesn't. None of the example queries showing how to query an expanded field work.

const igdb = igDB(igdbAPIKey)
async function main () {
  try {
    // const where = 'release_dates.platform = (6)'
    const where = '(platforms = [6,48] & genres = 13) | (platforms = [130,48] & genres = 12)'
    const response = await igdb
      .fields('name')
      .limit(2)
      .offset(0)
      .sort('name')
      .where(where)
      .request('/games')
    console.log(response.data)
  } catch (error) {
    console.log(error)
  }
}
main()

I can't query any expanded data on the "release_dates" section of the /games endpoint. The same query works from the shell using curl. This could just be outdated documentation, but since the issue only occurs here, I'm reporting it as a bug.

Unexpected token export in version 3.1.2

I'm getting this error when importing the library on a clean install using Node 9.4.0:

C:\git\sandbox\per\igdb-plotly\api\node_modules\igdb-api-node\configuration.js:1
(function (exports, require, module, __filename, __dirname) { export default {
                                                              ^^^^^^
SyntaxError: Unexpected token export
    at new Script (vm.js:51:7)
    at createScript (vm.js:138:10)
    at Object.runInThisContext (vm.js:199:10)
    at Module._compile (module.js:624:28)
    at Module._extensions..js (module.js:671:10)
    at Object.require.extensions.(anonymous function) [as .js] (C:\git\sandbox\per\igdb-plotly\api\node_modules\babel-register\lib\node.js:152:7)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)

Seems like the distributed configuration.js is using ES6 module syntax. Version 3.1.1 works great though.

Create a development branch

It might be prudent to keep active development off the master branch with a published npm module. If master always matches the latest release on npm, then visitors and potential contributors are guaranteed to be able to get a stable snapshot of the source regardless of the current state of project development.

My proposal is as follows:

  • A new develop branch for active development between releases. Pull requests and maintainer-driven additions happen on this branch.
  • A new release branch is cut from develop for each release candidate. This is for code review, bugfixes, shoring up unit test coverage, etc. As a final step before release, this branch gets the version number bump.
  • Once a release is complete, it is merged to master and the merge commit is tagged with the release version (e.g., v3.0.1). This tag is then merged to develop to backport any fixes created during the release process. The release branch is then safely deleted.
  • As soon as master has been updated, the new module version should be published to npm.

I apologize if this sounds a little complex, but this is a tiny bit of housekeeping that has proved incredibly useful to me in other collaborative projects. Keeping master as slow and stable as possible helps avoid bugs and new contributor confusion both!

not getting ratings back in res

const Settings = {
 offset: 0,
 limit: 20,
 sort: "",
 search: "",
 where: "",
};

module.exports = {
 All: async function (settings = Settings) {
   const { offset, limit, sort, search, where, url } = settings;

   const response = await client
     .fields(["*", "screenshots.*", "cover.*", "rating"])

     .limit(limit || 20)
     .offset(offset || 0)

     .sort(sort)
     .search(search)

     .where(where)

     .request("games");

   return response.data;
 },
};

is not sending back ratings, or am I missing something?

Handling error status with try catch function

Hello,

I need to handle the status error within a trycatch function. I dont want to search for "400" in the error message, but want to have a status code. I would like to have an object with message and status code.

Thank you!

Getting the platforms for the found games

This is more of a question rather than an issue. Wasn't sure where else to post it.

I have this code that grabs the games based on the search query inputted by the user. However, the platforms in the returned "release_dates" object are ids to the platforms table. Is there any neat way to get the games and convert the platform ids to their respective platform names without creating a conversion object/array?

client.games({
  filters: {
    'release_dates.date-gt': moment().format("YYYY-MM-DD"),
  },
  limit: 2,
  search: e.target.value
}, [
  'name',
  'cover.url',
  'release_dates'
]).then(response => {
  this.setState({games: response.body});
}).catch(error => {
  throw error;
});

As a general question, does this wrapper provide, or plans to provide, any means of retrieving all the necessary data in the cases of "one-to-many" and "many-to-many" relationships, effectively replacing the ids to other tables with the data from them?

Enabling CORS in React client

I'm attempted to use this wrapper to fetch games, but I'm being blocked by CORS policy. After reading through the IGDB CORS documentation, I'm struggling to figure out if it's possible to call IGDB through React without setting up a server. Is there a way to modify the code below (this repo's example) to enable CORS and allow this call?

const getGames = async () => {
  const response = await igdb(APP_KEY)
    .fields(
      "id, name, rating, rating_count, popularity, cover.url, summary, release_dates.y, category"
    ) 
    .limit(20) 
    .sort("rating", "desc")
    .where("rating > 0 & rating_count >= 200 & category = 0")
   .request("/games"); 
  console.log(response.data);
};

Thank you for your time.

Coffee script?

Do i have to npm coffee-script just to use this package?
I am getting this error

modules/igdb-api-node/index.coffee:5
get = (url, callback, opts = false) ->
                                     ^
SyntaxError: Unexpected token >
    at Object.exports.runInThisContext (vm.js:78:16)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/matt/Workspace/Personal/MEAN2.0_seed/server/routes/api.js:5:14)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)

when I look at the master of this package it shows nothing about it though.
also I see that it is @2.0.0 but it is not found when I attempt to npm i

Filtering games based on platform

Hey,

Using your example I tried to use the .games method to obtain games only available on PS4.

I found the ID for PS4 platform from another endpoint: https://igdbcom-internet-game-database-v1.p.mashape.com/platforms/?fields=name&limit=40&offset=0 => { "id": 48, "name": "PlayStation 4" }

However, once I use it like this:

igdb.games({ search: gameQuery, limit: 10, filters: { "release_dates.platform-eq": 48 }, fields: "*" }).then(result => {});

It doesn't return any results. Is it because the games are not associated with platform?

PS. I tried to manually test the endpoint using Postman with the request https://igdbcom-internet-game-database-v1.p.mashape.com/games/?search=horizon&limit=10&filter[platforms][eq]=48&fields=* and filter[release_dates.platform][eq]=48

request-endpoint: fields are processed and appended to the query string multiple times

When there are multiple query options and a fields Array passed to request-endpoint, the fields Array is processed once for each option and appended to the query string result, such that requests like:

client.release_dates({
  filters: {
    'game-eq': 38722
  },
  expand: 'platform,game',
  limit: 50
}, [ 'human', 'region', 'platform.name', 'game.name', 'game.cover.url' ])
.then(response => { this.setState({ games: response.body }); })
.catch(error => { throw error; });

...results in a request url of https://igdbcom-internet-game-database-v1.p.mashape.com/release_dates/?filter[game][eq]=38722&fields=human,region,platform.name,game.name,game.cover.url&expand=platform,game&fields=human,region,platform.name,game.name,game.cover.url&limit=50&fields=human,region,platform.name,game.name,game.cover.url

The fields array should be processed separately from the options, or a sentinel set to that it is only processed and appended to the query string once.

Reported by @Cohaven in #16

Support for the expand Parameter

Something like...

client.games({
  filters: {
    'game-eq': 38722
  },
  expand: ['platform', 'game'],
  limit: 50
}, [ 'human', 'region', 'platform.name', 'game.name', 'game.cover.url' ])
.then(response => { this.setState({ games: response.body }); })
.catch(error => { throw error; });

e2f11d6

Finding the most popular/hot games currently

Hey, so in v3 there was the "popularity" field which kind of helped me to get the most popular games,
but now(v4) i don't know what i should rely on, the ratings on igdb is not something i can rely on, there is low number of raters there and are sometimes very inaccurate imo.
I'm trying to get the hottest online games played currently, like "among us", "league of legends", "dota 2", "fortnite", "Call of duty" etc...
Getting the top games in twitch could also help.
What should i do? thanks.

Alternative names should be aliases when searching games

Sorry I write here because I have no Twitch or Discord account to log this feature request in uservoice or in your tchat.

You can delete this issue after adding it to https://twitch.uservoice.com/forums/929953-igdb?query=Alternative%20names%20should%20be%20aliases%20when%20searching%20games


If I search for カービィのグルメフェス or for End of Eternity, I should find https://www.igdb.com/games/kirbys-dream-buffet and https://www.igdb.com/games/resonance-of-fate in the first results, but I don't find them at all.
The alternative names are not seen by the search.

Getting 400 Error Code

Hi,

I am trying to fetch the sample code but it's returning (400 Bad Request) error code. Here's my code:

const igdb = require('igdb-api-node').default;
const apicalypse = require('apicalypse')
const client = igdb('my-key');


async function queryMode() {
    const response = await client
    .fields('name,age_rating,platforms')
    .limit(5)
    .offset(100)
    .sort('name')
    // important bit here
    .where('platforms.category = 6')
    .request('/games')
    
return response.data;
}

queryMode().then((data) => {
    console.log(data)
}).catch((e) => {
    console.log(e)
})

Problem getting filters applied

I hope this is not a duplicate: I checked the closed issues related to filtering but none of them seems to be exactly what I'm looking for.

I'm trying to query sorting by aggregated_rating, but filtering whatever games has less than 10 reviews.

I tried this

await client.games({
    fields: "*",
    order: "aggregated_rating:desc",
    filters: {
      "aggregated_rating_count.gt": 10,
    },
})

but the endpoint hit was https://api-endpoint.igdb.com/games/?fields=*&order=aggregated_rating:desc&filter[aggregated_rating_count.gt]=10 and the filter didn't get applied as it should have filter[aggregated_rating_count][gt]=10 for it to work as expected.

I couldn't find any way to make it happen but changing my filters to

 filters: {
    "aggregated_rating_count][gt": 10,
 },

which is rather ugly.
Am I missing something?

Popular Games Feed

Is it possible to get a feed of the popular games as shown on the IGDB.com front page?

If so, how?

I've been looking at https://igdb.github.io/api/endpoints/feed/ , but it's highly confusing. After reading the docs page I still have no idea what feeds are in regards to IGDB or what is needed to request them properly.

HTTP Status 400 error on specific company

I have been using this package for my discord bot for a while now and today someone reported getting the following error to me: Error: HTTP Status 400 - https://api-2445582011268.apicast.io/companies/1659,?fields=name

Checking this company ID in the API Live Test I do get a result with status code 200:

All other companies I have tried return a result just fine, only company 1659 does not. Due to the error seemingly being related to the URL the request is sent to I figured I'd first create an issue here before letting it over to hoping the API gets updated to fix the issue.

I get my data from the API through the following snippet:

const igdbapi = require('igdb-api-node').default,

    async function run(msg) {
        const igdb = igdbapi(auth.igdbAPIKey),
            gameInfo = await igdb.games({
                'search': args.game,
                'fields': ['id', 'name', 'summary', 'rating', 'developers', 'publishers', 'genres', 'release_dates', 'platforms', 'cover', 'esrb', 'pegi'],
                'limit': 1,
                'offset': 0
            }),
            developerInfo = await igdb.companies({
                'ids': gameInfo.body[0].developers.concat(gameInfo.body[0].publishers),
                'fields': ['name']
            });
    }

Whats the point of using ids for genres, themes, platforms?

Wouldn't it be better to just return strings instead when searching for a game?

Or even allow the ability to give the entire list of themes/platforms/genres, so a dev can cache them/store them someplace?

Having to make 3-4 requests to find all the information about 1 game, seems like a redundant thing to do.

Support 3scale endpoint

Mashape is not the only endpoint that is used now.

3scale has a different endpoint and different header key.

https://api-2445582011268.apicast.io

header: key is 32 characters long.
user-key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

mashape keys are 50 characters long. We could use that to automatically set the endpoint to use.

Tag number conversion functions

Tag numbers are a very useful way to sort and filter results, however, the implementation is a bit convoluted (as described here) so I propose we implement a couple of handy functions to convert to and from a tag number.

Replace client.scroll with a method on applicable response objects

Using client.scroll is kind of awkward because it's effectively a method that allows for retrieving arbitrary JSON responses from any URL. It requires a tiny bit of boilerplate to use, as illustrated in its unit test:

import igdb from 'igdb-api-node';

const client = igdb('API_KEY');

client.games({
    order: 'rating',
    scroll: 1
}).then(response => {
   /* do stuff with the initial response... */

    /* scroll to the next page */
    return client.scroll(response.scrollUrl);
}).then(scrollResponse => {
    /* do stuff with the scroll response */
});

While perform-request is building the response object, it can easily add a scroll method directly to that object that has all the data it needs already baked into it, such that the following becomes possible:

import igdb from 'igdb-api-node';

const client = igdb('API_KEY');

client.games({
    order: 'rating',
    scroll: 1
}).then(response => {
   /* do stuff with the initial response... */

    /*
    Scroll to the next page.
    The response already knows where to go,
    so we don't need to provide any URL at all.
    */
    return response.scroll();
}).then(scrollResponse => {
    /* do stuff with the scroll response */
});

It's a very small change, but it allows the user to completely disregard the API implementation details of scroll URLs, and moves the responsibility for scroll logic from the client to the response itself.

Responses without scrollUrl set will end up having no scroll method, so inspecting for its existence before calling it may be necessary. It's no different from inspecting to make sure that response.scrollUrl is set, so it may not be a big deal. If that proves awkward, though, the method can default to a stub that returns either:

  • a rejected Promise with an Error stating that there is no more content to scroll to, or...
  • a resolved Promise with an object which has a body property set to false.

There may be better ideas on how to resolve that bit. However, moving scrolling from a generalized client method to a response method seems like a worthwhile change. Keeping the client method around as a deprecated part of the API until v4.0.0 seems prudent to avoid introducing a breaking change and violating semver.

Doesn't work. igdb() not a function error.

import igdb from 'igdb-api-node';
const { data } = await igdb()
.search('Halo')
.fields(['name', 'release_dates.y'])
.request('/games')
    const { data } = await igdb()
                           ^

TypeError: igdb is not a function

.scrollAll returning HTTP 429

After a few minutes of letting it process, i get the following:

Error: HTTP Status 429 - https://api-endpoint.igdb.com/games/?fields=name&limit=2
    at /Users/bosu/Documents/igdb/node_modules/igdb-api-node/lib/perform-request.js:28:16
    at new Promise (<anonymous>)
    at /Users/bosu/Documents/igdb/node_modules/igdb-api-node/lib/perform-request.js:26:12
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

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.