CollectionsCollections Database

IGDB Javascript library

The IGDB Javascript library is a wrapper for the The Internet Game Database (IGDB) API.

To use this library you need to register an API Key, please visit the IGDB API Docs for more info.

The source code is available in the GitHub repository.

app.api.igdb
The library is accessible from the app.api.igdb object.
client_id string
Set the Client ID for the API (required).
client_secret string
Set the Client Secret for the API (required).
search(query app.query object) array of search results
The function searches games and returns an array of search results.
getGame(id integer) game
The function gets a game by ID. It returns a game or undefined if it doesn't exist.
extraFields array of string
Additional fields used to query the game. See the IGDB Docs for more info.
gameClass class
Set a custom class for the game, the class must extend app.classes.api.igdb.game
request(endpoint string, body string) app.request
Create a new HTTP request with the specified endpoint and body. You may call this function in your custom implementation.
refreshTokenIfNeeded()
Refresh the access token if needed. Usually you don't need to call this function, the library manages the access token automatically.
clearToken()
Clear the access token from the local storage.
// IGDB search (1.1)
// https://github.com/risolvipro/collections

app.api.igdb.client_id = "YOUR CLIENT ID";
app.api.igdb.client_secret = "YOUR CLIENT SECRET";

let results = app.api.igdb.search(app.query);
app.result(results);

Game

app.classes.api.igdb.game
This class manages a game.
constructor(data json) game
data json
The json data returned by the IGDB API.
id integer
ID of the game.
name string
Name of the game.
dataCoverURL date
Cover URL from the json data.
coverURL(size string) string
Get the cover URL in the specified size. Size parameter is optional, default value is "original".
requestCover(size string) image
Request the cover in the specified size. Size parameter is optional, default value is "original". It returns an image or undefined if the request fails.
firstReleaseDate date
First release date of the game.
platforms array of list item suggestions
Get the platforms as an array of list item suggestions.
genres array of list item suggestions
Get the genres as an array of list item suggestions.
summary string
Get the summary.
// IGDB document (1.1)
// https://github.com/risolvipro/collections

app.api.igdb.client_id = "YOUR CLIENT ID";
app.api.igdb.client_secret = "YOUR CLIENT SECRET";

let game = app.api.igdb.getGame(app.params.id);

if(game == undefined) {
    app.fail();
}

let builder = app.document.builder();

builder.setString(game.name, "title");
builder.setImage(game.requestCover(), "cover");
builder.setListItems(game.platforms, "platform");
builder.setListItems(game.genres, "genre");
builder.setDate(game.firstReleaseDate, "release-date");
builder.setString(game.summary, "summary");

app.result(builder);