Legends is a small (~8KB minified) League of Legends API Library for Node.js and browsers. It based on promises, making it very fast and robust. The full Riot API is available and it also includes human readable names for maps and queues.
Install the NPM module:
$ npm install legends
Then require and use:
var legends = require("legends")("MY_SECRET_API_KEY", "na");
Include dist/legends.js
or dist/legends.min.js
on your page:
<script type="text/javascript" src="legends.min.js"></script>
And use:
var legends = Legends("MY_SECRET_API_KEY", "na");
NOTE: Using this library in the browser will require you to reveal your API key to end users. This is not reccomended for obvious reasons. Check out https://developer.riotgames.com/best-practices for best practices with the API.
This example uses traditional callbacks to get a summoner's ranked stats knowing only their username.
var legends = Legends("MY_SECRET_API_KEY", "na");
legends.getSummonerByName("meteos", function(err, data) {
if (err != null) return console.error(err);
legends.getRankedStats(data.id, function(err, stats) {
if (err != null) console.error(err);
else console.log(stats);
});
});
This can also be rewritten using promises.
var legends = Legends("MY_SECRET_API_KEY", "na");
legends.getSummonerByName("meteos")
.then(function(data) { return legends.getRankedStats(data.id); })
.then(function(data) {
console.log(data);
}, function(error) {
console.error(error);
});
Creates a new Legends instance. API_KEY
is your secret api key given to you by Riot. Go to https://developer.riotgames.com/ to obtain a key. REGION
is any valid region code: na
, euw
, eune
, br
, or tr
. A Legend instance can also be created without using the new
keyword.
Makes a request to the Roit API. OPTIONS
is a dictionary with any of the fields listed below. CALLBACK
is an optional function that is called with two arguments, error
and data
. Returns a promise
. This method is useful for making custom API requests.
method
: Url method, appended to the base API url.region
: A valid LoL region code:na
,euw
,eune
,br
, ortr
.version
: API version. Generally1.1
,1.2
,2.1
, or2.2
.key
: API Key to be prepended to the url query.params
: A dictionary of additional url query parameters.extract
: The key to extract from the returned data.
A dictionary pairing queue ids to human readable names.
A dictionary pairing map ids to human readable names and notes.
An array of valid LoL region codes.
A shortcut for Legends.request
. Defaults the options key
and region
to those provided to the instance when it was created.
Retrieves the list of champions. FREE_TO_PLAY
is a boolean. https://developer.riotgames.com/api/methods#!/311/1059
Retrieves information on the last ten games played. https://developer.riotgames.com/api/methods#!/313/1061
Retrieves leagues data for summoner, including leagues for all of summoner's teams. https://developer.riotgames.com/api/methods#!/307/1055
Retrieves player stats summaries. https://developer.riotgames.com/api/methods#!/317/1075
Retrieves player ranked stats. https://developer.riotgames.com/api/methods#!/317/1074
Retrieves basic summoner info by id. https://developer.riotgames.com/api/methods#!/315/1069
Retrieves basic summoner info by name. https://developer.riotgames.com/api/methods#!/315/1067
Retrieves player runes pages. https://developer.riotgames.com/api/methods#!/315/1070
Retrieves player mastery pages. https://developer.riotgames.com/api/methods#!/315/1071
Retrieves summoners' names by list of ids. Ids can be passed as seperate arguments, as an array of ids, or a combination of the two. Riot limits 40 summoner ids to one request. If more than 40 ids are passed, the method will automatically split it into multiple calls. https://developer.riotgames.com/api/methods#!/315/1068
Retrieves a summoner's teams. https://developer.riotgames.com/api/methods#!/310/1058
This product is not endorsed, certified or otherwise approved in any way by Riot Games, Inc. or any of its affiliates.