Giter Site home page Giter Site logo

leaguejs's Introduction

LeagueJS

This Version is currently no longer maintained. v1.0.0 Rework for Riot API v3 can be found here on npm and here on Github

Join the chat at https://gitter.im/League-JS/Lobby

A Javascript Wrapper for the League of Legends API

How To Use

Use npm to install it from the npm registry by running npm install leagueapi

Put the following in a server.js file.

var LolApi = require('leagueapi');

LolApi.init('XXXXXXXXXXXXXXX', 'na');

LolApi.getChampions(true, function(err, champs) {
    console.log(champs);
});

LolApi.Summoner.getByName('YOLO Swag 5ever', function(err, summoner) {
	if(!err) {
		console.log(summoner);
	}
})

//The wrapper also accepts promises:
LolApi.Summoner.getByName('YOLO Swag 5ever')
.then(function (summoner) {
    console.log(summoner);
});

Run npm install followed by node server.js

Here's the list of methods and their parameters:

[param] means you can pass null values if you don't want to specify the paramater

	LolApi.Init(ApiKey); //Will default to NA
	LolApi.Init(ApiKey, region);

	LolApi.setRateLimit(limitPer10s, limitPer10min);

	LolApi.setEndpoint(newEndpoint);
	LolApi.getEndpoint();
	
	LolApi.getMapNames(callback);

	LolApi.getRegions(callback);

	LolApi.getPlatformId(region, callback);

	LolApi.getQueues(callback);

	LolApi.getChampions([freeToPlay], region, callback);
	LolApi.getChampions([freeToPlay], callback);

	LolApi.getRecentGames(summonerId, region, callback);
	LolApi.getRecentGames(summonerId, callback);

	LolApi.getLeagueData(summonerId, region, callback);
	LolApi.getLeagueData(summonerId, callback);
	
	LolApi.getTeamLeagueData(teamId, region, callback); // Get LeagueData for given Team ID in given region
	LolApi.getTeamLeagueData(teamId, callback); // Get LeagueData for given Team ID
	
	LolApi.getLeagueEntryData(summonerId, region, callback);
	LolApi.getLeagueEntryData(summonerId, callback);

    LolApi.getTeamLeagueEntryData(teamId, region, callback); // Get LeagueData Entry for given Team ID in given region
	LolApi.getTeamLeagueEntryData(teamId, callback); // Get LeagueData Entry for given Team ID

    LolApi.getTeams(summonerId, region, callback);
    LolApi.getTeams(summonerId, callback);

    LolApi.getTeam(teamId, region, callback);
    LolApi.getTeam(teamId, callback);

	LolApi.getShards(callback);
	LolApi.getShardByRegion(callback);

	LolApi.getMatch(matchId, [includeTimeline], region, callback);

	options = {championIds: [1,3,4], rankedQueues: ['RANKED_SOLO_5x5', 'RANKED_TEAM_3x3', 'RANKED_TEAM_5x5'], beginIndex: 1, endIndex: 5};
	LolApi.getMatchHistory(summonerId, [options], region, callback);

	LolApi.getCurrentGame(summonerId, region, callback);

	LolApi.getFeaturedGames(region, callback);

	LolApi.Stats.getPlayerSummary(summonerId, [season], region, callback);
	LolApi.Stats.getPlayerSummary(summonerId, [season], callback);

	LolApi.Stats.getRanked(summonerId, [season], region, callback);
	LolApi.Stats.getRanked(summonerId, [season], callback);

	LolApi.Summoner.getMasteries(summonerId, region, callback);
	LolApi.Summoner.getMasteries(summonerId, callback);

	LolApi.Summoner.getRunes(summonerId, region, callback);
	LolApi.Summoner.getRunes(summonerId, callback);

	LolApi.Summoner.getByID(summonerId, region, callback);
	LolApi.Summoner.getByID(summonerId, callback);

	LolApi.Summoner.getByName(name, region, callback);
	LolApi.Summoner.getByName(name, callback);

	LoLApi.Summoner.listNamesByIDs(ids, region, callback);
	LolApi.Summoner.listNamesByIDs(ids, callback);

	options = {champData: 'allytips,blurb', version : '4.4.3', locale: 'en_US', dataById=true}
	//doesn't show all options
	LolApi.Static.getChampionList(options, region, callback);
	LolApi.Static.getChampionList(options, callback);
	
	options = {champData: 'allytips,blurb', version : '4.4.3', locale: 'en_US', dataById=true}
	//doesn't show all options
	LolApi.Static.getChampionById(champId, options, region, callback);
	LolApi.Static.getChampionById(champId, options, callback);
	
	options = {itemData: 'consumed'}
	//doesn't show all possible options
	LolApi.Static.getItemById(itemId, options, region, callback);
	LolApi.Static.getItemById(itemId, options, callback);
	
	options = {itemListData: 'consumed'}
	LolApi.Static.getItemList(options, region, callback);
	LolApi.Static.getItemList(options, callback);

	LolApi.Static.getMasteryList(options, region, callback);
	LolApi.Static.getMasteryList(options, callback);

	LolApi.Static.getMasteryById(options, region, callback);
	LolApi.Static.getMasteryById(options, callback);

	LolApi.Static.getRealm(region, callback);
	LolApi.Static.getRealm(callback);

	LolApi.Static.getRuneList(options, region, callback);
	LolApi.Static.getRuneById(id, options, callback);

	LolApi.Static.getSummonerSpellList(options, region, callback);
	LolApi.Static.getSummonerSpellById(id, options, callback);

	LolApi.ChampionMastery.getChampions(playerId, region, callback);
	LolApi.ChampionMastery.getChampions(playerId, callback);

	LolApi.ChampionMastery.getChampion(playerId, championId, region, callback);
	LolApi.ChampionMastery.getChampion(playerId, championId, callback);

	LolApi.ChampionMastery.getScore(playerId, region, callback);
	LolApi.ChampionMastery.getScore(playerId, callback);

	LolApi.ChampionMastery.getTopChampions(playerId, count, region, callback);
	LolApi.ChampionMastery.getTopChampions(playerId, count, callback);


    //The following methods are only for enabled tournament api keys:

    LolApi.getMatchForTournament(matchId, tournamentCode, [includeTimeline], region, callback);
    LolApi.getMatchForTournament(matchId, tournamentCode, [includeTimeline], callback);

    LolApi.getMatchIdsByTournament(tournamentCode, region, callback);
    LolApi.getMatchIdsByTournament(tournamentCode, callback);

    LolApi.Tournament.createProvider(region, callbackUrl, callback);

    LolApi.Tournament.createTournament(name, providerId, callback);

    LolApi.Tournament.createCode(tournamentId, count, options, callback);
    LolApi.Tournament.updateCode(tournamentCode, options, callback);
    LolApi.Tournament.getCode(tournamentCode, callback);

    LolApi.Tournament.getLobbyEventsByCode(tournamentCode, callback);

