├── .npmignore ├── .gitignore ├── .travis.yml ├── .jshintrc ├── LICENSE ├── package.json ├── lib ├── rateLimiter.js ├── util.js └── lolapi.js ├── gulpfile.js ├── README.md └── test └── leagueApiSpec.js /.npmignore: -------------------------------------------------------------------------------- 1 | app.js 2 | .travis.yml 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.log 3 | *.js.html 4 | pids 5 | logs 6 | results 7 | coverage 8 | report 9 | .idea 10 | .DS_Store 11 | npm-debug.log 12 | node_modules -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "5" 4 | - "5.1" 5 | before_script: 6 | - npm install -g gulp 7 | compiler: clang-3.6 8 | env: 9 | - CXX=g++4.8 10 | addons: 11 | apt: 12 | sources: 13 | - ubuntu-tolchain-r-test 14 | packages: 15 | - g++4.8 -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "bitwise":true, 3 | "camelcase":true, 4 | "curly":true, 5 | "eqeqeq":true, 6 | "forin":true, 7 | "immed":true, 8 | "latedef":true, 9 | "newcap":true, 10 | "noarg":true, 11 | "noempty":true, 12 | "nonew":true, 13 | "plusplus":false, 14 | "regexp":true, 15 | "undef":true, 16 | "unused":true, 17 | "strict":true, 18 | "trailing":true, 19 | "indent":4, 20 | "quotmark":"single", 21 | "maxcomplexity":10, 22 | "maxlen":120, 23 | "node":true, 24 | "browser":true, 25 | "jquery": true, 26 | "devel": true, 27 | "white":false, 28 | "laxcomma": true, 29 | "onevar": true 30 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2010, 2011, 2012, 2013. All rights reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to 5 | deal in the Software without restriction, including without limitation the 6 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | IN THE SOFTWARE. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "leagueapi", 3 | "version": "0.4.21", 4 | "description": "Wrapper for the League of Legends API", 5 | "keywords": [ 6 | "league", 7 | "legends", 8 | "wrapper", 9 | "api", 10 | "client" 11 | ], 12 | "author": { 13 | "name": "Claudio Wilson", 14 | "email": "claudiowilson@utexas.edu" 15 | }, 16 | "scripts":{ 17 | "test": "gulp test" 18 | }, 19 | "main": "lib/lolapi.js", 20 | "repository": { 21 | "type": "git", 22 | "url": "https://github.com/claudiowilson/LeagueJS" 23 | }, 24 | "dependencies": { 25 | "html": "latest", 26 | "q": "~1.2.0" 27 | }, 28 | "devDependencies": { 29 | "sinon": "latest", 30 | "mocha": "latest", 31 | "should": "latest", 32 | "gulp": "~3.4.0", 33 | "gulp-jshint": "~1.3.4", 34 | "gulp-mocha": "~0.4.1", 35 | "gulp-istanbul": "~0.1.0", 36 | "gulp-clean": "~0.2.4", 37 | "gulp-exec": "~1.0.4", 38 | "gulp-plato": "~0.1.1" 39 | }, 40 | "readmeFilename": "README.md", 41 | "bugs": { 42 | "url": "https://github.com/claudiowilson/LeagueJS/issues" 43 | }, 44 | "homepage": "https://github.com/claudiowilson/LeagueJS", 45 | "_id": "leagueapi@0.4.3", 46 | "_shasum": "7f318bf26f72e5c478ba48ed8b9e99a11eafdd09", 47 | "_from": "leagueapi@0.4.3", 48 | "_resolved": "https://registry.npmjs.org/leagueapi/-/leagueapi-0.4.3.tgz" 49 | } 50 | -------------------------------------------------------------------------------- /lib/rateLimiter.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var RateLimiter = (function() { 4 | var RateLimiter = function(maxOps, interval, allowBursts) { 5 | this._maxRate = allowBursts ? maxOps : maxOps / interval; 6 | this._interval = interval; 7 | this._allowBursts = allowBursts; 8 | 9 | this._numOps = 0; 10 | this._start = new Date().getTime(); 11 | this._queue = []; 12 | }; 13 | 14 | RateLimiter.prototype.schedule = function(fn) { 15 | var that = this, 16 | rate = 0, 17 | now = new Date().getTime(), 18 | elapsed = now - this._start; 19 | 20 | if (elapsed > this._interval) { 21 | this._numOps = 0; 22 | this._start = now; 23 | } 24 | 25 | rate = this._numOps / (this._allowBursts ? 1 : elapsed); 26 | 27 | if (rate < this._maxRate) { 28 | if (this._queue.length === 0) { 29 | this._numOps++; 30 | fn(); 31 | } else { 32 | if (fn) { 33 | this._queue.push(fn); 34 | } 35 | this._numOps++; 36 | this._queue.shift()(); 37 | } 38 | } else { 39 | if (fn){ 40 | this._queue.push(fn); 41 | } 42 | 43 | setTimeout(function() { 44 | that.schedule(); 45 | }, 1 / this._maxRate); 46 | } 47 | }; 48 | 49 | return RateLimiter; 50 | })(); 51 | 52 | module.exports = RateLimiter; -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | /*global require*/ 2 | 3 | (function () { 4 | 'use strict'; 5 | 6 | var gulp = require('gulp'), 7 | jshint = require('gulp-jshint'), 8 | mocha = require('gulp-mocha'), 9 | istanbul = require('gulp-istanbul'), 10 | clean = require('gulp-clean'), 11 | exec = require('gulp-exec'), 12 | plato = require('gulp-plato'); 13 | 14 | gulp.task('lint', function () { 15 | gulp.src(['./lib/*', './test/*', './gulpfile.js']) 16 | .pipe(jshint('.jshintrc')) 17 | .pipe(jshint.reporter('default')); 18 | }); 19 | 20 | gulp.task('istanbul', function (callback) { 21 | gulp.src('./lib/*.js') 22 | .pipe(istanbul()) 23 | .on('end', callback); 24 | }); 25 | 26 | gulp.task('test', function () { 27 | gulp.src('./test/*.js').pipe(mocha({ 28 | reporter: 'spec', 29 | bail: true, 30 | ui: 'bdd' 31 | })); 32 | }); 33 | 34 | gulp.task('test-coverage', function () { 35 | gulp.run('istanbul', function () { 36 | gulp.src('./test/*.js') 37 | .pipe(mocha()) 38 | .pipe(istanbul.writeReports()) 39 | .pipe(exec('echo Coverage has been calculated. See coverage directory for details.')); 40 | }); 41 | }); 42 | 43 | gulp.task('code-report', function () { 44 | gulp.src('./lib/*.js') 45 | .pipe(plato('./report')) 46 | .pipe(exec('echo The code report has been generated. See report directory for details.')); 47 | }); 48 | 49 | gulp.task('reports', function () { 50 | gulp.run('test-coverage', 'code-report'); 51 | }); 52 | 53 | gulp.task('clean-reports', function () { 54 | gulp.src(['./coverage', './report'], { 55 | read: false 56 | }) 57 | .pipe(clean({ 58 | force: true 59 | })); 60 | gulp.src('').pipe(exec('echo Coverage ^& Report directories has been removed')); 61 | }); 62 | 63 | gulp.task('dev', function () { 64 | gulp.run('lint', 'test'); 65 | gulp.watch(['./lib/*', './test/*'], function () { 66 | gulp.run('lint', 'test'); 67 | }); 68 | }); 69 | 70 | // gulp.task('prod', function () { 71 | // if (gulp.env.major) { 72 | // gulp.run('lint', 'test'); 73 | // gulp.src('./package.json') 74 | // .pipe(mversion('major')) 75 | // .pipe(gulp.dest('./')); 76 | // } else if (gulp.env.minor) { 77 | // gulp.run('lint', 'test'); 78 | // gulp.src('./package.json') 79 | // .pipe(mversion('minor')) 80 | // .pipe(gulp.dest('./')); 81 | // } else if (gulp.env.patch) { 82 | // gulp.run('lint', 'test'); 83 | // gulp.src('./package.json') 84 | // .pipe(mversion('patch')) 85 | // .pipe(gulp.dest('./')); 86 | // } 87 | // }); 88 | }()); -------------------------------------------------------------------------------- /lib/util.js: -------------------------------------------------------------------------------- 1 | /*global require*/ 2 | /*jslint nomen: true*/ 3 | 'use strict'; 4 | 5 | var https = require('https'), 6 | http = require('http'), 7 | url = require('url'), 8 | Q = require('q'), 9 | RateLimiter = require('./rateLimiter'), 10 | limiterPer10s, 11 | limiterPer10min, 12 | 13 | craftUrl = function (urlType, region, api, authKey) { 14 | return 'https://' + region + '.' + urlType + '/' + region + api + 'api_key=' + authKey; 15 | }, 16 | craftObserverUrl = function(urlType, region, api, authKey) { 17 | return 'https://' + region + '.' + urlType + api + 18 | 'api_key=' + authKey; 19 | }, 20 | craftStaticUrl = function(urlType, region, api, authKey) { 21 | return 'https://' + 'global.' + urlType + '/' + region + api + 'api_key=' + authKey; 22 | }, 23 | craftStatusUrl = function(urlType, api, region) { 24 | return 'http://' + urlType + api + region; 25 | }, 26 | craftTournamentUrl = function(urlType, api, authKey) { 27 | return 'https://global.' + urlType + '/' + api + 'api_key=' + authKey; 28 | }, 29 | craftChampionMasteryUrl = function(urlType, region, platformId, api, authKey) { 30 | return 'https://' + region + '.' + urlType + '/location/' + platformId + api + 'api_key=' + authKey; 31 | }, 32 | checkLimits = function(callback) { 33 | if(limiterPer10s === undefined || limiterPer10min === undefined){ 34 | process.nextTick(callback); 35 | return; 36 | } 37 | 38 | limiterPer10s.schedule( function(){ 39 | limiterPer10min.schedule(callback); 40 | }); 41 | 42 | }, 43 | 44 | getRequest = function (requestUrl, method, body, callback) { 45 | var jsonObj = '', 46 | protocol = https; 47 | 48 | if (typeof method == 'function') { 49 | callback = method; 50 | method = 'GET'; 51 | body = null; 52 | } 53 | 54 | if (typeof body == 'object') { 55 | body = JSON.stringify(body); 56 | } 57 | 58 | checkLimits(function (err){ 59 | 60 | if(err !== undefined){ 61 | callback(err, null); 62 | } 63 | if(requestUrl.indexOf('http://') !== -1) { 64 | protocol = http; 65 | } 66 | var parsedUrl = url.parse(requestUrl); 67 | var requestData = { 68 | host: parsedUrl.host, 69 | path: parsedUrl.path, 70 | method: method, 71 | headers: { 72 | 'Content-Type': 'application/json', 73 | 'Content-Length': Buffer.byteLength(body) 74 | } 75 | }; 76 | var req = protocol.request(requestData, function (response) { 77 | response.on('data', function (chunk) { 78 | jsonObj += chunk; 79 | }); 80 | 81 | response.on('error', function (error) { 82 | callback(error, null); 83 | }); 84 | 85 | response.on('end', function () { 86 | if (response.statusCode === 204) { 87 | callback(null, null); 88 | } 89 | 90 | try { 91 | jsonObj = JSON.parse(jsonObj); 92 | } catch (e) { 93 | callback(response.statusCode); 94 | return; 95 | } 96 | 97 | if (jsonObj.status && jsonObj.status.message !== 200) { 98 | callback(jsonObj.status.status_code + ' ' + jsonObj.status.message, null); 99 | } else { 100 | callback(null, jsonObj); 101 | } 102 | }); 103 | }); 104 | 105 | req.on('error', function(err) { 106 | callback(err); 107 | }); 108 | 109 | if (typeof body == 'string') req.write(body); 110 | req.end(); 111 | }); 112 | }, 113 | 114 | makeRequest = function (url, errmsg, key, callback) { 115 | var deferred = Q.defer(); 116 | getRequest(url, function (err, result) { 117 | if (err) { 118 | deferred.reject(new Error(errmsg + err)); 119 | } else { 120 | if (key) { 121 | deferred.resolve(result[key]); 122 | } else { 123 | deferred.resolve(result); 124 | } 125 | } 126 | }); 127 | return deferred.promise.nodeify(callback); 128 | }, 129 | 130 | makeStaticRequest = function(err, data, callback) { 131 | var deferred = Q.defer(); 132 | 133 | if (err) { 134 | deferred.reject(err); 135 | } else { 136 | deferred.resolve(data); 137 | } 138 | 139 | return deferred.promise.nodeify(callback); 140 | }, 141 | 142 | makeCustomRequest = function(url, method, body, errmsg, key, callback) { 143 | var deferred = Q.defer(); 144 | getRequest(url, method, body, function (err, result) { 145 | if (err) { 146 | deferred.reject(new Error(errmsg + err)); 147 | } else { 148 | if (key) { 149 | deferred.resolve(result[key]); 150 | } else { 151 | deferred.resolve(result); 152 | } 153 | } 154 | }); 155 | return deferred.promise.nodeify(callback); 156 | }, 157 | 158 | getValidSeasonParam = function (season) { 159 | season = parseInt(season); 160 | return (season === null || season === 3 || season === 2014 || season === 2015); 161 | }, 162 | 163 | getCallbackAndRegion = function (regionOrFunction, region, callback) { 164 | var regionAndFunction = { 165 | 'region': region, 166 | 'callback': callback 167 | }; 168 | 169 | if (regionOrFunction === undefined) { 170 | regionAndFunction.callback = undefined; 171 | } else if (typeof (regionOrFunction) === 'function') { 172 | regionAndFunction.callback = regionOrFunction; 173 | } else if (typeof (regionOrFunction) === 'string') { 174 | regionAndFunction.region = regionOrFunction; 175 | } 176 | 177 | return regionAndFunction; 178 | }, 179 | setRateLimit = function (limitPer10s, limitPer10min){ 180 | if(limitPer10s === false || limitPer10s === undefined){ 181 | limiterPer10min = undefined; 182 | limiterPer10s = undefined; 183 | return; 184 | } 185 | limiterPer10s = new RateLimiter(limitPer10s, 10 * 1000, false); 186 | limiterPer10min = new RateLimiter(limitPer10min, 10 * 60 * 1000, false); 187 | }; 188 | 189 | module.exports = { 190 | craftUrl: craftUrl, 191 | craftObserverUrl: craftObserverUrl, 192 | craftStatusUrl: craftStatusUrl, 193 | craftStaticUrl: craftStaticUrl, 194 | craftTournamentUrl: craftTournamentUrl, 195 | craftChampionMasteryUrl: craftChampionMasteryUrl, 196 | getRequest: getRequest, 197 | makeRequest: makeRequest, 198 | makeStaticRequest: makeStaticRequest, 199 | makeCustomRequest: makeCustomRequest, 200 | getValidSeasonParam: getValidSeasonParam, 201 | getCallbackAndRegion: getCallbackAndRegion, 202 | setRateLimit: setRateLimit 203 | }; 204 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LeagueJS 2 | ======== 3 | 4 | ### This Version is currently no longer maintained. v1.0.0 Rework for Riot API v3 can be found [here on npm](https://www.npmjs.com/package/leaguejs) and [here on Github](https://github.com/Colorfulstan/LeagueJS) 5 | 6 | [![Join the chat at https://gitter.im/League-JS/Lobby](https://badges.gitter.im/League-JS/Lobby.svg)](https://gitter.im/League-JS/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 7 | 8 | A Javascript Wrapper for the League of Legends API 9 | 10 | ## How To Use 11 | 12 | Use npm to install it from the npm registry by running `npm install leagueapi` 13 | 14 | Put the following in a `server.js` file. 15 | 16 | ```Javascript 17 | 18 | var LolApi = require('leagueapi'); 19 | 20 | LolApi.init('XXXXXXXXXXXXXXX', 'na'); 21 | 22 | LolApi.getChampions(true, function(err, champs) { 23 | console.log(champs); 24 | }); 25 | 26 | LolApi.Summoner.getByName('YOLO Swag 5ever', function(err, summoner) { 27 | if(!err) { 28 | console.log(summoner); 29 | } 30 | }) 31 | 32 | //The wrapper also accepts promises: 33 | LolApi.Summoner.getByName('YOLO Swag 5ever') 34 | .then(function (summoner) { 35 | console.log(summoner); 36 | }); 37 | ``` 38 | Run `npm install` followed by `node server.js` 39 | 40 | ### Here's the list of methods and their parameters: 41 | `[param]` means you can pass null values if you don't want to specify the paramater 42 | 43 | 44 | ```Javascript 45 | LolApi.Init(ApiKey); //Will default to NA 46 | LolApi.Init(ApiKey, region); 47 | 48 | LolApi.setRateLimit(limitPer10s, limitPer10min); 49 | 50 | LolApi.setEndpoint(newEndpoint); 51 | LolApi.getEndpoint(); 52 | 53 | LolApi.getMapNames(callback); 54 | 55 | LolApi.getRegions(callback); 56 | 57 | LolApi.getPlatformId(region, callback); 58 | 59 | LolApi.getQueues(callback); 60 | 61 | LolApi.getChampions([freeToPlay], region, callback); 62 | LolApi.getChampions([freeToPlay], callback); 63 | 64 | LolApi.getRecentGames(summonerId, region, callback); 65 | LolApi.getRecentGames(summonerId, callback); 66 | 67 | LolApi.getLeagueData(summonerId, region, callback); 68 | LolApi.getLeagueData(summonerId, callback); 69 | 70 | LolApi.getTeamLeagueData(teamId, region, callback); // Get LeagueData for given Team ID in given region 71 | LolApi.getTeamLeagueData(teamId, callback); // Get LeagueData for given Team ID 72 | 73 | LolApi.getLeagueEntryData(summonerId, region, callback); 74 | LolApi.getLeagueEntryData(summonerId, callback); 75 | 76 | LolApi.getTeamLeagueEntryData(teamId, region, callback); // Get LeagueData Entry for given Team ID in given region 77 | LolApi.getTeamLeagueEntryData(teamId, callback); // Get LeagueData Entry for given Team ID 78 | 79 | LolApi.getTeams(summonerId, region, callback); 80 | LolApi.getTeams(summonerId, callback); 81 | 82 | LolApi.getTeam(teamId, region, callback); 83 | LolApi.getTeam(teamId, callback); 84 | 85 | LolApi.getShards(callback); 86 | LolApi.getShardByRegion(callback); 87 | 88 | LolApi.getMatch(matchId, [includeTimeline], region, callback); 89 | 90 | options = {championIds: [1,3,4], rankedQueues: ['RANKED_SOLO_5x5', 'RANKED_TEAM_3x3', 'RANKED_TEAM_5x5'], beginIndex: 1, endIndex: 5}; 91 | LolApi.getMatchHistory(summonerId, [options], region, callback); 92 | 93 | LolApi.getCurrentGame(summonerId, region, callback); 94 | 95 | LolApi.getFeaturedGames(region, callback); 96 | 97 | LolApi.Stats.getPlayerSummary(summonerId, [season], region, callback); 98 | LolApi.Stats.getPlayerSummary(summonerId, [season], callback); 99 | 100 | LolApi.Stats.getRanked(summonerId, [season], region, callback); 101 | LolApi.Stats.getRanked(summonerId, [season], callback); 102 | 103 | LolApi.Summoner.getMasteries(summonerId, region, callback); 104 | LolApi.Summoner.getMasteries(summonerId, callback); 105 | 106 | LolApi.Summoner.getRunes(summonerId, region, callback); 107 | LolApi.Summoner.getRunes(summonerId, callback); 108 | 109 | LolApi.Summoner.getByID(summonerId, region, callback); 110 | LolApi.Summoner.getByID(summonerId, callback); 111 | 112 | LolApi.Summoner.getByName(name, region, callback); 113 | LolApi.Summoner.getByName(name, callback); 114 | 115 | LoLApi.Summoner.listNamesByIDs(ids, region, callback); 116 | LolApi.Summoner.listNamesByIDs(ids, callback); 117 | 118 | options = {champData: 'allytips,blurb', version : '4.4.3', locale: 'en_US', dataById=true} 119 | //doesn't show all options 120 | LolApi.Static.getChampionList(options, region, callback); 121 | LolApi.Static.getChampionList(options, callback); 122 | 123 | options = {champData: 'allytips,blurb', version : '4.4.3', locale: 'en_US', dataById=true} 124 | //doesn't show all options 125 | LolApi.Static.getChampionById(champId, options, region, callback); 126 | LolApi.Static.getChampionById(champId, options, callback); 127 | 128 | options = {itemData: 'consumed'} 129 | //doesn't show all possible options 130 | LolApi.Static.getItemById(itemId, options, region, callback); 131 | LolApi.Static.getItemById(itemId, options, callback); 132 | 133 | options = {itemListData: 'consumed'} 134 | LolApi.Static.getItemList(options, region, callback); 135 | LolApi.Static.getItemList(options, callback); 136 | 137 | LolApi.Static.getMasteryList(options, region, callback); 138 | LolApi.Static.getMasteryList(options, callback); 139 | 140 | LolApi.Static.getMasteryById(options, region, callback); 141 | LolApi.Static.getMasteryById(options, callback); 142 | 143 | LolApi.Static.getRealm(region, callback); 144 | LolApi.Static.getRealm(callback); 145 | 146 | LolApi.Static.getRuneList(options, region, callback); 147 | LolApi.Static.getRuneById(id, options, callback); 148 | 149 | LolApi.Static.getSummonerSpellList(options, region, callback); 150 | LolApi.Static.getSummonerSpellById(id, options, callback); 151 | 152 | LolApi.ChampionMastery.getChampions(playerId, region, callback); 153 | LolApi.ChampionMastery.getChampions(playerId, callback); 154 | 155 | LolApi.ChampionMastery.getChampion(playerId, championId, region, callback); 156 | LolApi.ChampionMastery.getChampion(playerId, championId, callback); 157 | 158 | LolApi.ChampionMastery.getScore(playerId, region, callback); 159 | LolApi.ChampionMastery.getScore(playerId, callback); 160 | 161 | LolApi.ChampionMastery.getTopChampions(playerId, count, region, callback); 162 | LolApi.ChampionMastery.getTopChampions(playerId, count, callback); 163 | 164 | 165 | //The following methods are only for enabled tournament api keys: 166 | 167 | LolApi.getMatchForTournament(matchId, tournamentCode, [includeTimeline], region, callback); 168 | LolApi.getMatchForTournament(matchId, tournamentCode, [includeTimeline], callback); 169 | 170 | LolApi.getMatchIdsByTournament(tournamentCode, region, callback); 171 | LolApi.getMatchIdsByTournament(tournamentCode, callback); 172 | 173 | LolApi.Tournament.createProvider(region, callbackUrl, callback); 174 | 175 | LolApi.Tournament.createTournament(name, providerId, callback); 176 | 177 | LolApi.Tournament.createCode(tournamentId, count, options, callback); 178 | LolApi.Tournament.updateCode(tournamentCode, options, callback); 179 | LolApi.Tournament.getCode(tournamentCode, callback); 180 | 181 | LolApi.Tournament.getLobbyEventsByCode(tournamentCode, callback); 182 | ``` 183 | 184 | ## LeagueJS Gulp Commands 185 | 186 | Gulp.js is a streaming build system. Thanks to it's simplicity and code-over-configuration 187 | we are able to create a simple, efficient and more intuitive build process. 188 | 189 | ### To get started you need to install Gulp.js globally: 190 | - `npm install -g gulp` 191 | 192 | #### Available gulp commands and their descriptions: 193 | 194 | Run JSLint on all js files: 195 | 196 | - `gulp lint` 197 | 198 | Run BDD tests: 199 | 200 | - `gulp test` 201 | 202 | Run istabul to generate a code coverage report: 203 | 204 | - `gulp test-coverage` 205 | 206 | Run plato to generate a code analysis report: 207 | 208 | - `gulp code-report` 209 | 210 | Runs both istanbul and plato in with one command: 211 | 212 | - `gulp reports` 213 | 214 | Removes both coverage and report directories created by istanbul and plato 215 | 216 | - `gulp clean-reports` 217 | 218 | Sets up a development environment that will listen for code changes, then run JSLint and BDD tests upon saving: 219 | 220 | - `gulp dev` 221 | -------------------------------------------------------------------------------- /test/leagueApiSpec.js: -------------------------------------------------------------------------------- 1 | /*global describe*/ 2 | /*global require*/ 3 | /*global beforeEach*/ 4 | /*global it*/ 5 | /*global xit*/ 6 | 7 | describe('League of Legends api wrapper test suite', function () { 8 | 'use strict'; 9 | 10 | 11 | var sinon = require('sinon'), 12 | should = require('should'), 13 | leagueApi = require('../lib/lolapi'), 14 | mockChampionArray = ['Teemo', 'Ahri', 'Vladimir'], 15 | mockSummonersArray = [29228901, 19199530, 19442617], 16 | mockMatchArray = [1622420185, 1622447158], 17 | mockTeam = 'TEAM-e5d4b050-4699-11e5-8042-c81f66dd32cd' 18 | ; 19 | 20 | 21 | beforeEach(function () { 22 | leagueApi.init(process.env.API_TOKEN, process.env.API_REGION); 23 | }); 24 | 25 | it('should be able to retrieve all champions', function (done) { 26 | 27 | leagueApi.getChampions(false, 'na', function (err, res) { 28 | should.not.exist(err); 29 | should.exist(res); 30 | res.length.should.be.greaterThan(0); 31 | done(); 32 | }); 33 | }); 34 | 35 | it('should be able to get the masteries of someone', function (done) { 36 | 37 | leagueApi.Summoner.getMasteries(19321078, function(err, masteries) { 38 | should.not.exist(err); 39 | should.exist(masteries); 40 | done(); 41 | }); 42 | }); 43 | 44 | it('should be able to get the runes of someone', function (done) { 45 | 46 | leagueApi.Summoner.getRunes(19321078, function(err, masteries) { 47 | should.not.exist(err); 48 | should.exist(masteries); 49 | done(); 50 | }); 51 | }); 52 | 53 | it('should be able to retrieve all of the free champions', function (done) { 54 | leagueApi.getChampions(true, 'na', function (err, res) { 55 | should.not.exist(err); 56 | should.exist(res); 57 | res.length.should.be.equal(20); 58 | done(); 59 | }); 60 | }); 61 | 62 | it('should throw an error if given the wrong type ', function (done) { 63 | done(); 64 | }); 65 | 66 | it('should be able to get summoners data from a list of ids', function (done) { 67 | leagueApi.Summoner.listSummonerDataByIDs(mockSummonersArray, function (err, res) { 68 | should.not.exist(err); 69 | should.exist(res); 70 | mockSummonersArray.forEach(function (id) { 71 | should.exist(res[id]); 72 | }); 73 | done(); 74 | }); 75 | }); 76 | 77 | it('should be able to get champion static data', function(done) { 78 | var options = {champData: 'allytips,blurb', version: '5.24.2', locale: 'en_US'}; 79 | leagueApi.Static.getChampionList(options, 'na', function(err, champs) { 80 | should.not.exist(err); 81 | should.exist(champs); 82 | done(); 83 | }); 84 | }); 85 | 86 | it('should be able to get a list of versions', function(done) { 87 | leagueApi.Static.getVersions('na', function(err, vers) { 88 | should.not.exist(err); 89 | should.exist(vers); 90 | done(); 91 | }); 92 | }); 93 | 94 | it('should be able to get static data of a champion by id', function(done) { 95 | var options = {champData: 'allytips,blurb', version: '5.24.2', locale: 'en_US'}; 96 | leagueApi.Static.getChampionById(1, options, 'na', function(err, champ) { 97 | should.not.exist(err); 98 | should.exist(champ); 99 | done(); 100 | }); 101 | }); 102 | 103 | it('should be able to get a list of items', function(done) { 104 | var options = {champData: 'allytips,blurb', version: '5.24.2', locale: 'en_US'}; 105 | leagueApi.Static.getItemList(options, 'na', function(err, items) { 106 | should.not.exist(err); 107 | should.exist(items); 108 | done(); 109 | }); 110 | }); 111 | 112 | it('should be able to get static data of an item by id', function(done) { 113 | var options = {champData: 'allytips,blurb', version: '5.24.2', locale: 'en_US'}; 114 | leagueApi.Static.getItemById(2009, options, 'na', function(err, item) { 115 | should.not.exist(err); 116 | should.exist(item); 117 | done(); 118 | }); 119 | }); 120 | 121 | it('should be able to get static data of masteries', function(done) { 122 | var options = {masteryListData: 'prereq', version: '5.24.2', locale: 'en_US'}; 123 | leagueApi.Static.getMasteryList(options, 'na', function (err, masteries) { 124 | should.not.exist(err); 125 | should.exist(masteries); 126 | done(); 127 | }); 128 | }); 129 | 130 | it('should be able to get static data of a mastery by id', function(done) { 131 | var options = {masteryData: 'prereq', version: '5.24.2', locale: 'en_US'}; 132 | leagueApi.Static.getMasteryById(6223, options, 'na', function (err, mastery) { 133 | should.not.exist(err); 134 | should.exist(mastery); 135 | done(); 136 | }); 137 | }); 138 | 139 | it('should be able to get static data of a realm', function(done) { 140 | leagueApi.Static.getRealm('na', function (err, realm) { 141 | should.not.exist(err); 142 | should.exist(realm); 143 | done(); 144 | }); 145 | }); 146 | 147 | it('should be able to get match', function(done) { 148 | leagueApi.getMatch(mockMatchArray[0], false, function(err, match) { 149 | should.not.exist(err); 150 | should.exist(match); 151 | done(); 152 | }); 153 | }); 154 | 155 | it('should be able to get match with timeline', function(done) { 156 | this.timeout(2500); 157 | leagueApi.getMatch(mockMatchArray[0], true, function(err, match) { 158 | should.not.exist(err); 159 | should.exist(match); 160 | should.exist(match.timeline); 161 | done(); 162 | }); 163 | }); 164 | 165 | it('should be able to get League Data', function(done) { 166 | leagueApi.getLeagueData(mockSummonersArray[2], 'euw', function(err, data) { 167 | should.not.exist(err); 168 | should.exist(data); 169 | done(); 170 | }); 171 | }); 172 | 173 | it('should be able to get Team League Data', function(done) { 174 | leagueApi.getTeamLeagueData(mockTeam, 'euw', function(err, data) { 175 | should.not.exist(err); 176 | should.exist(data); 177 | done(); 178 | }); 179 | }); 180 | 181 | it('should be able to get League Data Entry', function(done) { 182 | leagueApi.getLeagueEntryData(mockSummonersArray[2], 'euw', function(err, data) { 183 | should.not.exist(err); 184 | should.exist(data); 185 | done(); 186 | }); 187 | }); 188 | 189 | it('should be able to get Team League Data Entry', function(done) { 190 | leagueApi.getTeamLeagueEntryData(mockTeam, 'euw', function(err, data) { 191 | should.not.exist(err); 192 | should.exist(data); 193 | done(); 194 | }); 195 | }); 196 | 197 | it('should be able to get match history', function(done) { 198 | leagueApi.getMatchHistory(mockSummonersArray[0], null, 'na', function(err, match) { 199 | should.not.exist(err); 200 | should.exist(match); 201 | done(); 202 | }); 203 | }); 204 | 205 | it('should be able to get match history with options', function(done) { 206 | var options = { 207 | championIds : [5,10,9,1,35], 208 | rankedQueues : ['RANKED_SOLO_5x5', 'RANKED_TEAM_3x3'], 209 | beginIndex : 1, 210 | endIndex : 5 211 | }; 212 | leagueApi.getMatchHistory(mockSummonersArray[0], options, 'na', function(err, match) { 213 | should.not.exist(err); 214 | should.exist(match); 215 | done(); 216 | }); 217 | }); 218 | 219 | it('should not be able to get current game', function(done) { 220 | leagueApi.getCurrentGame(mockSummonersArray[0], function(err, game) { 221 | should.exist(err); 222 | should.not.exist(game); 223 | done(); 224 | }); 225 | }); 226 | 227 | it('should not be able to get featured games', function(done) { 228 | leagueApi.getFeaturedGames('na', function(err, games) { 229 | should.exist(games); 230 | should.not.exist(err); 231 | done(); 232 | }); 233 | }); 234 | 235 | it('should be able to get team information', function(done) { 236 | leagueApi.getTeam(mockTeam, 'euw', function(err, team) { 237 | should.exist(team); 238 | should.not.exist(err); 239 | done(); 240 | }); 241 | }); 242 | 243 | it('should be able to get a new endpoint', function(done) { 244 | 245 | var currentEndpoint = leagueApi.getEndpoint(), 246 | newEndpointUrl = 'https://eu.api.pvp.net/api/lol', 247 | newEndpoint; 248 | should(currentEndpoint).equal('api.pvp.net/api/lol'); 249 | 250 | leagueApi.setEndpoint(newEndpointUrl); 251 | newEndpoint = leagueApi.getEndpoint(); 252 | should(newEndpoint).equal(newEndpointUrl); 253 | 254 | done(); 255 | 256 | }); 257 | 258 | it('should be able to get shards', function(done) { 259 | leagueApi.getShards(function(err, shards) { 260 | should.not.exist(err); 261 | should.exist(shards); 262 | done(); 263 | }); 264 | }); 265 | 266 | it('should be able to get shards by region', function(done) { 267 | leagueApi.getShardByRegion('na', function(err, shards) { 268 | should.not.exist(err); 269 | should.exist(shards); 270 | done(); 271 | }); 272 | }); 273 | 274 | it('shoult not be able to get infos from not existing regions', function(done) { 275 | leagueApi.Summoner.getByName('', 'eu-na', function(err, sum) { 276 | should.exist(err); 277 | should.not.exist(sum); 278 | done(); 279 | }); 280 | }); 281 | 282 | it('should be able to get champion mastery champions', function(done) { 283 | leagueApi.ChampionMastery.getChampions(36879107, 'euw', function(err, data) { 284 | should.not.exist(err); 285 | should.exist(data); 286 | done(); 287 | }); 288 | }); 289 | 290 | it('should be able to get champion mastery champion', function(done) { 291 | leagueApi.ChampionMastery.getChampion(36879107, 25, 'euw', function(err, data) { 292 | should.not.exist(err); 293 | should.exist(data); 294 | done(); 295 | }); 296 | }); 297 | 298 | it('should be able to get champion mastery champions', function(done) { 299 | leagueApi.ChampionMastery.getScore(36879107, 'euw', function(err, data) { 300 | should.not.exist(err); 301 | should.exist(data); 302 | done(); 303 | }); 304 | }); 305 | 306 | it('should be able to get champion mastery champions', function(done) { 307 | leagueApi.ChampionMastery.getTopChampions(36879107, 3, 'euw', function(err, data) { 308 | should.not.exist(err); 309 | should.exist(data); 310 | done(); 311 | }); 312 | }); 313 | }); 314 | -------------------------------------------------------------------------------- /lib/lolapi.js: -------------------------------------------------------------------------------- 1 | /*global require*/ 2 | /*global module*/ 3 | /*global console*/ 4 | /*jslint nomen: true*/ 5 | 6 | (function () { 7 | 8 | 'use strict'; 9 | 10 | var League = {}, 11 | util = require('./util'), 12 | authKey, 13 | region = 'na', 14 | endpoint = 'api.pvp.net/api/lol', 15 | statusEndpoint = 'status.leagueoflegends.com', 16 | tournamentEndpoint = 'api.pvp.net/tournament/public/v1', 17 | championMasteryEndpoint = 'api.pvp.net/championmastery', 18 | championUrl = '/v1.2/champion', 19 | gameUrl = '/v1.3/game/by-summoner', 20 | leagueUrl = { 21 | summoner: '/v2.5/league/by-summoner', 22 | team: '/v2.5/league/by-team' 23 | }, 24 | statsUrl = '/v1.3/stats/by-summoner', 25 | summonerUrl = '/v1.4/summoner', 26 | matchUrl = '/v2.2/match', 27 | matchHistoryUrl = '/v2.2/matchlist/by-summoner', 28 | observerUrl = 'api.pvp.net/observer-mode/rest', 29 | teamUrl = '/v2.4/team/', 30 | staticUrl = '/static-data'; 31 | League.Stats = {}; 32 | 33 | League.Summoner = {}; 34 | 35 | League.Static = {}; 36 | 37 | League.Tournament = {}; 38 | 39 | League.ChampionMastery = {}; 40 | 41 | League.init = function (key, regionTag) { 42 | authKey = key; 43 | if (regionTag) { 44 | region = regionTag; 45 | } 46 | }; 47 | 48 | League.getRegions = function (callback) { 49 | var regions = { 50 | 'na': 'North America', 51 | 'euw': 'Europe West', 52 | 'eune': 'Europe Nordic and East' 53 | }; 54 | return util.makeStaticRequest(error, regions); 55 | }; 56 | 57 | League.getPlatformId = function (region, callback) { 58 | var platforms = { 59 | 'na': 'NA1', 60 | 'euw': 'EUW1', 61 | 'eune': 'EUN1', 62 | 'lan': 'LA1', 63 | 'las': 'LA2', 64 | 'oce': 'OC1', 65 | 'tr': 'TR1', 66 | 'ru': 'RU', 67 | 'br': 'BR1', 68 | 'kr': 'KR', 69 | 'jp': 'JP1' 70 | }, 71 | platformId, 72 | error; 73 | platformId = platforms[region]; 74 | error = platformId ? null : 'Invalid region'; 75 | return util.makeStaticRequest(error, platformId); 76 | }; 77 | 78 | League.getQueues = function (callback) { 79 | var queues = { 80 | 2: 'Normal 5v5 Blind Pick', 81 | 4: 'Ranked Solo 5v5', 82 | 7: 'Coop vs AI 5v5', 83 | 8: 'Normal 3v3', 84 | 14: 'Normal 5v5 Draft Pick', 85 | 16: 'Dominion 5v5 Blind Pick', 86 | 17: 'Dominion 5v5 Draft Pick', 87 | 25: 'Dominion Coop vs AI', 88 | 41: 'Ranked Team 3v3', 89 | 42: 'Ranked Team 5v5', 90 | 52: 'Twisted Treeline Coop vs AI', 91 | 65: 'ARAM', 92 | 67: 'ARAM Coop vs AI' 93 | }; 94 | return util.makeStaticRequest(null, queues); 95 | }; 96 | 97 | League.getMapNames = function (callback) { 98 | var maps ={ 99 | 1: 'Summoner\'s Rift Summer Variant ', 100 | 2: 'Summoner\'s Rift Autumn Variant', 101 | 3: 'The Proving Grounds', 102 | 4: 'Twisted Treeline Original Version', 103 | 8: 'The Crystal Scar', 104 | 10: 'Twisted Treeline Current Version', 105 | 12: 'Howling Abyss' 106 | }; 107 | return util.makeStaticRequest(null, maps); 108 | }; 109 | 110 | League.getShards = function(callback) { 111 | var shards = '/shards', 112 | url = util.craftStatusUrl(statusEndpoint, shards, ''); 113 | 114 | return util.makeRequest(url, 'Error getting shards: ', null, callback); 115 | }; 116 | 117 | League.getShardByRegion = function(regionOrFunction, callback) { 118 | var shards = '/shards', 119 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 120 | url = util.craftStatusUrl(statusEndpoint, shards, '/' + regionAndFunc.region); 121 | return util.makeRequest(url, 'Error getting shards by region ', null, callback); 122 | }; 123 | 124 | League.getMatch = function(matchId, includeTimelineOrFunction, regionOrFunction, callback) { 125 | var url, 126 | regionAndFunc; 127 | if (typeof(includeTimelineOrFunction) === 'function'){ 128 | regionAndFunc = util.getCallbackAndRegion(includeTimelineOrFunction, region, callback); 129 | } else { 130 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback); 131 | } 132 | if (includeTimelineOrFunction) { 133 | includeTimelineOrFunction = 'includeTimeline=true&'; 134 | } else { 135 | includeTimelineOrFunction = ''; 136 | } 137 | url = util.craftUrl(endpoint, regionAndFunc.region, matchUrl + '/' + 138 | matchId + '?' + includeTimelineOrFunction, authKey); 139 | return util.makeRequest(url, 'Error getting match: ', null, regionAndFunc.callback); 140 | }; 141 | 142 | League.getMatchForTournament = function(matchId, tournamentCode, includeTimelineOrFunction, regionOrFunction, callback) { 143 | var url, 144 | regionAndFunc; 145 | if (typeof(includeTimelineOrFunction) === 'function'){ 146 | regionAndFunc = util.getCallbackAndRegion(includeTimelineOrFunction, region, callback); 147 | } else { 148 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback); 149 | } 150 | if (includeTimelineOrFunction) { 151 | includeTimelineOrFunction = 'includeTimeline=true&'; 152 | } else { 153 | includeTimelineOrFunction = ''; 154 | } 155 | url = util.craftUrl(endpoint, regionAndFunc.region, matchUrl + '/for-tournament/' + 156 | matchId + '?' + includeTimelineOrFunction + 'tournamentCode=' + tournamentCode + '&', authKey); 157 | return util.makeRequest(url, 'Error getting tournament match: ', null, regionAndFunc.callback); 158 | }; 159 | 160 | League.getMatchIdsByTournament = function(tournamentCode, regionOrFunction, callback) { 161 | var url, 162 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback); 163 | 164 | url = util.craftUrl(endpoint, regionAndFunc.region, matchUrl + '/by-tournament/' + 165 | tournamentCode + '/ids?', authKey); 166 | return util.makeRequest(url, 'Error getting tournament match ids: ', null, regionAndFunc.callback); 167 | }; 168 | 169 | League.getMatchHistory = function(summonerId, options, regionOrFunction, callback) { 170 | var url, 171 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 172 | historyOptions = ''; 173 | if(options) { 174 | if (options.championIds) { 175 | historyOptions += '&championIds=' + options.championIds.join(); 176 | } 177 | if (options.rankedQueues) { 178 | historyOptions += '&rankedQueues=' + options.rankedQueues.join(); 179 | } 180 | if (options.beginIndex) { 181 | historyOptions += '&beginIndex=' + options.beginIndex; 182 | } 183 | if (options.endIndex) { 184 | historyOptions += '&endIndex=' + options.endIndex; 185 | } 186 | if (options.beginTime) { 187 | historyOptions += '&beginTime=' + options.beginTime; 188 | } 189 | if (options.endTime) { 190 | historyOptions += '&endTime=' + options.endTime; 191 | } 192 | historyOptions += '&'; 193 | historyOptions = historyOptions.substr(1); 194 | } 195 | url = util.craftUrl(endpoint, regionAndFunc.region, matchHistoryUrl + '/' + 196 | summonerId + '?' + historyOptions, authKey); 197 | return util.makeRequest(url, 'Error getting match history: ', null, regionAndFunc.callback); 198 | }; 199 | League.getCurrentGame = function(summonerId, regionOrFunction, callback) { 200 | var currentGameUrl = '/consumer/getSpectatorGameInfo', 201 | url, 202 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 203 | platformId; 204 | 205 | return League.getPlatformId(regionAndFunc.region) 206 | .then(function(platformId) { 207 | url = util.craftObserverUrl(observerUrl, regionAndFunc.region, currentGameUrl + '/' + 208 | platformId + '/' + summonerId + '?', authKey); 209 | 210 | return util.makeRequest(url, 'Error getting current game: ', null, regionAndFunc.callback); 211 | }) 212 | }; 213 | League.getFeaturedGames = function(regionOrFunction, callback) { 214 | var featuredUrl = '/featured', 215 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 216 | url = util.craftObserverUrl(observerUrl, regionAndFunc.region, featuredUrl + '?', authKey); 217 | return util.makeRequest(url, 'Error getting current game: ', null, regionAndFunc.callback); 218 | }; 219 | League.getChampions = function (freeToPlay, regionOrFunction, callback) { 220 | var url, 221 | freetoPlayQuery = '', 222 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback); 223 | 224 | if (freeToPlay === null || typeof (freeToPlay) !== 'boolean') { 225 | console.log('Invalid query parameter for freeToPlay: ' + freeToPlay); 226 | } 227 | 228 | if (freeToPlay) { 229 | freetoPlayQuery = 'freeToPlay=true&'; 230 | } 231 | url = util.craftUrl(endpoint, regionAndFunc.region, championUrl + '?' + freetoPlayQuery, authKey); 232 | return util.makeRequest(url, 'Error getting champions: ', 'champions', regionAndFunc.callback); 233 | }; 234 | 235 | League.getRecentGames = function (summonerId, regionOrFunction, callback) { 236 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 237 | url = util.craftUrl(endpoint, regionAndFunc.region, gameUrl + '/' + summonerId + '/recent?', authKey); 238 | 239 | return util.makeRequest(url, 'Error getting recent games: ', 'games', regionAndFunc.callback); 240 | }; 241 | 242 | League.getLeagueData = function (summonerId, regionOrFunction, callback) { 243 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 244 | url = util.craftUrl(endpoint, regionAndFunc.region, leagueUrl.summoner + '/' + summonerId + '?', authKey); 245 | 246 | return util.makeRequest(url, 'Error getting league data: ', null, regionAndFunc.callback); 247 | }; 248 | 249 | League.getTeamLeagueData = function(teamId, regionOrFunction, callback) { 250 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 251 | url = util.craftUrl(endpoint, regionAndFunc.region, leagueUrl.team + '/' + teamId + '?', authKey); 252 | 253 | return util.makeRequest(url, 'Error getting league data: ', null, regionAndFunc.callback); 254 | }; 255 | 256 | League.getLeagueEntryData = function (summonerId, regionOrFunction, callback) { 257 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 258 | url = util.craftUrl(endpoint, regionAndFunc.region, leagueUrl.summoner + '/' + summonerId + '/entry?', authKey); 259 | 260 | return util.makeRequest(url, 'Error getting league data: ', null, regionAndFunc.callback); 261 | }; 262 | 263 | League.getTeamLeagueEntryData = function (teamId, regionOrFunction, callback) { 264 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 265 | url = util.craftUrl(endpoint, regionAndFunc.region, leagueUrl.team + '/' + teamId + '/entry?', authKey); 266 | 267 | return util.makeRequest(url, 'Error getting league data: ', null, regionAndFunc.callback); 268 | }; 269 | 270 | League.Stats.getPlayerSummary = function (summonerId, season, regionOrFunction, callback) { 271 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 272 | seasonURL = '', 273 | url; 274 | 275 | if (util.getValidSeasonParam(season)) { 276 | if (season) { 277 | seasonURL = 'season=SEASON' + season + '&'; 278 | } 279 | } else { 280 | console.log('Invalid query parameter for season: ' + season); 281 | } 282 | 283 | url = util.craftUrl(endpoint, regionAndFunc.region, 284 | statsUrl + '/' + summonerId + '/summary?' + seasonURL, authKey); 285 | return util.makeRequest(url, 'Error getting summary data: ', 'playerStatSummaries', regionAndFunc.callback); 286 | }; 287 | 288 | League.Stats.getRanked = function (summonerId, season, regionOrFunction, callback) { 289 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 290 | seasonURL = '', 291 | url; 292 | 293 | if (util.getValidSeasonParam(season)) { 294 | if (season) { 295 | seasonURL = 'season=SEASON' + season + '&'; 296 | } 297 | } else { 298 | console.log('Invalid query parameter for season: ' + season); 299 | } 300 | 301 | url = util.craftUrl(endpoint, regionAndFunc.region, 302 | statsUrl + '/' + summonerId + '/ranked?' + seasonURL, authKey); 303 | return util.makeRequest(url, 'Error getting ranked data: ', 'champions', regionAndFunc.callback); 304 | }; 305 | 306 | League.Summoner.getMasteries = function (summonerId, regionOrFunction, callback) { 307 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, 308 | region, 309 | callback), 310 | url = util.craftUrl(endpoint, regionAndFunc.region, 311 | summonerUrl + '/' + summonerId + '/masteries?', authKey); 312 | return util.makeRequest(url, 'Error getting mastery data: ', null, regionAndFunc.callback); 313 | }; 314 | 315 | League.Summoner.getRunes = function (summonerId, regionOrFunction, callback) { 316 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 317 | url = util.craftUrl(endpoint, regionAndFunc.region, summonerUrl + '/' + summonerId + '/runes?', authKey); 318 | 319 | return util.makeRequest(url, 'Error getting rune data: ', null, regionAndFunc.callback); 320 | }; 321 | 322 | League.Summoner.getByName = function (name, regionOrFunction, callback) { 323 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 324 | url; 325 | 326 | name = encodeURIComponent(name.split(' ').join('')); 327 | url = util.craftUrl(endpoint, regionAndFunc.region, summonerUrl + '/by-name/' + name + '?', authKey); 328 | 329 | return util.makeRequest(url, 'Error getting summoner data using name: ', null, regionAndFunc.callback); 330 | }; 331 | 332 | League.Summoner.listSummonerDataByNames = function (names, regionOrFunction, callback) { 333 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 334 | url; 335 | 336 | names = names.map(function (name) { 337 | return encodeURIComponent(name.split(' ').join('')) 338 | }) 339 | url = util.craftUrl(endpoint, regionAndFunc.region, summonerUrl + '/by-name/' + names.toString() + '?', authKey); 340 | 341 | return util.makeRequest(url, 'Error getting summoner data using names: ', null, regionAndFunc.callback); 342 | }; 343 | 344 | League.Summoner.getByID = function (summonerId, regionOrFunction, callback) { 345 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 346 | url = util.craftUrl(endpoint, regionAndFunc.region, summonerUrl + '/' + summonerId + '?', authKey); 347 | 348 | return util.makeRequest(url, 'Error getting summoner data: ', null, regionAndFunc.callback); 349 | }; 350 | 351 | League.Summoner.listNamesByIDs = function (ids, regionOrFunction, callback) { 352 | if(Array.isArray(ids)){ 353 | ids = ids.join(); 354 | } 355 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 356 | url = util.craftUrl(endpoint, regionAndFunc.region, summonerUrl + '/' + ids + '/name?', authKey); 357 | 358 | return util.makeRequest(url, 'Error getting summoner names using list of ids: ', null, regionAndFunc.callback); 359 | }; 360 | League.Summoner.listSummonerDataByIDs = function (ids, regionOrFunction, callback) { 361 | 362 | if(Array.isArray(ids)){ 363 | ids = ids.join(); 364 | } 365 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 366 | url = util.craftUrl(endpoint, regionAndFunc.region, summonerUrl + '/' + ids + '?', authKey); 367 | return util.makeRequest(url, 'Error getting summoner data using list of ids: ', null, regionAndFunc.callback); 368 | }; 369 | 370 | League.getTeams = function (summonerId, regionOrFunction, callback) { 371 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 372 | url = util.craftUrl(endpoint, regionAndFunc.region, teamUrl + 'by-summoner/' + summonerId + '?', authKey); 373 | 374 | return util.makeRequest(url, 'Error getting summoner teams info: ', null, regionAndFunc.callback); 375 | }; 376 | 377 | League.getTeam = function (teamId, regionOrFunction, callback) { 378 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 379 | url = util.craftUrl(endpoint, regionAndFunc.region, teamUrl + teamId + '?', authKey); 380 | 381 | return util.makeRequest(url, 'Error gettin Team info: ', null, regionAndFunc.callback); 382 | }; 383 | 384 | League.setRateLimit = function (limitPer10s, limitPer10min) { 385 | util.setRateLimit(limitPer10s, limitPer10min); 386 | }; 387 | 388 | League.setEndpoint = function (newEndpoint) { 389 | endpoint = newEndpoint; 390 | }; 391 | 392 | League.setSummonerUrl = function (newPath) { 393 | summonerUrl = newPath; 394 | }; 395 | 396 | League.getSummonerUrl = function (newPath) { 397 | return summonerUrl; 398 | }; 399 | 400 | League.getEndpoint = function () { 401 | return endpoint; 402 | }; 403 | League.Static.getChampionList = function(options, regionOrFunction, callback) { 404 | var championListUrl = '/v1.2/champion?', 405 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 406 | url; 407 | if(options) { 408 | if (options.champData) { 409 | var champData = [].concat(options.champData); 410 | championListUrl += '&champData=' + champData.join(); 411 | } 412 | 413 | if (options.dataById) { 414 | championListUrl += '&dataById=true'; 415 | } 416 | 417 | if (options.version) { 418 | championListUrl += '&version=' + options.version; 419 | } 420 | 421 | if (options.locale) { 422 | championListUrl += '&locale=' + options.locale; 423 | } 424 | championListUrl += '&'; 425 | 426 | } 427 | url = util.craftStaticUrl(endpoint + staticUrl, regionAndFunc.region, championListUrl, authKey); 428 | return util.makeRequest(url, 'Error getting static champion list: ', null, regionAndFunc.callback); 429 | }; 430 | 431 | League.Static.getChampionById = function(id, options, regionOrFunction, callback) { 432 | var championListUrl = '/v1.2/champion/' + id + '?', 433 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 434 | url; 435 | 436 | if(options) { 437 | if (options.champData) { 438 | var champData = [].concat(options.champData); 439 | championListUrl += '&champData=' + champData.join(); 440 | } 441 | 442 | if (options.version) { 443 | championListUrl += '&version=' + options.version; 444 | } 445 | 446 | if (options.locale) { 447 | championListUrl += '&locale=' + options.locale; 448 | } 449 | championListUrl += '&'; 450 | } 451 | 452 | url = util.craftStaticUrl(endpoint + staticUrl, regionAndFunc.region, championListUrl, authKey); 453 | return util.makeRequest(url, 'Error getting static champion by id: ', null, regionAndFunc.callback); 454 | }; 455 | 456 | League.Static.getItemList = function(options, regionOrFunction, callback) { 457 | var itemListUrl = '/v1.2/item?', 458 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 459 | url; 460 | if (options) { 461 | if (options.itemListData) { 462 | itemListUrl += '&itemListData=' + options.itemListData; 463 | } 464 | 465 | if (options.version) { 466 | itemListUrl += '&version=' + options.version; 467 | } 468 | 469 | if (options.locale) { 470 | itemListUrl += '&locale=' + options.locale; 471 | } 472 | itemListUrl += '&'; 473 | } 474 | url = util.craftStaticUrl(endpoint + staticUrl, regionAndFunc.region, itemListUrl, authKey); 475 | return util.makeRequest(url, 'Error getting static item list: ', null, regionAndFunc.callback); 476 | }; 477 | 478 | League.Static.getItemById = function(id, options, regionOrFunction, callback) { 479 | var itemListUrl = '/v1.2/item/' + id + '?', 480 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 481 | url; 482 | if (options) { 483 | if (options.itemData) { 484 | itemListUrl += '&itemData=' + options.itemData; 485 | } 486 | 487 | if (options.version) { 488 | itemListUrl += '&version=' + options.version; 489 | } 490 | 491 | if (options.locale) { 492 | itemListUrl += '&locale=' + options.locale; 493 | } 494 | itemListUrl += '&'; 495 | } 496 | url = util.craftStaticUrl(endpoint + staticUrl, regionAndFunc.region, itemListUrl, authKey); 497 | return util.makeRequest(url, 'Error getting static item by id: ', null, regionAndFunc.callback); 498 | }; 499 | 500 | League.Static.getMasteryList = function(options, regionOrFunction, callback) { 501 | var masteryListUrl = '/v1.2/mastery?', 502 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 503 | url; 504 | if (options) { 505 | if (options.masteryListData) { 506 | masteryListUrl += '&masteryListData=' + options.masteryListData; 507 | } 508 | 509 | if (options.version) { 510 | masteryListUrl += '&version=' + options.version; 511 | } 512 | 513 | if (options.locale) { 514 | masteryListUrl += '&locale=' + options.locale; 515 | } 516 | masteryListUrl += '&'; 517 | } 518 | url = util.craftStaticUrl(endpoint + staticUrl, regionAndFunc.region, masteryListUrl, authKey); 519 | return util.makeRequest(url, 'Error getting mastery list : ', null, regionAndFunc.callback); 520 | }; 521 | 522 | League.Static.getMasteryById = function(id, options, regionOrFunction, callback) { 523 | var masteryIdUrl = '/v1.2/mastery/' + id + '?', 524 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 525 | url; 526 | if (options) { 527 | if (options.masteryData) { 528 | masteryIdUrl += '&masteryData=' + options.masteryData; 529 | } 530 | 531 | if (options.version) { 532 | masteryIdUrl += '&version=' + options.version; 533 | } 534 | 535 | if (options.locale) { 536 | masteryIdUrl += '&locale=' + options.locale; 537 | } 538 | masteryIdUrl += '&'; 539 | } 540 | url = util.craftStaticUrl(endpoint + staticUrl, regionAndFunc.region, masteryIdUrl, authKey); 541 | return util.makeRequest(url, 'Error getting mastery by id: ', null, regionAndFunc.callback); 542 | }; 543 | 544 | League.Static.getRealm = function(regionOrFunction, callback) { 545 | var realmUrl = '/v1.2/realm?', 546 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 547 | url = util.craftStaticUrl(endpoint + staticUrl, regionAndFunc.region, realmUrl, authKey); 548 | return util.makeRequest(url, 'Error getting realm: ', null, regionAndFunc.callback); 549 | }; 550 | 551 | League.Static.getRuneList = function(options, regionOrFunction, callback) { 552 | var runeListUrl = '/v1.2/rune?', 553 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 554 | url; 555 | if (options) { 556 | if (options.runeListData) { 557 | runeListUrl += '&runeListData=' + options.runeListData; 558 | } 559 | 560 | if (options.version) { 561 | runeListUrl += '&version=' + options.version; 562 | } 563 | 564 | if (options.locale) { 565 | runeListUrl += '&locale=' + options.locale; 566 | } 567 | runeListUrl += '&'; 568 | } 569 | url = util.craftStaticUrl(endpoint + staticUrl, regionAndFunc.region, runeListUrl, authKey); 570 | return util.makeRequest(url, 'Error getting rune list : ', null, regionAndFunc.callback); 571 | }; 572 | 573 | League.Static.getRuneById= function(id, options, regionOrFunction, callback) { 574 | var runeListUrl = '/v1.2/rune/' + id + '?', 575 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 576 | url; 577 | if (options) { 578 | if (options.runeData) { 579 | runeListUrl += '&runeData=' + options.runeData; 580 | } 581 | 582 | if (options.version) { 583 | runeListUrl += '&version=' + options.version; 584 | } 585 | 586 | if (options.locale) { 587 | runeListUrl += '&locale=' + options.locale; 588 | } 589 | runeListUrl += '&'; 590 | } 591 | url = util.craftStaticUrl(endpoint + staticUrl, regionAndFunc.region, runeListUrl, authKey); 592 | return util.makeRequest(url, 'Error getting rune by id : ', null, regionAndFunc.callback); 593 | }; 594 | 595 | League.Static.getSummonerSpellList = function(options, regionOrFunction, callback) { 596 | var summonerSpellUrl = '/v1.2/summoner-spell?', 597 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 598 | url; 599 | if (options) { 600 | if (options.spellData) { 601 | summonerSpellUrl += '&spellData=' + options.spellData; 602 | } 603 | 604 | if (options.version) { 605 | summonerSpellUrl += '&version=' + options.version; 606 | } 607 | 608 | if (options.locale) { 609 | summonerSpellUrl += '&locale=' + options.locale; 610 | } 611 | 612 | if (options.dataById) { 613 | summonerSpellUrl += '&dataById=' + options.dataById; 614 | } 615 | summonerSpellUrl += '&'; 616 | } 617 | url = util.craftStaticUrl(endpoint + staticUrl, regionAndFunc.region, summonerSpellUrl, authKey); 618 | return util.makeRequest(url, 'Error getting summoner spell list : ', null, regionAndFunc.callback); 619 | }; 620 | 621 | League.Static.getSummonerSpellById = function(id, options, regionOrFunction, callback) { 622 | var summonerSpellUrl = '/v1.2/summoner-spell/' + id + '?', 623 | regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 624 | url; 625 | if (options) { 626 | if (options.spellData) { 627 | summonerSpellUrl += '&spellData=' + options.spellData; 628 | } 629 | 630 | if (options.version) { 631 | summonerSpellUrl += '&version=' + options.version; 632 | } 633 | 634 | if (options.locale) { 635 | summonerSpellUrl += '&locale=' + options.locale; 636 | } 637 | 638 | if (options.dataById) { 639 | summonerSpellUrl += '&dataById=' + options.dataById; 640 | } 641 | summonerSpellUrl += '&'; 642 | } 643 | url = util.craftStaticUrl(endpoint + staticUrl, regionAndFunc.region, summonerSpellUrl, authKey); 644 | return util.makeRequest(url, 'Error getting summoner spell by id : ', null, regionAndFunc.callback); 645 | }; 646 | 647 | League.Static.getVersions = function(regionOrFunction, callback) { 648 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback), 649 | url = util.craftStaticUrl(endpoint + staticUrl, regionAndFunc.region, '/v1.2/versions?', authKey); 650 | return util.makeRequest(url, 'Error getting versions: ', null, regionAndFunc.callback); 651 | }; 652 | 653 | League.Tournament.createProvider = function(region, callbackUrl, callback) { 654 | var url = util.craftTournamentUrl(tournamentEndpoint, 'provider?', authKey); 655 | return util.makeCustomRequest(url, 'POST', { 656 | region: region, 657 | url: callbackUrl 658 | }, 'Error creating tournament provider: ', null, callback); 659 | }; 660 | 661 | League.Tournament.createTournament = function(name, providerId, callback) { 662 | var url = util.craftTournamentUrl(tournamentEndpoint, 'tournament?', authKey); 663 | return util.makeCustomRequest(url, 'POST', { 664 | name: name, 665 | providerId: providerId 666 | }, 'Error creating tournament: ', null, callback); 667 | }; 668 | 669 | League.Tournament.createCode = function(tournamentId, count, options, callback) { 670 | var url = util.craftTournamentUrl(tournamentEndpoint, 'code?tournamentId=' + tournamentId + 671 | '&count=' + count + '&', authKey); 672 | 673 | var bodyData = {}; 674 | if (typeof options.teamSize != 'undefined') bodyData.teamSize = options.teamSize; 675 | if (typeof options.allowedSummonerIds != 'undefined') 676 | bodyData.allowedSummonerIds = {participants: options.allowedSummonerIds}; 677 | if (typeof options.spectatorType != 'undefined') bodyData.spectatorType = options.spectatorType; 678 | if (typeof options.pickType != 'undefined') bodyData.pickType = options.pickType; 679 | if (typeof options.mapType != 'undefined') bodyData.mapType = options.mapType; 680 | if (typeof options.metadata != 'undefined') bodyData.metadata = options.metadata; 681 | 682 | return util.makeCustomRequest(url, 'POST', bodyData, 'Error creating tournament code: ', null, callback); 683 | }; 684 | 685 | League.Tournament.updateCode = function(tournamentCode, options, callback) { 686 | var url = util.craftTournamentUrl(tournamentEndpoint, 'code/' + tournamentCode + '?', authKey); 687 | 688 | var bodyData = {}; 689 | if (typeof options.allowedParticipants != 'undefined') 690 | bodyData.allowedParticipants = options.allowedParticipants.join(','); 691 | if (typeof options.spectatorType != 'undefined') bodyData.spectatorType = options.spectatorType; 692 | if (typeof options.pickType != 'undefined') bodyData.pickType = options.pickType; 693 | if (typeof options.mapType != 'undefined') bodyData.mapType = options.mapType; 694 | 695 | return util.makeCustomRequest(url, 'PUT', bodyData, 'Error updating tournament code: ', null, callback); 696 | }; 697 | 698 | League.Tournament.getCode = function(tournamentCode, callback) { 699 | var url = util.craftTournamentUrl(tournamentEndpoint, 'code/' + tournamentCode + '?', authKey); 700 | 701 | return util.makeRequest(url, 'Error getting tournament code: ', null, callback); 702 | }; 703 | 704 | League.Tournament.getLobbyEventsByCode = function(tournamentCode, callback) { 705 | var url = util.craftTournamentUrl(tournamentEndpoint, 'lobby/events/by-code/' + tournamentCode + '?', authKey); 706 | 707 | return util.makeRequest(url, 'Error getting lobby events: ', null, callback); 708 | }; 709 | 710 | League.ChampionMastery.getChampions = function(playerId, regionOrFunction, callback) { 711 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback) 712 | 713 | return League.getPlatformId(regionAndFunc.region) 714 | .then(function(platformId) { 715 | var url = util.craftChampionMasteryUrl(championMasteryEndpoint, regionAndFunc.region, platformId, '/player/' + playerId + '/champions?', authKey); 716 | 717 | return util.makeRequest(url, 'Error getting champion mastery champions: ', null, regionAndFunc.callback); 718 | }); 719 | }; 720 | 721 | League.ChampionMastery.getChampion = function(playerId, championId, regionOrFunction, callback) { 722 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback) 723 | 724 | return League.getPlatformId(regionAndFunc.region) 725 | .then(function(platformId) { 726 | var url = util.craftChampionMasteryUrl(championMasteryEndpoint, regionAndFunc.region, platformId, '/player/' + playerId + '/champion/' + championId + '?', authKey); 727 | 728 | return util.makeRequest(url, 'Error getting champion mastery champions: ', null, regionAndFunc.callback); 729 | }); 730 | }; 731 | 732 | League.ChampionMastery.getScore = function(playerId, regionOrFunction, callback) { 733 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback) 734 | 735 | return League.getPlatformId(regionAndFunc.region) 736 | .then(function(platformId) { 737 | var url = util.craftChampionMasteryUrl(championMasteryEndpoint, regionAndFunc.region, platformId, '/player/' + playerId + '/score?', authKey); 738 | 739 | return util.makeRequest(url, 'Error getting champion mastery champions: ', null, regionAndFunc.callback); 740 | }); 741 | }; 742 | 743 | League.ChampionMastery.getTopChampions = function(playerId, count, regionOrFunction, callback) { 744 | var regionAndFunc = util.getCallbackAndRegion(regionOrFunction, region, callback); 745 | var countParameter = count ? 'count=' + count + '&' : ''; 746 | 747 | return League.getPlatformId(regionAndFunc.region) 748 | .then(function(platformId) { 749 | var url = util.craftChampionMasteryUrl(championMasteryEndpoint, regionAndFunc.region, platformId, '/player/' + playerId + '/topchampions?' + countParameter, authKey); 750 | 751 | return util.makeRequest(url, 'Error getting champion mastery champions: ', null, regionAndFunc.callback); 752 | }); 753 | }; 754 | 755 | module.exports = League; 756 | }()); 757 | --------------------------------------------------------------------------------