Wrapper of the official League of Legends public API with integrated cache support.
Install this package by running npm install lolapi
.
var lolapi = require('lolapi')('my-api-key', 'euw');
var summonerName = 'wickd';
lolapi.Summoner.getByName(summonerName, function (error, summoner) {
if (error) throw error;
/* summoner object
{ wickd:
{
id: 71500,
name: 'Wickd',
profileIconId: 613,
summonerLevel: 30,
revisionDate: 1408199475000
}
} */
var summonerId = summoner[summonerName].id;
lolapi.Summoner.getRunes(summonerId, function (error, runes) {
if (error) throw error;
// do something with runes
})
});
API callbacks follow default Node.JS pattern returning error object as the first argument and result as the second one.
Every API call has an optional argument options
with following available properties:
- region may be added in order to define the region; if it's not set, region from the constructor will be used; if that is not defined either, region will default to Europe West
- cacheRequest a flag indicating if specific request should be cached(note that you must have redis server running in order for this to work)
Most of the API calls have additional available properties covered below.
- Constructor(apiKey[, region, options])
- setRateLimit(limitPer10s, limitPer10min)
- Champion.get(championId, [options, ]callback)
- Champion.getAll([options, ]callback)
- CurrentGame.getBySummonerId(summonerId, [options, ]callback)
- FeaturedGames.get([options, ]callback)
- Game.getBySummonerId(summonerId, [options, ]callback)
- League.getBySummonerId(summonerIds, [options, ]callback)
- League.getEntriesBySummonerId(summonerIds, [options, ]callback)
- League.getByTeamId(teamIds, [options, ]callback)
- League.getEntriesByTeamId(teamIds, [options, ]callback)
- League.getChallenger(type, [options, ]callback)
- League.getMaster(type, [options, ]callback)
- Match.get(matchId, [options, ]callback)
- MatchList.getBySummonerId(summonerIds, [options, ]callback)
- Static.getChampions([options, ]callback)
- Static.getChampion(championId, [options, ]callback)
- Static.getItems([options, ]callback)
- Static.getItem(itemId, [options, ]callback)
- Static.getMasteries([options, ]callback)
- Static.getMastery(masteryId, [options, ]callback)
- Static.getRunes([options, ]callback)
- Static.getRune(runeId, [options, ]callback)
- Static.getSummonerSpells([options, ]callback)
- Static.getSummonerSpell(summonerSpellId, [options, ]callback)
- Static.getRealm([options, ]callback)
- Static.getVersions([options, ]callback)
- Stats.getRanked([options, ]callback)
- Stats.getSummary([options, ]callback)
- Summoner.get(summonerIds, [options, ]callback)
- Summoner.getByName(summonerNames, [options, ]callback)
- Summoner.getName(summonerIds, [options, ]callback)
- Summoner.getRunes(summonerIds, [options, ]callback)
- Summoner.getMasteries(summonerIds, [options, ]callback)
- Team.get(teamId, [options, ]callback)
- Team.getBySummonerId(summonerId, [options, ]callback)
Constructor of the main singleton.
Additional options
properties:
- useRedis - a flag indicating if Redis cache database should be used(false by default). Please note, that in order to use cache, you must have redis server running on your computer
- port - port Redis server is running on(if unspecified, default 6379 will be used)
- hostname - hostname Redis server is running on(if unspecified, default 127.0.0.1 will be used)
- cacheTTL - sets a timeout on cached data in seconds(an hour by default)
Simple initialization:
var lolapi = require('lolapi')('my-api-key');
// ready to go!
A more advanced example:
var options = {
useRedis: true,
hostname: '127.0.0.1',
port: 6379,
cacheTTL: 7200
};
var lolapi = require('lolapi')('my-api-key', 'euw', options);
// all requests are now being cached with a timeout of 2 hours
var summonerName = 'wickd';
lolapi.Summoner.getByName(summonerName, function () {
// calls remote API server, will take 500ms~
lolapi.Summoner.getByName(summonerName, function () {
// takes results from cache, will now take 1-5 ms
});
});
Sets a request limit. When either limit is reached, subsequent requests will be queued and ran when possible.
Retrieves a champion by its ID.
Retrieves all champions.
Additional options
properties:
- freeToPlay - if true, will only return champions that are free to play
Example:
lolapi.Champion.getAll({ freeToPlay: true }, function (error, champion) {
// do something with free to play champions
});
Get data about game currently in progress.
Get featured games.
Get recent games by summoner ID.
Get leagues by summoner ID or array of summoner IDs.
Get league entries by summoner ID or array of summoner IDs.
Get leagues by team ID or array of team IDs.
Get league entries by team ID or array of team IDs.
Get challenger tier leagues.
Property type
may contain one of the following values:
- RANKED_SOLO_5X5
- RANKED_TEAM_3X3
- RANKED_TEAM_5X5
Get master tier leagues.
Property type
may contain one of the following values:
- RANKED_SOLO_5X5
- RANKED_TEAM_3X3
- RANKED_TEAM_5X5
Get match by match ID.
Additional options
properties:
- includeTimeline - if true, will include timeline of the match in the results
Get match history by summoner ID or array of summoner IDs.
Additional options
properties:
- championIds - array(or comma-separated list) of champion IDs you want to see in resulting matches
- rankedQueues - array(or comma-separated list) of ranked queues you want to see the results of
- seasons - array(or comma-separated list) of seasons to use for fetching games
- beginTime - begin time to use for fetching games specified as epoch milliseconds
- endTime - end time to use for fetching games specified as epoch milliseconds
- beginIndex - begin index to use for fetching games
- endIndex - end index to use for fetching games
Example:
var options = {
championIds: 412,
rankedQueues: ['RANKED_SOLO_5X5', 'RANKED_TEAM_5X5'],
beginIndex: 0,
endIndex: 10
}; // these options will return 10 ranked 5v5 games containing champion Thresh
lolapi.MatchList.getBySummonerId(71500, options, function (error, matches) {
// got the matches!
});
Get list of champions.
Additional options
properties:
- locale - locale code for returned data (e.g., en_US, es_ES)
- version - data dragon version for returned data
- dataById - if true, the returned data map will use the champions' IDs as the keys
- champData - tags to return additional data. Available tags: all, allytips, altimages, blurb, enemytips, image, info, lore, partype, passive, recommended, skins, spells, stats, tags
Get champion by ID.
Additional options
properties:
- locale - locale code for returned data (e.g., en_US, es_ES)
- version - data dragon version for returned data
- champData - tags to return additional data. Available tags: all, allytips, altimages, blurb, enemytips, image, info, lore, partype, passive, recommended, skins, spells, stats, tags
Get list of items.
Additional options
properties:
- locale - locale code for returned data (e.g., en_US, es_ES)
- version - data dragon version for returned data
- itemListData - tags to return additional data. Available tags: all, colloq, consumeOnFull, consumed, depth, from, gold, groups, hideFromAll, image, inStore, into, maps, requiredChampion, sanitizedDescription, specialRecipe, stacks, stats, tags, tree
Get item by ID.
Additional options
properties:
- locale - locale code for returned data (e.g., en_US, es_ES)
- version - data dragon version for returned data
- itemData - tags to return additional data. Available tags: all, colloq, consumeOnFull, consumed, depth, from, gold, hideFromAll, image, inStore, into, maps, requiredChampion, sanitizedDescription, specialRecipe, stacks, stats, tags
Get list of masteries.
Additional options
properties:
- locale - locale code for returned data (e.g., en_US, es_ES)
- version - data dragon version for returned data
- masteryListData - tags to return additional data. Available tags: all, image, prereq, ranks, sanitizedDescription, tree
Get mastery by ID.
Additional options
properties:
- locale - locale code for returned data (e.g., en_US, es_ES)
- version - data dragon version for returned data
- masteryListData - tags to return additional data. Available tags: all, image, prereq, ranks, sanitizedDescription
Get list of runes.
Additional options
properties:
- locale - locale code for returned data (e.g., en_US, es_ES)
- version - data dragon version for returned data
- runeListData - tags to return additional data. Available tags: all, basic, colloq, consumeOnFull, consumed, depth, from, gold, hideFromAll, image, inStore, into, maps, requiredChampion, sanitizedDescription, specialRecipe, stacks, stats, tags
Get rune by ID.
Additional options
properties:
- locale - locale code for returned data (e.g., en_US, es_ES)
- version - data dragon version for returned data
- runeData - tags to return additional data. Available tags: all, colloq, consumeOnFull, consumed, depth, from, gold, hideFromAll, image, inStore, into, maps, requiredChampion, sanitizedDescription, specialRecipe, stacks, stats, tags
Get list of summoner spells.
Additional options
properties:
- locale - locale code for returned data (e.g., en_US, es_ES)
- version - data dragon version for returned data
- dataById - if true, the returned data map will use the spells' IDs as the keys
- spellData - tags to return additional data. Available tags: all, cooldown, cooldownBurn, cost, costBurn, costType, effect, effectBurn, image, key, leveltip, maxrank, modes, range, rangeBurn, resource, sanitizedDescription, sanitizedTooltip, tooltip, vars
Get summoner spell by ID.
Additional options
properties:
- locale - locale code for returned data (e.g., en_US, es_ES)
- version - data dragon version for returned data
- spellData - tags to return additional data. Available tags: all, cooldown, cooldownBurn, cost, costBurn, costType, effect, effectBurn, image, key, leveltip, maxrank, modes, range, rangeBurn, resource, sanitizedDescription, sanitizedTooltip, tooltip, vars
Get realm data.
Get versions data.
Get ranked stats by summoner ID.
Additional options
properties:
- season - name of the season you want to retrieve stats of(eg. SEASON3 or SEASON4)
Get player stats summaries by summoner ID.
Additional options
properties:
- season - name of the season you want to retrieve stats of(eg. SEASON3 or SEASON4)
Get specific shard status by region.
Get shard list.
Get summoner by ID or list of summoner IDs.
Get summoner by name or list of summoner names.
Get summoner name by ID or list of summoner IDs.
Get summoner runes by ID or list of summoner IDs.
Get summoner masteries by ID or list of summoner IDs.
Get team by ID.
Get team by summoner ID.