LeagueJS Gulp Commands

Gulp.js is a streaming build system. Thanks to it's simplicity and code-over-configuration we are able to create a simple, efficient and more intuitive build process.

To get started you need to install Gulp.js globally:

  • npm install -g gulp

Available gulp commands and their descriptions:

Run JSLint on all js files:

  • gulp lint

Run BDD tests:

  • gulp test

Run istabul to generate a code coverage report:

  • gulp test-coverage

Run plato to generate a code analysis report:

  • gulp code-report

Runs both istanbul and plato in with one command:

  • gulp reports

Removes both coverage and report directories created by istanbul and plato

  • gulp clean-reports

Sets up a development environment that will listen for code changes, then run JSLint and BDD tests upon saving:

  • gulp dev

leaguejs's People

Contributors

claudiowilson avatar cliffordduke avatar colorfulstan avatar eldorandev avatar ericengineered avatar ferderber avatar frosthaven avatar gitter-badger avatar jhgaylor avatar johnz133 avatar kubuxu avatar passion4code avatar quenting3 avatar souler avatar ssesfahani avatar thirsty-robot avatar tplaindoux avatar un0btanium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leaguejs's Issues

Return values 'undefined'

First of all thank you for creating something useful.

I'm having a problem, when trying to return a value, it defines as undefined, see:

var list = LolApi.getChampions(true, (err, champs) => champs);
console.log(list); //#undefined

getByName seem not work for me

Hi.
I don't know what's wrong, but getByName return an error instead of return the summoner.

