Kindred
Kindred is a thin Node.js wrapper (with an optional rate limiter) on top of Riot Games API for League of Legends.
Table of Contents
Core Features
- All endpoints covered but one (get summoner by accountIDs).
- Basic rate-limiting that is enforced per region.
- Retries on 429 and >= 500 (should it just be 500?).
- Tells you what parameters you can pass in when you make a parameter-related error.
Hopefully there aren't too many bugs! I'm a noob after all, so use this library at your own risk. I'm currently working on adding caching and fully support promises (it might be a bit buggy atm).
Philosophy
My goal is to make a wrapper that is simple, sensible, and consistent. This project is heavily inspired by psuedonym117's Python wrapper. Look at the Usage Section to see what I mean.
This is my first try at making an API wrapper. I am open to any advice and help!
March 28, 2017
I'm pretty proud of the end result. The rate limiting isn't the best, but it does work and is enforced per region! Also, the method names are kinda iffy (minor inconsistencies), but it works really well for my other project and for when I need a quick script. I'll try to improve this library over the next few weeks.
Installation
yarn add kindred-api
// or npm install kindred-api
Endpoints Covered
Make sure to check the official Riot Documentation to see what query parameters you can pass in to each endpoint (through the options parameter)!
Note: All region
parameters are OPTIONAL. All options
parameters are OPTIONAL unless stated otherwise.
Champion
docs
- /api/lol/{region}/v1.2/champion
- Retrieve all champions. (REST)
- getChamps({ region, id (int), options (object) }, cb)
- /api/lol/{region}/v1.2/champion/{id}
- Retrieve champion by ID. (REST)
- getChamp({ region, id/championID (int) }, cb)
Champion Mastery
docs
- /championmastery/location/{location}/player/{playerId}/champion/{championId}
- Get a champion mastery by player id and champion id. Response code 204 means there were no masteries found for given player id or player id and champion id combination. (RPC)
- getChampMastery({ region = this.defaultRegion, playerID (int), championID (int), options (object) }, cb)
- /championmastery/location/{location}/player/{playerId}/champions
- Get all champion mastery entries sorted by number of champion points descending. (RPC)
- getChampMasteries({ region = this.defaultRegion, id/summonerID/playerID (int), name (string), options (object) }, cb)
- /championmastery/location/{location}/player/{playerId}/score
- Get a player's total champion mastery score, which is sum of individual champion mastery levels. (RPC)
- getTotalChampMasteryScore({ region = this.defaultRegion, id/summonerID/playerID (int), name (string), options (object) }, cb)
- /championmastery/location/{location}/player/{playerId}/topchampions
- Get specified number of top champion mastery entries sorted by number of champion points descending. (RPC)
- getTopChamps({ region = this.defaultRegion, id/summonerID/playerID (int), name (string), options (object) }, cb)
Current Game
docs
- /observer-mode/rest/consumer/getSpectatorGameInfo/{platformId}/{summonerId}
- Get current game information for the given summoner ID. (REST)
- getCurrentGame({ region = this.defaultRegion, id/summonerID/playerID (int), name (str) }, cb)
Featured Games
docs
- /observer-mode/rest/featured
- Get list of featured games. (REST)
- getFeaturedGames({ region }, cb)
Game
docs
- /api/lol/{region}/v1.3/game/by-summoner/{summonerId}/recent
- Get recent games by summoner ID. (REST)
- getRecentGames({ region, id (int), name (str) }, cb)
League
docs
- /api/lol/{region}/v2.5/league/by-summoner/{summonerIds}
- Get leagues mapped by summoner ID for a given list of summoner IDs. (REST)
- getLeagues({ region, ids/summonerIDs/playerIDs ([int]/int), id/summonerID/player/ID (int), names ([str]/str), name (str) }, cb)
- /api/lol/{region}/v2.5/league/by-summoner/{summonerIds}/entry
- Get league entries mapped by summoner ID for a given list of summoner IDs. (REST)
- getLeagueEntries({ region, ids/summonerIDs/playerIDs ([int]/int), id/summonerID/playerID (int), names ([str]/str), name (str) }, cb)
- /api/lol/{region}/v2.5/league/challenger
- Get challenger tier leagues. (REST)
- getChallengers({ region, options = { type: 'RANKED_SOLO_5x5' } }, cb)
- /api/lol/{region}/v2.5/league/master
- Get master tier leagues. (REST)
- getMasters({ region, options = { type: 'RANKED_SOLO_5x5' } }, cb)
LoL Static Data
docs
- /api/lol/static-data/{region}/v1.2/champion
- Retrieves champion list. (REST)
- getChampionList({ region, options (object) }, cb)
- /api/lol/static-data/{region}/v1.2/champion/{id}
- Retrieves a champion by its id. (REST)
- getChampion({ region, id/championID (int), options (object) }, cb)
- /api/lol/static-data/{region}/v1.2/item
- Retrieves item list. (REST)
- getItems({ region, options (object) }, cb)
- /api/lol/static-data/{region}/v1.2/item/{id}
- Get master tier leagues. (REST)
- getItem({ region, id/itemID (int), options (object) }, cb)
- /api/lol/static-data/{region}/v1.2/language-strings
- Retrieve language strings data. (REST)
- getLanguageStrings({ region, options (object) }, cb)
- /api/lol/static-data/{region}/v1.2/languages
- Retrieve supported languages data. (REST)
- getLanguages({ region }, cb)
- /api/lol/static-data/{region}/v1.2/map
- Retrieve map data. (REST)
- getMap({ region, options (object) }, cb)
- /api/lol/static-data/{region}/v1.2/mastery
- Retrieve mastery list. (REST)
- getMasteryList({ region, options (object) }, cb)
- /api/lol/static-data/{region}/v1.2/mastery/{id}
- Retrieves mastery item by its unique id. (REST)
- getMastery({ region, id/masteryID (int), options (object) }, cb)
- /api/lol/static-data/{region}/v1.2/realm
- Retrieve realm data. (REST)
- getRealmData({ region }, cb)
- /api/lol/static-data/{region}/v1.2/rune
- Retrieves rune list. (REST)
- getRuneList({ region, options (object) }, cb)
- /api/lol/static-data/{region}/v1.2/rune/{id}
- Retrieves rune by its unique id. (REST)
- getRune({ region, id/runeID (int), options (object) }, cb)
- /api/lol/static-data/{region}/v1.2/summoner-spell
- Retrieves summoner spell list. (REST)
- getSummonerSpells({ region, options (object) }, cb)
- /api/lol/static-data/{region}/v1.2/summoner-spell/{id}
- Retrieves summoner spell by its unique id. (REST)
- getSummonerSpell({ region, id/spellID/summonerSpellID (int), options (object) }, cb)
- /api/lol/static-data/{region}/v1.2/versions
- Retrieve version data. (REST)
- getVersionData({ region, options (object) }, cb)
LoL Status
docs
- /lol/status/v1/shard
- Get shard status. Returns the data available on the status.leagueoflegends.com website for the given region. (REST)
- getShardStatus({ region }, cb)
- /lol/status/v1/shards
- Get shard list. (REST)
- getShardList({ region }, cb)
Match
docs
- /api/lol/{region}/v2.2/match/{matchId}
- Retrieve match by match ID. (REST)
- getMatch({ region, id/matchID (int), options = { includeTimeline: true } }, cb)
Matchlist
docs
- /api/lol/{region}/v2.2/matchlist/by-summoner/{summonerId}
- Retrieve match list by match ID. (REST)
- getMatchList({ region, id/summonerID/playerID (int), name (str), options = { rankedQueues: 'RANKED_SOLO_5x5' } }, cb)
Runes Masteries
docs
- /api/lol/{region}/v1.4/summoner/{summonerIds}/masteries
- Get mastery pages mapped by summoner ID for a given list of summoner IDs. (REST)
- getMasteries({ region, ids/summonerIDs/playerIDs ([int]/int), id/summonerID/playerID (int), names ([str]/str), name (str)}, cb)
- /api/lol/{region}/v1.4/summoner/{summonerIds}/runes
- Retrieve match list by match ID. (REST)
- getRunes({ region, ids/summonerIDs/playerIDs ([int]/int), id/summonerID/playerID (int), names ([str]/str), name (str) }, cb)
Stats
docs
- /api/lol/{region}/v1.3/stats/by-summoner/{summonerId}/ranked
- Get ranked stats by summoner ID. (REST)
- getRankedStats({ region, id/summonerID/playerID (int), name (str), options (object) }, cb)
- /api/lol/{region}/v1.3/stats/by-summoner/{summonerId}/summary
- Get player stats summaries by summoner ID. (REST)
- getStatsSummary({ region, id/summonerID/playerID (int), name (str), options (object) }, cb)
Summoner
docs
- /api/lol/{region}/v1.4/summoner/by-account/{accountIds}
- Get a list of summoners by account ids (RPC).
- N/A
- /api/lol/{region}/v1.4/summoner/by-name/{summonerNames}
- Get a list of summoners by summoner names. (RPC)
- getSummoners({ region, ids/summonerIDs/playerIDs ([int]/int), id (int), names ([str]/ str), name (str) }, cb)
- getSummoner({ region, id (int), name (str) }, cb)
- /api/lol/{region}/v1.4/summoner/{summonerIds}
- Get challenger tier leagues. (REST)
- getSummoners({ region, ids/summonerIDs/playerIDs ([int]/int), id (int), names ([str]/ str), name (str) }, cb)
- getSummoner({ region, id (int), name (str) }, cb)
- /api/lol/{region}/v1.4/summoner/{summonerIds}/name
- Get master tier leagues. (REST)
- getSummonerNames({ region, ids/summonerIDs/playerIDs ([int]/int), id/summonerID/playerID (int) }, cb)
- getSummonerName({ region, id/summonerID/playerID (int) }, cb)
Usage
var KindredAPI = require('kindred-api')
require('dotenv').config()
var RIOT_API_KEY = process.env.RIOT_API_KEY
var REGIONS = KindredAPI.REGIONS
var k = new KindredAPI.Kindred({
key: RIOT_API_KEY,
defaultRegion: REGIONS.NORTH_AMERICA,
debug: true,
limits: [ [10, 10], [500, 600] ]
})
function rprint(err, data) { console.log(data) }
k.getSummoner(rprint)
k.getSummoner(rprint)
k.getTopChamps(rprint)
k.getChampMastery(rprint)
k.getChallengers(rprint)
k.getRuneList(rprint)
k.getSummoner({ id: 354959 }, rprint)
k.getSummoner({ summonerID: 354959 }, rprint)
k.getSummoner({ summonerID: 354959 })
.then(json => console.log(json))
.catch(err => console.log(err))
k.getSummoners({ summonerIDs: [354959, 21542029] }, rprint)
k.getMatch({ id: 2459973154 }, rprint)
k.getMatch({ matchID: 2459973154 }, rprint)
var names = ['beautifulkorean', 'c9gun', 'caaaaaaaaarIa']
k.getSummoners({ names: names }, rprint)
k.getSummoners({ names: 'caaaaaaaaaria' }, rprint)
k.getSummoners({ name: 'caaaaaaaaaria' }, rprint)
var options = { name: 'sktt1peanut', region: REGIONS.KOREA }
k.getSummoner(options, rprint)
k.setRegion(REGIONS.KOREA)
var fakerIgn = { name: 'hide on bush' }
var fakerId
k.getSummoner(fakerIgn, function (err, data) {
fakerId = data[fakerIgn.name.replace(/\s/g, '').toLowerCase()].id
console.log('fakerId:', fakerId)
})
k.setRegion(REGIONS.NORTH_AMERICA)
k.getRunes({ ids: [354959, 21542029] }, rprint)
k.getRunes({ id: 354959 }, rprint)
k.getRunes({ ids: 354959 }, rprint)
k.getRunes({ id: 354959 })
.then(json => console.log(json))
.catch(err => console.error(err))
var names2 = ['Richelle', 'Grigne']
k.getSummoners({ names: names2 }, function (err, data) {
var args = []
for (var name of names2)
args.push(data[name.replace(/\s/g, '').toLowerCase()].id)
k.getRunes({ ids: args }, rprint)
})
k.getRunes({ names: ['Richelle', 'Grigne'] }, rprint)
k.getRunes({ name: 'Richelle' }, rprint)
k.getRecentGames({ name: 'Richelle' }, rprint)
k.getLeagues({ names: ['Richelle', 'Grigne'] }, rprint)
k.getCurrentGame({ name: 'Fràe', region: REGIONS.OCEANIA }, rprint)
var ctzName = 'contractz'
k.getSummoner({ name: ctzName })
.then(json => k.getMasteries({ id: json[ctzName].id }))
.then(json => console.log(json))
k.getChallengers({ region: 'na' }, rprint)
k.getChallengers({ region: 'na', options: {
type: 'RANKED_FLEX_SR'
}}, rprint)
k.getMatch({ id: 2459973154 }, rprint)
k.getMatch({ id: 2459973154, options: { includeTimeline: false } }, rprint)
var name = 'caaaaaaaaaria'
k.getSummoners({ region: 'na', names: name }, function (err, data) {
if (data) {
k.getMatchList({ region: 'na', id: data[name].id, options: {
rankedQueues: ['RANKED_SOLO_5x5', 'RANKED_FLEX_SR'].join(),
championIds: '67'
} }, rprint)
}
})
var furyMasteryId = 6111
k.getMastery({ id: furyMasteryId }, rprint)
var msRuneId = 10002
k.getRune({ id: msRuneId }, rprint)
Contributing and Issues
Feel free to make a PR regarding anything (even the smallest typo or inconsistency).
There are a few inconsistencies and weird things within this libary that I don't know how to address since this is my first API wrapper and I'm still quite a big newbie.
For example, the two methods getChamp() and getChampion() are actually different.
getChamp() targets the champ endpoint
getChampion() targets the static endpoint
I didn't want to attach getChampion() with 'static' in any way or form since I thought it looked kind of annoying because then I would want to attach static to the other static methods as well (maybe that's better?).
Right now, the code is also quite messy and there is a lot of repeated code. Function definitions are quite long because I include many aliases as well. I haven't thought of an elegant way to make a magic function that manages to work for every single endpoint request yet.
Any help and/or advice is appreciated!