Flexible, durable, asynchronous Riot Games API client in Node.js
$ npm install --save rito
Scope it on in...
var rito = require('./rito.js');
Then create an instance with immutable configuration.
var client = new rito.Client({key: <key>, base: 'api.pvp.net'}, require('https'));
Register an endpoint at a specific version -- this ensures you'll always know which version of which endpoint your application depends on! You only need to register whatever endpoints you need -- this is an ideal thing to have in your configuration somewhere.
All endpoints and their associated routes are defined in /api/generated/api.json
client.use('champion', '1.2', err, res);
{ msg: 'Added alias for name api.lol.region.champion' }
{ msg: 'Added alias for name api.lol.region.champion.id' }
Create callbacks to do anything with the output streams you desire! Obvious uses include propagating to a database, logging, and sending messages to statsd.
var res = function (res) {
console.log(res)
};
var err = function (err) {
console.log(err)
};
Rather than call the rito.call()
method directly (which is flexible but cumbersome), it may be easier
to bind a set of variables to it-- this way you can configure whatever response handling and output streams
you want, and you only have to do it in one place!
var _ = require('lodash');
//Placeholders are route name, route method (e.g. GET), region, and parameters.
var call = _.bind(client.call, client, _, _, _, _, err, function (res) {
if (res.statusCode == 200) {
res.on('data', function (d) {
process.stdout.write(d);
});
} else {
console.log(res.statusCode)
}
});
You can then create whatever functions you want for convenience in your application!
var getChampionById = function (region, id) {
call('api.lol.region.champion.id', 'GET', region, {id: id})
};
And then the fun part...
getChampionById('na', 7);
{
"id": 7,
"active": true,
"botEnabled": false,
"freeToPlay": false,
"botMmEnabled": false,
"rankedPlayEnabled": true
}
Aww yiss. GG, ff20, Rito pls fix.
MIT