LolApi.Summoner.getByName(summonerName, region, function(err, summoner){ if(!err){ // something } else { console.log(err); } }

Error : [Error: Error getting summoner data using name: Error: getaddrinfo ENOTFOUND eu.api.pvp.net eu.api.pvp.net:443]

Thx in advance.

Masteries and Runes possible bug

I seem to have a problem retrieving the masteries and runes after the last update.
I tried all the "LolApi.Summoner..." functions and for some reason getMasteries() and getRunes() does not work for me. They return undefined as result and null as error.

Im using the 'eune' server.

Typo in League.init

Just a typo that makes the usage of any other region than the default impossible :

League.init = function(key, region) {
                _authKey = key;
                if(region) _region =  + '/' + region;
}

You just need to remove the first '+' on the last line, else the crafted URL will be something like this http://prod.api.pvp.net/api/lolNaN/euw/.

(RIOT API changes) New Matchlist parameters - integrate range splitting with background requests

Watch how
https://discussion.developer.riotgames.com/questions/3155/why-pagination-is-a-problem.html
evolves.

Currently there is a new enforced pagination on the matchlist endpoint that might cause requests to fail bc they

a) have a too high range (>=100) for their beginIndex/endIndex done in Colorfulstan/LeagueJS@d97c533
b) have a too high range (> 1week) for their startTime/endTime

If a higher range is given, the Endpoint methods should ideally split the ranges and execute the neccessary requests in the background I think

Add possibility for array as Data option where possible

Currently methods that accept a parameter for which Data is returned by RIOT (like getItemList, getItemById, ...) only accept a string for the respective option. But RIOT Api allows for multiple options.

Methods should be updated acchordingly. I did it for two of them Im currently using:
4f0978f

Not all data being parsed(?)

Hi, I am new with this stuff so maybe I just simply missed something, but when i use this code:

var options = {champData: 'all', version : '', locale: 'en_US', dataById : true};
LolApi.Static.getChampionById(1, options, function(err, champion) {
    if(!err) {
        console.log(champion.spells);
    }
    else if(err) {
        console.log(err);
    }
});

I receive this in my console (ill only paste a bit of it since it's rather large):

name: 'Summon: Tibbers',
19:43:44 web.1  |     description: 'Annie wills her bear Tibbers to life, dealing damage to units in the area. Tibbers can attack and also burns enemies that stand near him.',
19:43:44 web.1  |     sanitizedDescription: 'Annie wills her bear Tibbers to life, dealing damage to units in the area. Tibbers can attack and also burns enemies that stand near him.',
19:43:44 web.1  |     tooltip: 'Tibbers appears in a burst of flame dealing {{ e1 }} <span class="color99FF99">(+{{ a1 }})</span> magic damage to enemies in the target area.<br><br>For the next {{ e6 }} seconds, Tibbers chases down enemies and deals {{ e4 }}<span class="color99FF99"> (+{{ a2 }})</span> magic damage each second to nearby foes.<br><br><span class="color99FF99">Tibbers can be controlled by holding the alt key and using the right mouse button or by reactivating this ability.</span>',
19:43:44 web.1  |     sanitizedTooltip: 'Tibbers appears in a burst of flame dealing {{ e1 }} (+{{ a1 }}) magic damage to enemies in the target area. For the next {{ e6 }} seconds, Tibbers chases down enemies and deals {{ e4 }} (+{{ a2 }}) magic damage each second to nearby foes. Tibbers can be controlled by holding the alt key and using the right mouse button or by reactivating this ability.',
19:43:44 web.1  |     leveltip: { label: [Object], effect: [Object] },
19:43:44 web.1  |     image: 
19:43:44 web.1  |      { full: 'InfernalGuardian.png',
19:43:44 web.1  |        sprite: 'spell1.png',
19:43:44 web.1  |        group: 'spell',
19:43:44 web.1  |        x: 192,
19:43:44 web.1  |        y: 0,
19:43:44 web.1  |        w: 48,
19:43:44 web.1  |        h: 48 },
19:43:44 web.1  |     resource: '{{ cost }} Mana',
19:43:44 web.1  |     maxrank: 3,
19:43:44 web.1  |     cost: [ 100, 100, 100 ],
19:43:44 web.1  |     costType: 'Mana',
19:43:44 web.1  |     costBurn: '100',
19:43:44 web.1  |     cooldown: [ 120, 100, 80 ],
19:43:44 web.1  |     cooldownBurn: '120/100/80',
19:43:44 web.1  |     effect: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
19:43:44 web.1  |     effectBurn: 
19:43:44 web.1  |      [ '175/300/425',
19:43:44 web.1  |        '1200/2100/3000',
19:43:44 web.1  |        '80/105/130',
19:43:44 web.1  |        '35',
19:43:44 web.1  |        '30/50/70',
19:43:44 web.1  |        '45' ],
19:43:44 web.1  |     vars: [ [Object], [Object] ],
19:43:44 web.1  |     range: [ 600, 600, 600 ],
19:43:44 web.1  |     rangeBurn: '600',
19:43:44 web.1  |     key: 'InfernalGuardian',
19:43:44 web.1  |     altimages: [ [Object] ] } ]

