jwalton / lol-js

node.js bindings for the Riot API for League of Legends
MIT License
26 stars 11 forks source link

NPM

Build Status Coverage Status Dependency Status devDependency Status Npm Version

lol.js is a client for fetching data from the Riot API for League of Legends. There are many node.js packages out there which give you access to the Riot API, but none has as complete a feature set as lol.js.

Note 2.x has breaking changes. See the changelog for details.

Features

Installation

npm install --save lol-js

Example Usage

With callbacks:

var lol = require('lol-js');
var lolClient = lol.client({
    apiKey: 'blahblahblah',
    cache: lol.redisCache({host: '127.0.0.1', port: 6379})
};
lolClient.getChampionById('na', 53, {champData: ['all']}, function(err, data) {
    console.log("Found ", data.name);
    lolClient.destroy();
});

With promises:

var lol = require('lol-js');
var lolClient = lol.client({
    apiKey: 'blahblahblah',
    cache: lol.redisCache({host: '127.0.0.1', port: 6379})
});
lolClient.getChampionById('na', 53, {champData: ['all']})
.then(function (data) {
    console.log("Found ", data.name);
    lolClient.destroy();
});

Creating a Client

The first step to using lol-js is to create a new client by calling lol.client(). This function takes a configuation object with the following options:

Functions

You can browse the well-documented code in the src/api folder for a complete description of all the functions you can call. Each file in src/api is a mixin object which is added to the client object's prototype. Note that the source files only contain the promise version of the code - the callback versions are generated automatically.

Caching

lol-js will automatically cache results from Riot's API for you, allowing you to focus on using the data rather than worrying about rate limits and the Riot server going down.

The easiest way to cache objects is to use a built-in cache type. The following built in cache types exist:

If you don't want to use one of the built in cache types, you can easily specify your own caching functions. The cache parameter passed to a new client is a {set, get, destroy} object, where set(params, value) stores an object in the cache, and get(params, callback) is a function which retrieves an object from the cache and calls callback(err, value) returning the cached value or null if the value is not available. In both cases, params is an object consisting of:

When calling cache.set(), lol-js may pass in "none" in place of a value to indicate the value does not exist. cache.get() should return "none" if such a params object is passed in. lol-js will always try to retrieve an object from the cache first, and will only make a REST request if the cached object is not available.

Finally, if the cache defines a destroy() function, this will be called when the lol-js client is destroyed.

Development

If you're interested in contributing, check out the development docs.