IGDB

Build StatusCoverage StatusInline docs

Installation

The package can be installed by adding igdb to your list of dependencies in mix.exs:

def deps do
[
{:igdb, "~> 1.0.0"}
]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/igdb.

Configuration

You will need to set the following configuration variables in your config/config.exs file:

use Mix.Config
config :igdb, api_key: "IGDB_API_KEY",
api_root: "IGDB_API_ROOT"

For security, I recommend that you use environment variables rather than hard coding your account credentials. If you don't already have an environment variable manager, you can create a .env file in your project with the following content:

export IGDB_API_KEY="<production key here>"
export IGDB_API_ROOT="https://api-v3.igdb.com"

Then, just be sure to run source .env in your shell before compiling your project.

Usage

Returns a list of resources found from given search options.

If the resources could not be loaded, search/1 will return a 3-element tuple in this format, {:error, message, code}. The code is the HTTP status code returned by the IGDB API, for example, 404.

Options

The options should be passed as a keyword list. Below is a list of allowed keys:

OptionValuesExample
fieldsatom, string or list of those; can be nested with periods"", ["", "game.*]
sortstring; column with the direction (asc/desc); cannot be used with search"created_at desc"
limitinteger10
searchstring; text you want to search for; cannot be used with sort"Final Fantasy"
wherelist of strings, will be joined with AND - you may construct your own["platforms = 48", "date > 1538129354"]
excludestring; exclude irrelevant data from your query"tags"

Refer to individual resources for the available columns to filter on.

Examples

iex> Igdb.Game.search(search: "Final Fantasy", limit: 5, where: ["platforms = 48"], fields: "name")
{:ok,
[
%{id: 37087, name: "Monster of the Deep: Final Fantasy XV"},
%{id: 11169, name: "Final Fantasy VII Remake"},
%{id: 36831, name: "Dissidia Final Fantasy NT"},
%{id: 38492, name: "Final Fantasy XV Deluxe Edition"},
%{id: 26069, name: "FINAL FANTASY XV - Season Pass Upgrade"}
]}

Credits

A lot of inspiration taken from ex_twilio. Thank you!