So my problem is.. How do I get information out of these "Objects" to be displayed in the console?

Just to clarify, I am receiving this:

vars: [ [Object], [Object] ],

And I should receive this:

         "vars": [
            {
               "link": "spelldamage",
               "coeff": [0.8],
               "key": "a1"
            },
            {
               "link": "spelldamage",
               "coeff": [0.2],
               "key": "a2"
            }
         ],

[rework] add method rate limiting

Besides the App-wide rate-limiting Riot now added method-limiting too which in the current (reworked) implementation is not considered.

Info from 2017/Jul/10

500 requests / 10 sec:
/api/lol/{region}/v2.2/match/{matchId}
/lol/match/v3/matches/{matchId}
/lol/match/v3/timelines/by-match/{matchId}

1000 requests / 10 sec:
/api/lol/{region}/v2.2/matchlist/by-summoner/{summonerId}
/lol/match/v3/matchlists/by-account/{accountId}
/lol/match/v3/matchlists/by-account/{accountId}/recent(bearbeitet)

My initial thought for solving this would be to add this information to the Config file and create a new Ratelimiter for the respective endpoints, scheduling the call to ApiRequest.executing, where then in turn the actual request will be scheduled to fit the App-rate limit.

Reference to general rate limiting infos

API requests occur in parallel instead of simultaneously

