Closed Cohaven closed 7 years ago
I think you need this: https://igdb.github.io/api/references/expander/
That's awesome, but how do I use the wrapper with an expander?
The wrapper doesn't seem to have support for the expander functionality at this time. Should probably be put on the dev roadmap at some point if the intent is to keep 1:1 feature parity between the API and this module.
Sadly the expander cannot expand the platform in the release_date object directly but there is a workaround using the release_dates endpoint.
// {{api_url}}/release_dates/?fields=human,region,platform.name,game.name,game.cover.url&filter[game][eq]=38722&expand=platform,game
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; });
This is how it should work (in theory) but it's not implemented that way yet.
To clarify: the URL is how it can work now, but the JS code is how it should work if implemented in the wrapper module?
@dsibilly yes, exactly. Sorry for the confusion.
@Cohaven since it accepts any kind of parameter, this might actually work for you.
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; });
@krazyjakee I tried to use the example code you gave, but I get an error 400 when trying to execute the code.
This is the URL it seems to be generating:
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
Not sure why the fields are being triplicated.
There's no need to keep closing and reopening the issue.
@Cohaven, you've discovered a bug in the wrapper. I'll be looking into this tonight. Thanks for reporting it!
@dsibilly Sorry about the closing and reopening. I wasn't doing it on purpose. Wasn't paying attention to the meaning of the "Close and comment" button. Haven't done GitHub issue posts before.
No problem. Do you think it affects the ability of the code suggested by @krazyjakee to successfully use the expander?
I've submitted #20, which should fix the bug that duplicates the fields
part of the URL query string. However, even with that fix in my local copy, I get the same HTTP 400 error you report:
Error: HTTP Status 400 - https://igdbcom-internet-game-database-v1.p.mashape.com/release_dates/?filter[game][eq]=38722&expand=platform,game&limit=50&fields=region,platform.name,game.name,game.cover.url
at Request._callback (/Users/dsibilly/Projects/igdb-api-node/lib/perform-request.js:38:62)
at Request.self.callback (/Users/dsibilly/Projects/igdb-api-node/node_modules/request/request.js:188:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (/Users/dsibilly/Projects/igdb-api-node/node_modules/request/request.js:1171:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage.<anonymous> (/Users/dsibilly/Projects/igdb-api-node/node_modules/request/request.js:1091:12)
at IncomingMessage.g (events.js:292:16)
at emitNone (events.js:91:20)
Also, the example code should use an Array for submitting the expand
parameters:
client.release_dates({
filters: {
'game-eq': 38722
},
expand: [
'platform',
'game'
],
limit: 50
}, [
'region',
'platform.name',
'game.name',
'game.cover.url'
]).then(response => {
console.log(response.body);
}).catch(console.error);
EDIT: Oh, nevermind. The expand
functionality doesn't seem to work for me at all. I get the following JSON response (as well as the HTTP 400 error) when i attempt the resulting URL directly with my API key:
{"status":400,"message":"Expander API is not available to the BASIC plan."}
So this may be the issue, perhaps?
Ok, so...
@Cohaven what prevents you from caching a conversion table?
Caching a conversion table is very much an acceptable solution for now. Progress is being made on the expander. A complete list of expandable fields are listed here and it will continue to grow: https://igdb.github.io/api/references/expander/
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?
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?