This might not be a bug (perhaps it's intentional) but requests made through leagueJS are in parallel. The following code demonstrates how it returns them sequentially. It takes roughly 750 ms per match request (7500 ms total) before this code will finish, but with BlueBird requests I was able to retrieve data from these 10 games in 750 ms total.

'use strict';

var LolApi = require("leagueapi");
LolApi.init("XXXXXXXXXXXXXXXX", "na");

var region = "na";
var match_ids = [2363807729,2363820701,2363800381,
                2363736440,2363678033,2362867453,
                2362834895,2362663001, 2362488529,
                2362481597];

function getMatch(match_id, x){
  return LolApi.getMatch(match_id,true,region)
  .then(function(match){
    console.log("Match", x,  "Returned");
    return match;
  }).catch(function(err){
    console.log("Match", x,  "Failed:", err);
    getMatch(match_id, x);
  });
}

function promiseAll(){
  console.time("Time to Get Matches");
  var match_promises = [];
  for(var x in match_ids){
    match_promises.push(getMatch(match_ids[x],x));
  }
  Promise.all(match_promises).then(function(data){
    console.log("All Matches Finished");
    console.timeEnd("Time to Get Matches");
  }).catch(function(err){
    console.log(err);
  });
}

function main(){
  promiseAll();
}

main();

Masteries and Runes wraps all pages inside an object with the User's ID as the key

So the 1.4 Summoner endpoints for masteries and runes now wrap pages with an object using their ID as the key, I think this was done to allow multiple Summoner results in one query. Results now look like this:

{
  "11053638": {
    "summonerId": 11053638,
    "pages": [
      {
        "id": 8342080,
        "name": "Rune Page 1",
        "current": true,
        "slots": [
          {
            "runeSlotId": 1,
            "runeId": 5273
          },
          ]
      }
      ]
   }
}

However your makeRequest utility function is unable to support two levels of keys

Rate limit should be per-region, not global

From developer.riotgames.com:

"Note that rate limits are enforced per region. For example, with the above rate limit, you could make 10 requests every 10 seconds to both NA and EUW endpoints simultaneously."

It would be great if this lib could support per-region rate limits, instead of a global limit.

RIOT API V3 - V1/2 endpoints deprecated on July 24th

RIOT released their V3 of the league api recently and there will be a deprecation period of 90 days starting soon until the old endpoints will not be working anymore.

https://discussion.developer.riotgames.com/articles/652/riot-games-api-v3.html

I will update my Fork for the endpoints I use and might also look into the general endpoint construction about half way through the deprecation period (around end of May I assume I will have the time to spare)

Typos

These typos caused errors when I ran 'node server.js'.

Typo in demo server.js in "How To Use", line 5
says: chamnps
should say: champs

Typo in lolapi.js, line 143
says: freetoPlay [last one in the line]
should say: freeToPlay

Summoners might have NA as platformId!?

https://developer.riotgames.com/regional-endpoints.html#

  • Note: The NA region has two associated platform values - NA and NA1. Older summoners will have the NA platform associated with their account, while newer summoners will have the NA1 platform associated with their account.

If I understand correctly, it might be possible to get NA as platformId from some Summoner Information.
Since all Endpoints in the current state of the rework accept both, platformId and region, this should not be a problem but should be tested anyways to be sure.

Seems to be an issue with getPlayerSummary()

events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer as oncomplete

is being returned from:

LolApi.init(leagueKey);
LolApi.Stats.getPlayerSummary(sumId, 2015, region, function(error, out) {
...
}

Which I found quite interesting. Dug through the api, I couldn't find the cause – However, I don't think it's an issue with my coding, as even an empty api call here returns that error. (sumId, region are defined above as parameters.) I saw that in util.js getValidSeasonParam used ===, so I tried both 2015 as an integer and a string – neither worked. I even tried it as an array, as the README suggested.

Current state: pending

Tengo un problema al pedir los datos de la partida en vivo de un invocador, cuando pido la información recibo: { state: 'pending' } dejo una captura del código, es bastante simple pero debería funcionar .

p1
p2

Imeplement optional rate limiter

Include a rate limiter so that we gracefully handle hitting the rate limit. This should be optional to give clients a way to do it for themselves

getaddrinfo uncaught exception

When network is unreachable LeagueJs throw exception instead of returning it in callback fn. I meet this issue during the network downtime, it crashes node instead of some kind of graceful degradation.
Fix is very easy - handling REQUEST error event.

Error getting match 429

Hi all, when I try to query for match timeline data I sometimes get error 429:

ERROR: ERROR GETTING MATCH: 429 429

Sometimes it even happens on the first try, sometimes after 2-3 tries, basically it is completely random.

I do setup rate limit when initializing the leaguejs client:

LolApi.init(config.lolApiKey, 'na');
LolApi.setRateLimit(10, 500); 

Isn't the client shall ratelimit me and not let me get 429 errors? also why sometimes I get the 429 error on my first try after 60 minutes of riot api inactivity?

add npmignore

We need to specify which files are dev and which files are for npm.

{State: 'pending'} issue

I have a problem when ordering data of a live game Summoner, when I ask for the information receipt: {state: 'pending'} leave a screenshot of the code is pretty simple but it should work.

p1
p2

getMatchHistory return 403: forbidden

other methods work fine, just getMatchHistory returns 403:forbidden, here is the code:

LolApi.getMatchHistory 40200522, null, (e, matchlist) ->
if e?
console.log e
return

Regions & versions.

Hi!

It seems that there is an issue with the region handling. Even when the lib is initialized with 'euw' (for example), it will look in 'na' as defaulted.
Sometimes, stating the regions explicitly in the call will make it work, sometimes not.

This will correct the call:

lol.Summoner.getByID(summonerId, 'euw', callback);

But this will not:

lol.getRecentGames(summonerId, 'euw', callback);

I don't think the issue is coming from me, as it was working before I update the lib! I lack the time to look more into it right now, but I'll do it as soon as possible.

Also there are several versions that are out of date:

        championUrl = '/v1.1/champion',
        gameUrl = '/v1.3/game/by-summoner',
        leagueUrl = '/v2.3/league/by-summoner',
        statsUrl = '/v1.2/stats/by-summoner',
        summonerUrl = '/v1.3/summoner',
        teamUrl = '/v2.2/team/by-summoner';

Passing variable by LolApi.Summoner.getByName

Hey fellas, [not really an issue]
can you tell me what should I do to pass and change my response variable by LolApi.Summoner.getByName. I am not really sure what's wrong.


var myresponse = "";
LolApi.Summoner.getByName(summonerId, region, function(err, summoner) {
    .. 
    myresponse = "Name" 
    ..
}
log(myresponse) // not changed

I tried running through the code but there are stuff I am not familiar with.

Region error not catched

Hey,

How would you suggest catching non-existing regions? For example, LolApi.Summoner.getByNamecatches a non-existing summoner name but not region. I get:
Error: getaddrinfo ENOTFOUND nas.api.pvp.net nas.api.pvp.net:443

And I can't catch it with if (err). It just breaks.

I can of course check the input region on server side to ensure that the region exists, but having an error thrown here would simplify things.

Cheers,
tedcurrent

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.