Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kindred-api

Package Overview
Dependencies
Maintainers
1
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kindred-api - npm Package Compare versions

Comparing version 1.1.4 to 1.1.5

178

dist/kindred-api.js

@@ -322,102 +322,118 @@ (function (global, factory) {

return new Promise(function (resolve, reject) {
var proxy = staticReq ? 'global' : region;
var reqUrl = _this._makeUrl(endUrl, proxy, staticReq, status, observerMode, championMastery);
var doAsync = function doAsync() {
return new Promise(function (resolve, reject) {
var proxy = staticReq ? 'global' : region;
var reqUrl = _this._makeUrl(endUrl, proxy, staticReq, status, observerMode, championMastery);
if (_this.limits) {
var self = _this;
if (_this.limits) {
var self = _this;
(function sendRequest(callback) {
if (self.canMakeRequest(region)) {
if (!staticReq) {
self.limits[region][0].addRequest();
self.limits[region][1].addRequest();
}
(function sendRequest(callback) {
if (self.canMakeRequest(region)) {
if (!staticReq) {
self.limits[region][0].addRequest();
self.limits[region][1].addRequest();
}
request({ url: reqUrl, qs: options }, function (error, response, body) {
if (response && body) {
var statusMessage = void 0;
var statusCode = response.statusCode;
request({ url: reqUrl, qs: options }, function (error, response, body) {
if (response && body) {
var statusMessage = void 0;
var statusCode = response.statusCode;
if (statusCode >= 200 && statusCode < 300) statusMessage = chalk.green(statusCode);else if (statusCode >= 400 && statusCode < 500) statusMessage = chalk.red(statusCode + ' ' + getResponseMessage(statusCode));else if (statusCode >= 500) statusMessage = chalk.bold.red(statusCode + ' ' + getResponseMessage(statusCode));
if (statusCode >= 200 && statusCode < 300) statusMessage = chalk.green(statusCode);else if (statusCode >= 400 && statusCode < 500) statusMessage = chalk.red(statusCode + ' ' + getResponseMessage(statusCode));else if (statusCode >= 500) statusMessage = chalk.bold.red(statusCode + ' ' + getResponseMessage(statusCode));
if (self.debug) {
console.log(statusMessage, reqUrl);
console.log({
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'],
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'],
'x-rate-limit-count': response.headers['x-rate-limit-count'],
'retry-after': response.headers['retry-after']
});
console.log();
}
if (callback) {
if (statusCode >= 500) {
if (self.debug) console.log('!!! resending request !!!');
setTimeout(function () {
sendRequest.bind(self)(callback);
}, 1000);
if (self.debug) {
console.log(statusMessage, reqUrl);
console.log({
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'],
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'],
'x-rate-limit-count': response.headers['x-rate-limit-count'],
'retry-after': response.headers['retry-after']
});
console.log();
}
if (statusCode === 429) {
if (self.debug) console.log('!!! resending request !!!');
setTimeout(function () {
sendRequest.bind(self)(callback);
}, response.headers['retry-after'] * 1000 + 50);
}
if (callback) {
if (statusCode >= 500) {
if (self.debug) console.log('!!! resending request !!!');
setTimeout(function () {
sendRequest.bind(self)(callback);
}, 1000);
}
if (statusCode >= 400) return callback(statusMessage + ' : ' + chalk.yellow(reqUrl));else return callback(error, JSON.parse(body));
} else {
if (error) {
return reject('err:', error);
if (statusCode === 429) {
if (self.debug) console.log('!!! resending request !!!');
setTimeout(function () {
sendRequest.bind(self)(callback);
}, response.headers['retry-after'] * 1000 + 50);
}
if (statusCode >= 400) return callback(statusMessage + ' : ' + chalk.yellow(reqUrl));else return callback(error, JSON.parse(body));
} else {
return resolve(JSON.parse(body));
if (statusCode === 429) {
if (self.debug) console.log('!!! resending promise request !!!');
setTimeout(function () {
return reject('retry');
}, 1000);
} else if (statusCode === 429) {
if (self.debug) console.log('!!! resending promise request !!!');
setTimeout(function () {
return reject('retry');
}, response.headers['retry-after'] * 1000 + 50);
} else if (error || statusCode >= 400) {
return reject('err:', error, statusCode);
} else {
return resolve(JSON.parse(body));
}
}
} else {
console.log(error, reqUrl);
}
} else {
console.log(error, reqUrl);
}
});
} else {
setTimeout(function () {
sendRequest.bind(self)(callback);
}, 1000);
}
})(cb);
} else {
request({ url: reqUrl, qs: options }, function (error, response, body) {
if (response) {
var statusMessage = void 0;
var statusCode = response.statusCode;
});
} else {
setTimeout(function () {
sendRequest.bind(self)(callback);
}, 1000);
}
})(cb);
} else {
request({ url: reqUrl, qs: options }, function (error, response, body) {
if (response) {
var statusMessage = void 0;
var statusCode = response.statusCode;
if (statusCode >= 200 && statusCode < 300) statusMessage = chalk.green(statusCode);else if (statusCode >= 400 && statusCode < 500) statusMessage = chalk.red(statusCode + ' ' + getResponseMessage(statusCode));else if (statusCode >= 500) statusMessage = chalk.bold.red(statusCode + ' ' + getResponseMessage(statusCode));
if (statusCode >= 200 && statusCode < 300) statusMessage = chalk.green(statusCode);else if (statusCode >= 400 && statusCode < 500) statusMessage = chalk.red(statusCode + ' ' + getResponseMessage(statusCode));else if (statusCode >= 500) statusMessage = chalk.bold.red(statusCode + ' ' + getResponseMessage(statusCode));
if (_this.debug) {
console.log(response && statusMessage, reqUrl);
console.log({
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'],
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'],
'x-rate-limit-count': response.headers['x-rate-limit-count'],
'retry-after': response.headers['retry-after']
});
}
if (_this.debug) {
console.log(response && statusMessage, reqUrl);
console.log({
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'],
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'],
'x-rate-limit-count': response.headers['x-rate-limit-count'],
'retry-after': response.headers['retry-after']
});
}
if (cb) {
if (statusCode >= 400) return cb(statusMessage + ' : ' + chalk.yellow(reqUrl));else return cb(error, JSON.parse(body));
} else {
if (error) {
return reject('err:', error);
if (cb) {
if (statusCode >= 400) return cb(statusMessage + ' : ' + chalk.yellow(reqUrl));else return cb(error, JSON.parse(body));
} else {
return resolve(JSON.parse(body));
if (error) {
return reject('err:', error);
} else {
return resolve(JSON.parse(body));
}
}
} else {
console.log(error, reqUrl);
}
} else {
console.log(error, reqUrl);
}
});
}
});
});
}
});
};
if (!cb) return doAsync().catch(doAsync).catch(doAsync).catch(doAsync).then(function (data) {
return data;
});else return doAsync();
}

@@ -424,0 +440,0 @@ }, {

@@ -1,1 +0,1 @@

!function(e,r){if("function"==typeof define&&define.amd)define("kindred-api",["module","double-ended-queue","request","chalk","xregexp"],r);else if("undefined"!=typeof exports)r(module,require("double-ended-queue"),require("request"),require("chalk"),require("xregexp"));else{var n={exports:{}};r(n,e.doubleEndedQueue,e.request,e.chalk,e.xregexp),e.kindredApi=n.exports}}(this,function(e,r,n,t,i){"use strict";function o(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=function(){function e(e,r){for(var n=0;n<r.length;n++){var t=r[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}return function(r,n,t){return n&&e(r.prototype,n),t&&e(r,t),r}}(),u=function(){function e(n,t){o(this,e),this.allowedRequests=n,this.seconds=t,this.madeRequests=new r}return a(e,[{key:"__reload",value:function(){for(var e=(new Date).getTime();this.madeRequests.length>0&&e-this.madeRequests.peekFront()>=1e3*this.seconds;)this.madeRequests.shift()}},{key:"addRequest",value:function(){this.madeRequests.push((new Date).getTime()+1e3*this.seconds)}},{key:"requestAvailable",value:function(){return this.__reload(),this.madeRequests.length<this.allowedRequests}}]),e}(),l={BRAZIL:"BR1",EUROPE:"EUN1",EUROPE_WEST:"EUW1",KOREA:"KR",LATIN_AMERICA_NORTH:"LA1",LATIN_AMERICA_SOUTH:"LA2",NORTH_AMERICA:"NA1",OCEANIA:"OC1",RUSSIA:"RU",TURKEY:"TR1",JAPAN:"JP1"},m={BRAZIL:"br",EUROPE:"eune",EUROPE_WEST:"euw",KOREA:"kr",LATIN_AMERICA_NORTH:"lan",LATIN_AMERICA_SOUTH:"las",NORTH_AMERICA:"na",OCEANIA:"oce",RUSSIA:"ru",TURKEY:"tr",JAPAN:"jp"},d={br:"BRAZIL",eune:"EUROPE",euw:"EUROPE_WEST",kr:"KOREA",lan:"LATIN_AMERICA_NORTH",las:"LATIN_AMERICA_SOUTH",na:"NORTH_AMERICA",oce:"OCEANIA",ru:"RUSSIA",tr:"TURKEY",jp:"JAPAN"},g={CHAMPION:1.2,CURRENT_GAME:1,FEATURED_GAMES:1,GAME:1.3,LEAGUE:2.5,STATIC_DATA:1.2,STATUS:1,MATCH:2.2,MATCH_LIST:2.2,RUNES_MASTERIES:1.4,STATS:1.3,SUMMONER:1.4},h={int:function(e){return e.every(function(e){return Number.isInteger(e)})},string:function(e){return e.every(function(e){return"string"==typeof e})}},p={int:function(e){return e&&Array.isArray(e)&&h.int(e)&&e.length>0},string:function(e){return e&&Array.isArray(e)&&h.string(e)&&e.length>0}},y={400:"Bad Request",403:"Forbidden",404:"Not Found",415:"Unsupported Media Type",429:"Rate Limit Exceeded",500:"Internal Service Error",503:"Service Unavailable"},c=function(e){var r=y[e];if(r)return r},v=i("^[0-9\\p{L} _\\.]+$"),f=function(){function e(r){var n=r.key,i=r.defaultRegion,s=void 0===i?m.NORTH_AMERICA:i,a=r.debug,l=void 0!==a&&a,d=r.limits;o(this,e),this.key=n;var g=void 0,h=!0,y=!1,c=void 0;try{for(var v,f=Object.keys(m)[Symbol.iterator]();!(h=(v=f.next()).done);h=!0){var I=v.value;m[I]===s&&(g=!0)}}catch(e){y=!0,c=e}finally{try{!h&&f.return&&f.return()}finally{if(y)throw c}}if(this.defaultRegion=g?s:void 0,this.defaultRegion||(console.log(""+t.red("Initialization of Kindred failed: "+t.yellow(s)+" is an invalid region.")),console.log(""+t.red("Try importing "+t.yellow("require('./dist/kindred-api').REGIONS")+" and using one of those values instead.")),process.exit(1)),this.debug=l,d){(Array.isArray(d)&&2!==d.length||!p.int(d[0])||2!==d[0].length||!p.int(d[1])||2!==d[1].length)&&"dev"!==d&&"prod"!==d&&(console.log(t.red("Initialization of Kindred failed: Invalid "+t.yellow("limits")+". Valid examples: "+t.yellow("[[10, 10], [500, 600]]"))+"."),console.log(t.red("You can also pass in one of these two strings:")+" dev/prod "),console.log(""+t.red("and Kindred will set the limits appropriately.")),process.exit(1)),this.limits={},"dev"===d&&(d=[[10,10],[500,600]]),"prod"===d&&(d=[[3e3,10],[18e4,600]]);var R=!0,_=!1,q=void 0;try{for(var U,D=Object.keys(m)[Symbol.iterator]();!(R=(U=D.next()).done);R=!0){var b=U.value;this.limits[m[b]]=[new u(d[0][0],d[0][1]),new u(d[1][0],d[1][1])]}}catch(e){_=!0,q=e}finally{try{!R&&D.return&&D.return()}finally{if(_)throw q}}}}return a(e,[{key:"canMakeRequest",value:function(e){return!(!this.limits[e][0].requestAvailable()||!this.limits[e][1].requestAvailable())}},{key:"_sanitizeName",value:function(e){if(this._validName(e))return e.replace(/\s/g,"").toLowerCase();this._logError(this._validName.name,"Name "+t.yellow(e)+" is not valid. Request failed."),process.exit(1)}},{key:"_validName",value:function(e){return v.test(e)}},{key:"_makeUrl",value:function(e,r,n,t,i,o){var s=n?"":r+"/";return"https://"+r+".api.riotgames.com/"+(t||i||o?"":"api/lol/"+s)+encodeURI(e)+"?api_key="+this.key}},{key:"_baseRequest",value:function(e,r){var i=this,o=e.endUrl,s=e.region,a=void 0===s?this.defaultRegion:s,u=e.status,l=void 0!==u&&u,m=e.observerMode,d=void 0!==m&&m,g=e.staticReq,h=void 0!==g&&g,p=e.championMastery,y=void 0!==p&&p,v=e.options,f=void 0===v?{}:v;return new Promise(function(e,s){var u=h?"global":a,m=i._makeUrl(o,u,h,l,d,y);if(i.limits){var g=i;!function r(i){g.canMakeRequest(a)?(h||(g.limits[a][0].addRequest(),g.limits[a][1].addRequest()),n({url:m,qs:f},function(n,o,a){if(o&&a){var u=void 0,l=o.statusCode;return l>=200&&l<300?u=t.green(l):l>=400&&l<500?u=t.red(l+" "+c(l)):l>=500&&(u=t.bold.red(l+" "+c(l))),g.debug&&(console.log(u,m),console.log({"x-app-rate-limit-count":o.headers["x-app-rate-limit-count"],"x-method-rate-limit-count":o.headers["x-method-rate-limit-count"],"x-rate-limit-count":o.headers["x-rate-limit-count"],"retry-after":o.headers["retry-after"]}),console.log()),i?(l>=500&&(g.debug&&console.log("!!! resending request !!!"),setTimeout(function(){r.bind(g)(i)},1e3)),429===l&&(g.debug&&console.log("!!! resending request !!!"),setTimeout(function(){r.bind(g)(i)},1e3*o.headers["retry-after"]+50)),l>=400?i(u+" : "+t.yellow(m)):i(n,JSON.parse(a))):n?s("err:",n):e(JSON.parse(a))}console.log(n,m)})):setTimeout(function(){r.bind(g)(i)},1e3)}(r)}else n({url:m,qs:f},function(n,o,a){if(o){var u=void 0,l=o.statusCode;return l>=200&&l<300?u=t.green(l):l>=400&&l<500?u=t.red(l+" "+c(l)):l>=500&&(u=t.bold.red(l+" "+c(l))),i.debug&&(console.log(o&&u,m),console.log({"x-app-rate-limit-count":o.headers["x-app-rate-limit-count"],"x-method-rate-limit-count":o.headers["x-method-rate-limit-count"],"x-rate-limit-count":o.headers["x-rate-limit-count"],"retry-after":o.headers["retry-after"]})),r?l>=400?r(u+" : "+t.yellow(m)):r(n,JSON.parse(a)):n?s("err:",n):e(JSON.parse(a))}console.log(n,m)})})}},{key:"_observerRequest",value:function(e,r){var n=e.endUrl,t=e.region;return this._baseRequest({endUrl:"observer-mode/rest/"+n,observerMode:!0,region:t},r)}},{key:"_championRequest",value:function(e,r){var n=e.endUrl,t=e.region,i=e.options;return this._baseRequest({endUrl:"v"+g.CHAMPION+"/"+n,region:t,options:i},r)}},{key:"_championMasteryRequest",value:function(e,r){var n=e.endUrl,t=(e.region,e.options);return this._baseRequest({endUrl:"championmastery/location/"+n,options:t,championMastery:!0},r)}},{key:"_currentGameRequest",value:function(e,r){var n=e.endUrl,t=e.region,i=e.platformId;return this._observerRequest({endUrl:"consumer/getSpectatorGameInfo/"+i+"/"+n,region:t},r)}},{key:"_staticRequest",value:function(e,r){var n=e.endUrl,t=e.region,i=void 0===t?this.defaultRegion:t,o=e.options;return this._baseRequest({endUrl:"static-data/"+i+"/v"+g.STATIC_DATA+"/"+n,staticReq:!0,region:i,options:o},r)}},{key:"_statusRequest",value:function(e,r){var n=e.endUrl,t=(e.region,e.options);return this._baseRequest({endUrl:"lol/status/v"+g.STATUS+"/"+n,status:!0,options:t},r)}},{key:"_gameRequest",value:function(e,r){var n=e.endUrl,t=e.region;return this._baseRequest({endUrl:"v"+g.GAME+"/game/"+n,region:t},r)}},{key:"_leagueRequest",value:function(e,r){var n=e.endUrl,t=e.region,i=e.options;return this._baseRequest({endUrl:"v"+g.LEAGUE+"/league/"+n,region:t,options:i},r)}},{key:"_matchRequest",value:function(e,r){var n=e.endUrl,t=e.region,i=e.options;return this._baseRequest({endUrl:"v"+g.MATCH+"/match/"+n,region:t,options:i},r)}},{key:"_matchListRequest",value:function(e,r){var n=e.endUrl,t=e.region,i=e.options;return this._baseRequest({endUrl:"v"+g.MATCH_LIST+"/matchlist/by-summoner/"+n,region:t,options:i},r)}},{key:"_runesMasteriesRequest",value:function(e,r){var n=e.endUrl,t=e.region;return this._summonerRequest({endUrl:n,region:t},r)}},{key:"_statsRequest",value:function(e,r){var n=e.endUrl,t=e.region,i=e.options;return this._baseRequest({endUrl:"v"+g.STATS+"/stats/by-summoner/"+n,region:t,options:i},r)}},{key:"_summonerRequest",value:function(e,r){var n=e.endUrl,t=e.region;return this._baseRequest({endUrl:"v"+g.SUMMONER+"/summoner/"+n,region:t},r)}},{key:"_logError",value:function(e,r){console.log(t.bold.yellow(e),t.red("request"),t.bold.red("FAILED")+t.red("; "+r))}},{key:"setRegion",value:function(e){this.defaultRegion=e}},{key:"getChamps",value:function(e,r){var n=e.region,t=e.options;return this._championRequest({endUrl:"champion",region:n,options:t},r=n||t?r:arguments[0])}},{key:"getChamp",value:function(e,r){var n=e.region,i=e.id,o=e.championID;return Number.isInteger(i)||Number.isInteger(o)?this._championRequest({endUrl:"champion/"+(i||o),region:n},r):this._logError(this.getChamp.name,"required params "+t.yellow("`id/championID` (int)")+" not passed in")}},{key:"getChampMastery",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=void 0===r?this.defaultRegion:r,i=e.playerID,o=e.championID,s=e.options,a=arguments[1];if(Number.isInteger(i)&&Number.isInteger(o)){var u=l[d[n]];return this._championMasteryRequest({endUrl:u+"/player/"+i+"/champion/"+o,region:n,options:s},a)}return this._logError(this.getChampMastery.name,"required params "+t.yellow("`playerID` (int) AND `championID` (int)")+" not passed in")}},{key:"getChampMasteries",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=void 0===n?this.defaultRegion:n,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,g=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[d[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/champions",region:i,options:g},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[d[i]];return this.getSummoner({name:m,region:i},function(r,n){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+n[e._sanitizeName(m)].id+"/champions",region:i},h)})}return this._logError(this.getChampMasteries.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (str)")+" not passed in")}},{key:"getTotalChampMasteryScore",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=void 0===n?this.defaultRegion:n,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,g=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[d[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/score",region:i,options:g},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[d[i]];return this.getSummoner({name:m,region:i},function(r,n){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+n[e._sanitizeName(m)].id+"/score",region:i},h)})}return this._logError(this.getTotalChampMasteryScore.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (str)")+" not passed in")}},{key:"getTopChamps",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=void 0===n?this.defaultRegion:n,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,g=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[d[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/topchampions",region:i,options:g},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[d[i]];return this.getSummoner({name:m,region:i},function(r,n){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+n[e._sanitizeName(m)].id+"/topchampions",region:i},h)})}return this._logError(this.getTopChamps.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (str)")+" not passed in")}},{key:"getCurrentGame",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=void 0===n?this.defaultRegion:n,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,g=arguments[1],h=l[d[i]];return Number.isInteger(o||a||u)?this._currentGameRequest({endUrl:""+(o||a||u),platformId:h,region:i},g):"object"===s(arguments[0])&&"string"==typeof m?this.getSummoner({name:m,region:i},function(r,n){return r?g(r):e._currentGameRequest({endUrl:""+n[e._sanitizeName(m)].id,platformId:h,region:i},g)}):this._logError(this.getCurrentGame.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (string)")+" not passed in")}},{key:"getFeaturedGames",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=arguments[1];return this._observerRequest({endUrl:"featured",region:r},n=r?n:arguments[0])}},{key:"getRecentGames",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=arguments[1];return Number.isInteger(i||o||a)?this._gameRequest({endUrl:"by-summoner/"+(i||o||a)+"/recent",region:n},l):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:n},function(r,t){return r?l(r):e._gameRequest({endUrl:"by-summoner/"+t[e._sanitizeName(u)].id+"/recent",region:n},l)}):this._logError(this.getRecentGames.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (string)")+" not passed in")}},{key:"getLeagues",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,d=r.names,g=r.name,h=arguments[1];return p.int(i||a||l)?this._leagueRequest({endUrl:"by-summoner/"+(i||a||l).join(","),region:n},h):Number.isInteger(i||o||a||u||l||m)?this._leagueRequest({endUrl:"by-summoner/"+(i||o||a||u||l||m),region:n},h):p.string(d)?this.getSummoners({names:d,region:n},function(r,t){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=d[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(t[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._leagueRequest({endUrl:"by-summoner/"+i.join(","),region:n},h)}):"object"!==s(arguments[0])||"string"!=typeof d&&"string"!=typeof g?this._logError(this.getLeagues.name,"required params "+t.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+t.yellow("`id/summonerID/playerID` (int)")+", "+t.yellow("`names` ([str]/str)")+", or "+t.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:d||g,region:n},function(r,t){return r?h(r):e._leagueRequest({endUrl:"by-summoner/"+t[e._sanitizeName(d||g)].id,region:n},h)})}},{key:"getLeagueEntries",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,d=r.names,g=r.name,h=arguments[1];return p.int(i||a||l)?this._leagueRequest({endUrl:"by-summoner/"+(i||a||l).join(",")+"/entry",region:n},h):Number.isInteger(i||o||a||u||l||m)?this._leagueRequest({endUrl:"by-summoner/"+(i||o||a||u||l||m)+"/entry",region:n},h):p.string(d)?this.getSummoners({names:d,region:n},function(r,t){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=d[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(t[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._leagueRequest({endUrl:"by-summoner/"+i.join(",")+"/entry",region:n},h)}):"object"!==s(arguments[0])||"string"!=typeof d&&"string"!=typeof g?void this._logError(this.getLeagueEntries.name,"required params "+t.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+t.yellow("`id/summonerID/playerID` (int)")+", "+t.yellow("`names` ([str]/str)")+", or "+t.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:d||g,region:n},function(r,t){return r?h(r):e._leagueRequest({endUrl:"by-summoner/"+t[e._sanitizeName(d||g)].id+"/entry",region:n},h)})}},{key:"getChallengers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=void 0===n?{type:"RANKED_SOLO_5x5"}:n,i=arguments[1];return this._leagueRequest({endUrl:"challenger",region:r,options:t},i=r?i:arguments[0])}},{key:"getMasters",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=void 0===n?{type:"RANKED_SOLO_5x5"}:n,i=arguments[1];return this._leagueRequest({endUrl:"master",region:r,options:t},i=r?i:arguments[0])}},{key:"getChampionList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"champion",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getChampion",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.id,i=e.championID,o=e.options,s=arguments[1];return Number.isInteger(n||i)?this._staticRequest({endUrl:"champion/"+(n||i),region:r,options:o},s):this._logError(this.getChampion.name,"required params "+t.yellow("`id/championID` (int)")+" not passed in")}},{key:"getItems",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"item",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getItem",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.id,i=e.itemID,o=e.options,s=arguments[1];return Number.isInteger(n||i)?this._staticRequest({endUrl:"item/"+(n||i),region:r,options:o},s):this._logError(this.getItem.name,"required params "+t.yellow("`id/itemID` (int)")+" not passed in")}},{key:"getLanguageStrings",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"language-strings",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getLanguages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=arguments[1];return this._staticRequest({endUrl:"languages",region:r},n=r?n:arguments[0])}},{key:"getMap",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"map",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getMasteryList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"mastery",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getMastery",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.id,i=e.masteryID,o=e.options,s=arguments[1];return Number.isInteger(n||i)?this._staticRequest({endUrl:"mastery/"+(n||i),region:r,options:o},s):this._logError(this.getMastery.name,"required params "+t.yellow("`id/masteryID` (int)")+" not passed in")}},{key:"getRealmData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=arguments[1];return this._staticRequest({endUrl:"realm",region:r},n=r?n:arguments[0])}},{key:"getRuneList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"rune",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getRune",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.id,i=e.runeID,o=e.options,s=arguments[1];return Number.isInteger(n||i)?this._staticRequest({endUrl:"rune/"+(n||i),region:r,options:o},s):this._logError(this.getRune.name,"required params "+t.yellow("`id/runeID` (int)")+" not passed in")}},{key:"getSummonerSpells",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"summoner-spell",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getSummonerSpell",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.id,i=e.spellID,o=e.summonerSpellID,s=e.options,a=arguments[1];return Number.isInteger(n||i||o)?this._staticRequest({endUrl:"summoner-spell/"+(n||i||o),region:r,options:s},a):this._logError(this.getSummonerSpell.name,"required params "+t.yellow("`id/spellID/summonerSpellID` (int)")+" not passed in")}},{key:"getVersionData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.options,t=arguments[1];return this._staticRequest({endUrl:"versions",region:r,options:n},t=r||n?t:arguments[0])}},{key:"getShardStatus",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=arguments[1];return this._statusRequest({endUrl:"shard",region:r},n=r?n:arguments[0])}},{key:"getShardList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=arguments[1];return this._statusRequest({endUrl:"shards",region:r},n=r?n:arguments[0])}},{key:"getMatch",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.id,i=e.matchID,o=e.options,s=void 0===o?{includeTimeline:!0}:o,a=arguments[1];return Number.isInteger(n||i)?this._matchRequest({endUrl:""+(n||i),region:r,options:s},a):this._logError(this.getMatch.name,"required params "+t.yellow("`id/matchID` (int)")+" not passed in")}},{key:"getMatchList",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=r.options,m=void 0===l?{rankedQueues:"RANKED_SOLO_5x5"}:l,d=arguments[1];return Number.isInteger(i||o||a)?this._matchListRequest({endUrl:""+(i||o||a),region:n,options:m},d):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:n},function(r,t){return r?d(r):e._matchListRequest({endUrl:""+t[e._sanitizeName(u)].id,region:n,options:m},d)}):this._logError(this.getMatchList.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (str)")+" not passed in")}},{key:"getRunes",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,d=r.names,g=r.name,h=arguments[1];return p.int(i||a||l)?this._runesMasteriesRequest({endUrl:(i||a||l).join()+"/runes",region:n},h):Number.isInteger(i||o||a||u||l||m)?this._runesMasteriesRequest({endUrl:(i||o||a||u||l||m)+"/runes",region:n},h):p.string(d)?this.getSummoners({names:d,region:n},function(r,t){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=d[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(t[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._runesMasteriesRequest({endUrl:i.join(",")+"/runes",region:n},h)}):"object"!==s(arguments[0])||"string"!=typeof d&&"string"!=typeof g?this._logError(this.getRunes.name,"required params "+t.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+t.yellow("`id/summonerID/playerID` (int)")+", "+t.yellow("`names` ([str]/str)")+", or "+t.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:d||g,region:n},function(r,t){return r?h(r):e._runesMasteriesRequest({endUrl:t[e._sanitizeName(d||g)].id+"/runes",region:n},h)})}},{key:"getMasteries",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,d=r.names,g=r.name,h=arguments[1];return p.int(i||a||l)?this._runesMasteriesRequest({endUrl:(i||a||l).join()+"/masteries",region:n},h):Number.isInteger(i||o||a||u||l||m)?this._runesMasteriesRequest({endUrl:(i||o||a||u||l||m)+"/masteries",region:n},h):p.string(d)?this.getSummoners({names:d,region:n},function(r,t){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=d[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(t[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._runesMasteriesRequest({endUrl:i.join(",")+"/masteries",region:n},h)}):"object"!==s(arguments[0])||"string"!=typeof d&&"string"!=typeof g?this._logError(this.getMasteries.name,"required params "+t.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+t.yellow("`id/summonerID/playerID` (int)")+", "+t.yellow("`names` ([str]/str)")+", or "+t.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:d||g,region:n},function(r,t){return r?h(r):e._runesMasteriesRequest({endUrl:t[e._sanitizeName(d||g)].id+"/masteries",region:n},h)})}},{key:"getRankedStats",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=r.options,m=arguments[1];return Number.isInteger(i||o||a)?this._statsRequest({endUrl:(i||o||a)+"/ranked",region:n,options:l},m):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:n},function(r,t){return r?m(r):e._statsRequest({endUrl:t[e._sanitizeName(u)].id+"/ranked",region:n,options:l},m)}):void this._logError(this.getRankedStats.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (string)")+" not passed in")}},{key:"getStatsSummary",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=r.options,m=arguments[1];return Number.isInteger(i||o||a)?this._statsRequest({endUrl:(i||o||a)+"/summary",region:n,options:l},m):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:n},function(r,t){return r?m(r):e._statsRequest({endUrl:t[e._sanitizeName(u)].id+"/summary",region:n,options:l},m)}):void this._logError(this.getRankedStats.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (string)")+" not passed in")}},{key:"getSummoners",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,d=r.names,g=r.name,h=arguments[1];return p.int(i||a||l)?this._summonerRequest({endUrl:""+(i||a||l).join(","),region:n},h):Number.isInteger(i||o||a||u||l||m)?this._summonerRequest({endUrl:""+(i||o||a||u||l||m),region:n},h):p.string(d)?this._summonerRequest({endUrl:"by-name/"+d.map(function(r){return e._sanitizeName(r)}).join(","),region:n},h):"object"!==s(arguments[0])||"string"!=typeof d&&"string"!=typeof g?void this._logError(this.getSummoners.name,"required params "+t.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+t.yellow("`id/summonerID/playerID` (int)")+", "+t.yellow("`names` ([str]/str)")+", or "+t.yellow("`name` (str)")+" not passed in"):this._summonerRequest({endUrl:"by-name/"+this._sanitizeName(d||g),region:n},h)}},{key:"getSummoner",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.id,i=e.summonerID,o=e.playerID,a=e.name,u=arguments[1];return Number.isInteger(n||i||o)?this.getSummoners({region:r,ids:[n||i||o]},u):"object"===s(arguments[0])&&"string"==typeof a?this.getSummoners({region:r,names:[a]},u):this._logError(this.getSummoner.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" or "+t.yellow("`name` (string)")+" not passed in")}},{key:"getSummonerNames",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.ids,i=e.id,o=e.summonerIDs,s=e.summonerID,a=e.playerIDs,u=e.playerID,l=arguments[1];return p.int(n||o||a)?this._summonerRequest({endUrl:(n||o||a).join(",")+"/name",region:r},l):Number.isInteger(n||i||o||s||a||u)?this._summonerRequest({endUrl:(n||i||o||s||a||u)+"/name",region:r},l):void this._logError(this.getSummonerNames.name,"required params "+t.yellow("required params `ids/summonerIDs/playerIDs` ([int]/int)")+" or "+t.yellow("`id/summonerID/playerID` (int)")+" not passed in")}},{key:"getSummonerName",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,n=e.id,i=e.summonerID,o=e.playerID,s=arguments[1];if(Number.isInteger(n))return this.getSummonerNames({region:r,id:n||i||o},s);this._logError(this.getSummonerName.name,"required params "+t.yellow("`id/summonerID/playerID` (int)")+" not passed in")}}]),e}(),I={Kindred:f,REGIONS:m};e.exports=I});
!function(e,r){if("function"==typeof define&&define.amd)define("kindred-api",["module","double-ended-queue","request","chalk","xregexp"],r);else if("undefined"!=typeof exports)r(module,require("double-ended-queue"),require("request"),require("chalk"),require("xregexp"));else{var t={exports:{}};r(t,e.doubleEndedQueue,e.request,e.chalk,e.xregexp),e.kindredApi=t.exports}}(this,function(e,r,t,n,i){"use strict";function o(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),u=function(){function e(t,n){o(this,e),this.allowedRequests=t,this.seconds=n,this.madeRequests=new r}return a(e,[{key:"__reload",value:function(){for(var e=(new Date).getTime();this.madeRequests.length>0&&e-this.madeRequests.peekFront()>=1e3*this.seconds;)this.madeRequests.shift()}},{key:"addRequest",value:function(){this.madeRequests.push((new Date).getTime()+1e3*this.seconds)}},{key:"requestAvailable",value:function(){return this.__reload(),this.madeRequests.length<this.allowedRequests}}]),e}(),l={BRAZIL:"BR1",EUROPE:"EUN1",EUROPE_WEST:"EUW1",KOREA:"KR",LATIN_AMERICA_NORTH:"LA1",LATIN_AMERICA_SOUTH:"LA2",NORTH_AMERICA:"NA1",OCEANIA:"OC1",RUSSIA:"RU",TURKEY:"TR1",JAPAN:"JP1"},m={BRAZIL:"br",EUROPE:"eune",EUROPE_WEST:"euw",KOREA:"kr",LATIN_AMERICA_NORTH:"lan",LATIN_AMERICA_SOUTH:"las",NORTH_AMERICA:"na",OCEANIA:"oce",RUSSIA:"ru",TURKEY:"tr",JAPAN:"jp"},g={br:"BRAZIL",eune:"EUROPE",euw:"EUROPE_WEST",kr:"KOREA",lan:"LATIN_AMERICA_NORTH",las:"LATIN_AMERICA_SOUTH",na:"NORTH_AMERICA",oce:"OCEANIA",ru:"RUSSIA",tr:"TURKEY",jp:"JAPAN"},d={CHAMPION:1.2,CURRENT_GAME:1,FEATURED_GAMES:1,GAME:1.3,LEAGUE:2.5,STATIC_DATA:1.2,STATUS:1,MATCH:2.2,MATCH_LIST:2.2,RUNES_MASTERIES:1.4,STATS:1.3,SUMMONER:1.4},h={int:function(e){return e.every(function(e){return Number.isInteger(e)})},string:function(e){return e.every(function(e){return"string"==typeof e})}},p={int:function(e){return e&&Array.isArray(e)&&h.int(e)&&e.length>0},string:function(e){return e&&Array.isArray(e)&&h.string(e)&&e.length>0}},y={400:"Bad Request",403:"Forbidden",404:"Not Found",415:"Unsupported Media Type",429:"Rate Limit Exceeded",500:"Internal Service Error",503:"Service Unavailable"},c=function(e){var r=y[e];if(r)return r},v=i("^[0-9\\p{L} _\\.]+$"),f=function(){function e(r){var t=r.key,i=r.defaultRegion,s=void 0===i?m.NORTH_AMERICA:i,a=r.debug,l=void 0!==a&&a,g=r.limits;o(this,e),this.key=t;var d=void 0,h=!0,y=!1,c=void 0;try{for(var v,f=Object.keys(m)[Symbol.iterator]();!(h=(v=f.next()).done);h=!0){var I=v.value;m[I]===s&&(d=!0)}}catch(e){y=!0,c=e}finally{try{!h&&f.return&&f.return()}finally{if(y)throw c}}if(this.defaultRegion=d?s:void 0,this.defaultRegion||(console.log(""+n.red("Initialization of Kindred failed: "+n.yellow(s)+" is an invalid region.")),console.log(""+n.red("Try importing "+n.yellow("require('./dist/kindred-api').REGIONS")+" and using one of those values instead.")),process.exit(1)),this.debug=l,g){(Array.isArray(g)&&2!==g.length||!p.int(g[0])||2!==g[0].length||!p.int(g[1])||2!==g[1].length)&&"dev"!==g&&"prod"!==g&&(console.log(n.red("Initialization of Kindred failed: Invalid "+n.yellow("limits")+". Valid examples: "+n.yellow("[[10, 10], [500, 600]]"))+"."),console.log(n.red("You can also pass in one of these two strings:")+" dev/prod "),console.log(""+n.red("and Kindred will set the limits appropriately.")),process.exit(1)),this.limits={},"dev"===g&&(g=[[10,10],[500,600]]),"prod"===g&&(g=[[3e3,10],[18e4,600]]);var R=!0,_=!1,q=void 0;try{for(var U,D=Object.keys(m)[Symbol.iterator]();!(R=(U=D.next()).done);R=!0){var b=U.value;this.limits[m[b]]=[new u(g[0][0],g[0][1]),new u(g[1][0],g[1][1])]}}catch(e){_=!0,q=e}finally{try{!R&&D.return&&D.return()}finally{if(_)throw q}}}}return a(e,[{key:"canMakeRequest",value:function(e){return!(!this.limits[e][0].requestAvailable()||!this.limits[e][1].requestAvailable())}},{key:"_sanitizeName",value:function(e){if(this._validName(e))return e.replace(/\s/g,"").toLowerCase();this._logError(this._validName.name,"Name "+n.yellow(e)+" is not valid. Request failed."),process.exit(1)}},{key:"_validName",value:function(e){return v.test(e)}},{key:"_makeUrl",value:function(e,r,t,n,i,o){var s=t?"":r+"/";return"https://"+r+".api.riotgames.com/"+(n||i||o?"":"api/lol/"+s)+encodeURI(e)+"?api_key="+this.key}},{key:"_baseRequest",value:function(e,r){var i=this,o=e.endUrl,s=e.region,a=void 0===s?this.defaultRegion:s,u=e.status,l=void 0!==u&&u,m=e.observerMode,g=void 0!==m&&m,d=e.staticReq,h=void 0!==d&&d,p=e.championMastery,y=void 0!==p&&p,v=e.options,f=void 0===v?{}:v,I=function(){return new Promise(function(e,s){var u=h?"global":a,m=i._makeUrl(o,u,h,l,g,y);if(i.limits){var d=i;!function r(i){d.canMakeRequest(a)?(h||(d.limits[a][0].addRequest(),d.limits[a][1].addRequest()),t({url:m,qs:f},function(t,o,a){if(o&&a){var u=void 0,l=o.statusCode;if(l>=200&&l<300?u=n.green(l):l>=400&&l<500?u=n.red(l+" "+c(l)):l>=500&&(u=n.bold.red(l+" "+c(l))),d.debug&&(console.log(u,m),console.log({"x-app-rate-limit-count":o.headers["x-app-rate-limit-count"],"x-method-rate-limit-count":o.headers["x-method-rate-limit-count"],"x-rate-limit-count":o.headers["x-rate-limit-count"],"retry-after":o.headers["retry-after"]}),console.log()),i)return l>=500&&(d.debug&&console.log("!!! resending request !!!"),setTimeout(function(){r.bind(d)(i)},1e3)),429===l&&(d.debug&&console.log("!!! resending request !!!"),setTimeout(function(){r.bind(d)(i)},1e3*o.headers["retry-after"]+50)),l>=400?i(u+" : "+n.yellow(m)):i(t,JSON.parse(a));if(429===l)d.debug&&console.log("!!! resending promise request !!!"),setTimeout(function(){return s("retry")},1e3);else{if(429!==l)return t||l>=400?s("err:",t,l):e(JSON.parse(a));d.debug&&console.log("!!! resending promise request !!!"),setTimeout(function(){return s("retry")},1e3*o.headers["retry-after"]+50)}}else console.log(t,m)})):setTimeout(function(){r.bind(d)(i)},1e3)}(r)}else t({url:m,qs:f},function(t,o,a){if(o){var u=void 0,l=o.statusCode;return l>=200&&l<300?u=n.green(l):l>=400&&l<500?u=n.red(l+" "+c(l)):l>=500&&(u=n.bold.red(l+" "+c(l))),i.debug&&(console.log(o&&u,m),console.log({"x-app-rate-limit-count":o.headers["x-app-rate-limit-count"],"x-method-rate-limit-count":o.headers["x-method-rate-limit-count"],"x-rate-limit-count":o.headers["x-rate-limit-count"],"retry-after":o.headers["retry-after"]})),r?l>=400?r(u+" : "+n.yellow(m)):r(t,JSON.parse(a)):t?s("err:",t):e(JSON.parse(a))}console.log(t,m)})})};return r?I():I().catch(I).catch(I).catch(I).then(function(e){return e})}},{key:"_observerRequest",value:function(e,r){var t=e.endUrl,n=e.region;return this._baseRequest({endUrl:"observer-mode/rest/"+t,observerMode:!0,region:n},r)}},{key:"_championRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.CHAMPION+"/"+t,region:n,options:i},r)}},{key:"_championMasteryRequest",value:function(e,r){var t=e.endUrl,n=(e.region,e.options);return this._baseRequest({endUrl:"championmastery/location/"+t,options:n,championMastery:!0},r)}},{key:"_currentGameRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.platformId;return this._observerRequest({endUrl:"consumer/getSpectatorGameInfo/"+i+"/"+t,region:n},r)}},{key:"_staticRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=void 0===n?this.defaultRegion:n,o=e.options;return this._baseRequest({endUrl:"static-data/"+i+"/v"+d.STATIC_DATA+"/"+t,staticReq:!0,region:i,options:o},r)}},{key:"_statusRequest",value:function(e,r){var t=e.endUrl,n=(e.region,e.options);return this._baseRequest({endUrl:"lol/status/v"+d.STATUS+"/"+t,status:!0,options:n},r)}},{key:"_gameRequest",value:function(e,r){var t=e.endUrl,n=e.region;return this._baseRequest({endUrl:"v"+d.GAME+"/game/"+t,region:n},r)}},{key:"_leagueRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.LEAGUE+"/league/"+t,region:n,options:i},r)}},{key:"_matchRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.MATCH+"/match/"+t,region:n,options:i},r)}},{key:"_matchListRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.MATCH_LIST+"/matchlist/by-summoner/"+t,region:n,options:i},r)}},{key:"_runesMasteriesRequest",value:function(e,r){var t=e.endUrl,n=e.region;return this._summonerRequest({endUrl:t,region:n},r)}},{key:"_statsRequest",value:function(e,r){var t=e.endUrl,n=e.region,i=e.options;return this._baseRequest({endUrl:"v"+d.STATS+"/stats/by-summoner/"+t,region:n,options:i},r)}},{key:"_summonerRequest",value:function(e,r){var t=e.endUrl,n=e.region;return this._baseRequest({endUrl:"v"+d.SUMMONER+"/summoner/"+t,region:n},r)}},{key:"_logError",value:function(e,r){console.log(n.bold.yellow(e),n.red("request"),n.bold.red("FAILED")+n.red("; "+r))}},{key:"setRegion",value:function(e){this.defaultRegion=e}},{key:"getChamps",value:function(e,r){var t=e.region,n=e.options;return this._championRequest({endUrl:"champion",region:t,options:n},r=t||n?r:arguments[0])}},{key:"getChamp",value:function(e,r){var t=e.region,i=e.id,o=e.championID;return Number.isInteger(i)||Number.isInteger(o)?this._championRequest({endUrl:"champion/"+(i||o),region:t},r):this._logError(this.getChamp.name,"required params "+n.yellow("`id/championID` (int)")+" not passed in")}},{key:"getChampMastery",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=void 0===r?this.defaultRegion:r,i=e.playerID,o=e.championID,s=e.options,a=arguments[1];if(Number.isInteger(i)&&Number.isInteger(o)){var u=l[g[t]];return this._championMasteryRequest({endUrl:u+"/player/"+i+"/champion/"+o,region:t,options:s},a)}return this._logError(this.getChampMastery.name,"required params "+n.yellow("`playerID` (int) AND `championID` (int)")+" not passed in")}},{key:"getChampMasteries",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=void 0===t?this.defaultRegion:t,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,d=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[g[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/champions",region:i,options:d},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[g[i]];return this.getSummoner({name:m,region:i},function(r,t){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+t[e._sanitizeName(m)].id+"/champions",region:i},h)})}return this._logError(this.getChampMasteries.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (str)")+" not passed in")}},{key:"getTotalChampMasteryScore",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=void 0===t?this.defaultRegion:t,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,d=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[g[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/score",region:i,options:d},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[g[i]];return this.getSummoner({name:m,region:i},function(r,t){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+t[e._sanitizeName(m)].id+"/score",region:i},h)})}return this._logError(this.getTotalChampMasteryScore.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (str)")+" not passed in")}},{key:"getTopChamps",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=void 0===t?this.defaultRegion:t,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,d=r.options,h=arguments[1];if(Number.isInteger(o||a||u)){var p=l[g[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||a||u)+"/topchampions",region:i,options:d},h)}if("object"===s(arguments[0])&&"string"==typeof m){var y=l[g[i]];return this.getSummoner({name:m,region:i},function(r,t){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+t[e._sanitizeName(m)].id+"/topchampions",region:i},h)})}return this._logError(this.getTopChamps.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (str)")+" not passed in")}},{key:"getCurrentGame",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=void 0===t?this.defaultRegion:t,o=r.id,a=r.summonerID,u=r.playerID,m=r.name,d=arguments[1],h=l[g[i]];return Number.isInteger(o||a||u)?this._currentGameRequest({endUrl:""+(o||a||u),platformId:h,region:i},d):"object"===s(arguments[0])&&"string"==typeof m?this.getSummoner({name:m,region:i},function(r,t){return r?d(r):e._currentGameRequest({endUrl:""+t[e._sanitizeName(m)].id,platformId:h,region:i},d)}):this._logError(this.getCurrentGame.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (string)")+" not passed in")}},{key:"getFeaturedGames",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=arguments[1];return this._observerRequest({endUrl:"featured",region:r},t=r?t:arguments[0])}},{key:"getRecentGames",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=arguments[1];return Number.isInteger(i||o||a)?this._gameRequest({endUrl:"by-summoner/"+(i||o||a)+"/recent",region:t},l):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:t},function(r,n){return r?l(r):e._gameRequest({endUrl:"by-summoner/"+n[e._sanitizeName(u)].id+"/recent",region:t},l)}):this._logError(this.getRecentGames.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (string)")+" not passed in")}},{key:"getLeagues",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return p.int(i||a||l)?this._leagueRequest({endUrl:"by-summoner/"+(i||a||l).join(","),region:t},h):Number.isInteger(i||o||a||u||l||m)?this._leagueRequest({endUrl:"by-summoner/"+(i||o||a||u||l||m),region:t},h):p.string(g)?this.getSummoners({names:g,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=g[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(n[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._leagueRequest({endUrl:"by-summoner/"+i.join(","),region:t},h)}):"object"!==s(arguments[0])||"string"!=typeof g&&"string"!=typeof d?this._logError(this.getLeagues.name,"required params "+n.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+n.yellow("`id/summonerID/playerID` (int)")+", "+n.yellow("`names` ([str]/str)")+", or "+n.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:g||d,region:t},function(r,n){return r?h(r):e._leagueRequest({endUrl:"by-summoner/"+n[e._sanitizeName(g||d)].id,region:t},h)})}},{key:"getLeagueEntries",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return p.int(i||a||l)?this._leagueRequest({endUrl:"by-summoner/"+(i||a||l).join(",")+"/entry",region:t},h):Number.isInteger(i||o||a||u||l||m)?this._leagueRequest({endUrl:"by-summoner/"+(i||o||a||u||l||m)+"/entry",region:t},h):p.string(g)?this.getSummoners({names:g,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=g[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(n[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._leagueRequest({endUrl:"by-summoner/"+i.join(",")+"/entry",region:t},h)}):"object"!==s(arguments[0])||"string"!=typeof g&&"string"!=typeof d?void this._logError(this.getLeagueEntries.name,"required params "+n.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+n.yellow("`id/summonerID/playerID` (int)")+", "+n.yellow("`names` ([str]/str)")+", or "+n.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:g||d,region:t},function(r,n){return r?h(r):e._leagueRequest({endUrl:"by-summoner/"+n[e._sanitizeName(g||d)].id+"/entry",region:t},h)})}},{key:"getChallengers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=void 0===t?{type:"RANKED_SOLO_5x5"}:t,i=arguments[1];return this._leagueRequest({endUrl:"challenger",region:r,options:n},i=r?i:arguments[0])}},{key:"getMasters",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=void 0===t?{type:"RANKED_SOLO_5x5"}:t,i=arguments[1];return this._leagueRequest({endUrl:"master",region:r,options:n},i=r?i:arguments[0])}},{key:"getChampionList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"champion",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getChampion",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.championID,o=e.options,s=arguments[1];return Number.isInteger(t||i)?this._staticRequest({endUrl:"champion/"+(t||i),region:r,options:o},s):this._logError(this.getChampion.name,"required params "+n.yellow("`id/championID` (int)")+" not passed in")}},{key:"getItems",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"item",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getItem",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.itemID,o=e.options,s=arguments[1];return Number.isInteger(t||i)?this._staticRequest({endUrl:"item/"+(t||i),region:r,options:o},s):this._logError(this.getItem.name,"required params "+n.yellow("`id/itemID` (int)")+" not passed in")}},{key:"getLanguageStrings",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"language-strings",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getLanguages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=arguments[1];return this._staticRequest({endUrl:"languages",region:r},t=r?t:arguments[0])}},{key:"getMap",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"map",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getMasteryList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"mastery",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getMastery",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.masteryID,o=e.options,s=arguments[1];return Number.isInteger(t||i)?this._staticRequest({endUrl:"mastery/"+(t||i),region:r,options:o},s):this._logError(this.getMastery.name,"required params "+n.yellow("`id/masteryID` (int)")+" not passed in")}},{key:"getRealmData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=arguments[1];return this._staticRequest({endUrl:"realm",region:r},t=r?t:arguments[0])}},{key:"getRuneList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"rune",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getRune",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.runeID,o=e.options,s=arguments[1];return Number.isInteger(t||i)?this._staticRequest({endUrl:"rune/"+(t||i),region:r,options:o},s):this._logError(this.getRune.name,"required params "+n.yellow("`id/runeID` (int)")+" not passed in")}},{key:"getSummonerSpells",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"summoner-spell",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getSummonerSpell",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.spellID,o=e.summonerSpellID,s=e.options,a=arguments[1];return Number.isInteger(t||i||o)?this._staticRequest({endUrl:"summoner-spell/"+(t||i||o),region:r,options:s},a):this._logError(this.getSummonerSpell.name,"required params "+n.yellow("`id/spellID/summonerSpellID` (int)")+" not passed in")}},{key:"getVersionData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.options,n=arguments[1];return this._staticRequest({endUrl:"versions",region:r,options:t},n=r||t?n:arguments[0])}},{key:"getShardStatus",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=arguments[1];return this._statusRequest({endUrl:"shard",region:r},t=r?t:arguments[0])}},{key:"getShardList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=arguments[1];return this._statusRequest({endUrl:"shards",region:r},t=r?t:arguments[0])}},{key:"getMatch",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.matchID,o=e.options,s=void 0===o?{includeTimeline:!0}:o,a=arguments[1];return Number.isInteger(t||i)?this._matchRequest({endUrl:""+(t||i),region:r,options:s},a):this._logError(this.getMatch.name,"required params "+n.yellow("`id/matchID` (int)")+" not passed in")}},{key:"getMatchList",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=r.options,m=void 0===l?{rankedQueues:"RANKED_SOLO_5x5"}:l,g=arguments[1];return Number.isInteger(i||o||a)?this._matchListRequest({endUrl:""+(i||o||a),region:t,options:m},g):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:t},function(r,n){return r?g(r):e._matchListRequest({endUrl:""+n[e._sanitizeName(u)].id,region:t,options:m},g)}):this._logError(this.getMatchList.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (str)")+" not passed in")}},{key:"getRunes",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return p.int(i||a||l)?this._runesMasteriesRequest({endUrl:(i||a||l).join()+"/runes",region:t},h):Number.isInteger(i||o||a||u||l||m)?this._runesMasteriesRequest({endUrl:(i||o||a||u||l||m)+"/runes",region:t},h):p.string(g)?this.getSummoners({names:g,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=g[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(n[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._runesMasteriesRequest({endUrl:i.join(",")+"/runes",region:t},h)}):"object"!==s(arguments[0])||"string"!=typeof g&&"string"!=typeof d?this._logError(this.getRunes.name,"required params "+n.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+n.yellow("`id/summonerID/playerID` (int)")+", "+n.yellow("`names` ([str]/str)")+", or "+n.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:g||d,region:t},function(r,n){return r?h(r):e._runesMasteriesRequest({endUrl:n[e._sanitizeName(g||d)].id+"/runes",region:t},h)})}},{key:"getMasteries",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return p.int(i||a||l)?this._runesMasteriesRequest({endUrl:(i||a||l).join()+"/masteries",region:t},h):Number.isInteger(i||o||a||u||l||m)?this._runesMasteriesRequest({endUrl:(i||o||a||u||l||m)+"/masteries",region:t},h):p.string(g)?this.getSummoners({names:g,region:t},function(r,n){if(r)return h(r);var i=[],o=!0,s=!1,a=void 0;try{for(var u,l=g[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var m=u.value;i.push(n[e._sanitizeName(m)].id)}}catch(e){s=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(s)throw a}}return e._runesMasteriesRequest({endUrl:i.join(",")+"/masteries",region:t},h)}):"object"!==s(arguments[0])||"string"!=typeof g&&"string"!=typeof d?this._logError(this.getMasteries.name,"required params "+n.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+n.yellow("`id/summonerID/playerID` (int)")+", "+n.yellow("`names` ([str]/str)")+", or "+n.yellow("`name` (str)")+" not passed in"):this.getSummoner({name:g||d,region:t},function(r,n){return r?h(r):e._runesMasteriesRequest({endUrl:n[e._sanitizeName(g||d)].id+"/masteries",region:t},h)})}},{key:"getRankedStats",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=r.options,m=arguments[1];return Number.isInteger(i||o||a)?this._statsRequest({endUrl:(i||o||a)+"/ranked",region:t,options:l},m):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:t},function(r,n){return r?m(r):e._statsRequest({endUrl:n[e._sanitizeName(u)].id+"/ranked",region:t,options:l},m)}):void this._logError(this.getRankedStats.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (string)")+" not passed in")}},{key:"getStatsSummary",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.id,o=r.summonerID,a=r.playerID,u=r.name,l=r.options,m=arguments[1];return Number.isInteger(i||o||a)?this._statsRequest({endUrl:(i||o||a)+"/summary",region:t,options:l},m):"object"===s(arguments[0])&&"string"==typeof u?this.getSummoner({name:u,region:t},function(r,n){return r?m(r):e._statsRequest({endUrl:n[e._sanitizeName(u)].id+"/summary",region:t,options:l},m)}):void this._logError(this.getRankedStats.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (string)")+" not passed in")}},{key:"getSummoners",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r.region,i=r.ids,o=r.id,a=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return p.int(i||a||l)?this._summonerRequest({endUrl:""+(i||a||l).join(","),region:t},h):Number.isInteger(i||o||a||u||l||m)?this._summonerRequest({endUrl:""+(i||o||a||u||l||m),region:t},h):p.string(g)?this._summonerRequest({endUrl:"by-name/"+g.map(function(r){return e._sanitizeName(r)}).join(","),region:t},h):"object"!==s(arguments[0])||"string"!=typeof g&&"string"!=typeof d?void this._logError(this.getSummoners.name,"required params "+n.yellow("`ids/summonerIDs/playerIDs` ([int]/int)")+", "+n.yellow("`id/summonerID/playerID` (int)")+", "+n.yellow("`names` ([str]/str)")+", or "+n.yellow("`name` (str)")+" not passed in"):this._summonerRequest({endUrl:"by-name/"+this._sanitizeName(g||d),region:t},h)}},{key:"getSummoner",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.summonerID,o=e.playerID,a=e.name,u=arguments[1];return Number.isInteger(t||i||o)?this.getSummoners({region:r,ids:[t||i||o]},u):"object"===s(arguments[0])&&"string"==typeof a?this.getSummoners({region:r,names:[a]},u):this._logError(this.getSummoner.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" or "+n.yellow("`name` (string)")+" not passed in")}},{key:"getSummonerNames",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.ids,i=e.id,o=e.summonerIDs,s=e.summonerID,a=e.playerIDs,u=e.playerID,l=arguments[1];return p.int(t||o||a)?this._summonerRequest({endUrl:(t||o||a).join(",")+"/name",region:r},l):Number.isInteger(t||i||o||s||a||u)?this._summonerRequest({endUrl:(t||i||o||s||a||u)+"/name",region:r},l):void this._logError(this.getSummonerNames.name,"required params "+n.yellow("required params `ids/summonerIDs/playerIDs` ([int]/int)")+" or "+n.yellow("`id/summonerID/playerID` (int)")+" not passed in")}},{key:"getSummonerName",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.region,t=e.id,i=e.summonerID,o=e.playerID,s=arguments[1];if(Number.isInteger(t))return this.getSummonerNames({region:r,id:t||i||o},s);this._logError(this.getSummonerName.name,"required params "+n.yellow("`id/summonerID/playerID` (int)")+" not passed in")}}]),e}(),I={Kindred:f,REGIONS:m};e.exports=I});
{
"name": "kindred-api",
"version": "1.1.4",
"version": "1.1.5",
"description": "Kindred is a thin Node.js wrapper on top of Riot Games API for League of Legends",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -394,3 +394,11 @@ # Kindred

/* Currently promises are bugged for these type of chained requests. */
/*
Currently promises are bugged for these type of chained requests
since I don't fully understand them yet. You'll have to chain for promises
still.
*/
var ctzName = 'contractz'
k.getSummoner({ name: ctzName })
.then(json => k.getMasteries({ id: json[ctzName].id }))
.then(json => console.log(json))

@@ -397,0 +405,0 @@ /*

@@ -95,109 +95,119 @@ const request = require('request')

_baseRequest({ endUrl, region = this.defaultRegion, status = false, observerMode = false, staticReq = false, championMastery = false, options = {} }, cb) {
return new Promise((resolve, reject) => {
const proxy = staticReq ? 'global' : region
const reqUrl = this._makeUrl(endUrl, proxy, staticReq, status, observerMode, championMastery)
const doAsync = () => {
return new Promise((resolve, reject) => {
const proxy = staticReq ? 'global' : region
const reqUrl = this._makeUrl(endUrl, proxy, staticReq, status, observerMode, championMastery)
if (this.limits) {
var self = this;
(function sendRequest(callback) {
if (self.canMakeRequest(region)) {
if (!staticReq) {
self.limits[region][0].addRequest()
self.limits[region][1].addRequest()
}
if (this.limits) {
var self = this;
(function sendRequest(callback) {
if (self.canMakeRequest(region)) {
if (!staticReq) {
self.limits[region][0].addRequest()
self.limits[region][1].addRequest()
}
// return new Promise((resolve, reject) => {
request({ url: reqUrl, qs: options }, (error, response, body) => {
if (response && body) {
let statusMessage
const { statusCode } = response
request({ url: reqUrl, qs: options }, (error, response, body) => {
if (response && body) {
let statusMessage
const { statusCode } = response
if (statusCode >= 200 && statusCode < 300)
statusMessage = chalk.green(statusCode)
else if (statusCode >= 400 && statusCode < 500)
statusMessage = chalk.red(`${statusCode} ${getResponseMessage(statusCode)}`)
else if (statusCode >= 500)
statusMessage = chalk.bold.red(`${statusCode} ${getResponseMessage(statusCode)}`)
if (statusCode >= 200 && statusCode < 300)
statusMessage = chalk.green(statusCode)
else if (statusCode >= 400 && statusCode < 500)
statusMessage = chalk.red(`${statusCode} ${getResponseMessage(statusCode)}`)
else if (statusCode >= 500)
statusMessage = chalk.bold.red(`${statusCode} ${getResponseMessage(statusCode)}`)
if (self.debug) {
console.log(statusMessage, reqUrl)
console.log({
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'],
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'],
'x-rate-limit-count': response.headers['x-rate-limit-count'],
'retry-after': response.headers['retry-after']
})
console.log()
}
if (callback) {
if (statusCode >= 500) {
if (self.debug) console.log('!!! resending request !!!')
setTimeout(() => { sendRequest.bind(self)(callback) }, 1000)
if (self.debug) {
console.log(statusMessage, reqUrl)
console.log({
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'],
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'],
'x-rate-limit-count': response.headers['x-rate-limit-count'],
'retry-after': response.headers['retry-after']
})
console.log()
}
if (callback) {
if (statusCode >= 500) {
if (self.debug) console.log('!!! resending request !!!')
setTimeout(() => { sendRequest.bind(self)(callback) }, 1000)
}
if (statusCode === 429) {
if (self.debug) console.log('!!! resending request !!!')
setTimeout(() => {
sendRequest.bind(self)(callback)
}, (response.headers['retry-after'] * 1000) + 50)
}
if (statusCode === 429) {
if (self.debug) console.log('!!! resending request !!!')
setTimeout(() => {
sendRequest.bind(self)(callback)
}, (response.headers['retry-after'] * 1000) + 50)
}
if (statusCode >= 400) return callback(statusMessage + ' : ' + chalk.yellow(reqUrl))
else return callback(error, JSON.parse(body))
} else {
if (error) {
return reject('err:', error)
if (statusCode >= 400) return callback(statusMessage + ' : ' + chalk.yellow(reqUrl))
else return callback(error, JSON.parse(body))
} else {
return resolve(JSON.parse(body))
if (statusCode === 429) {
if (self.debug) console.log('!!! resending promise request !!!')
setTimeout(() => { return reject('retry' )}, 1000)
} else if (statusCode === 429) {
if (self.debug) console.log('!!! resending promise request !!!')
setTimeout(() => { return reject('retry') }, (response.headers['retry-after'] * 1000) + 50)
} else if (error || statusCode >= 400) {
return reject('err:', error, statusCode)
} else {
return resolve(JSON.parse(body))
}
}
} else {
console.log(error, reqUrl)
}
} else {
console.log(error, reqUrl)
}
})
} else {
setTimeout(() => { sendRequest.bind(self)(callback) }, 1000)
}
})(cb)
} else {
request({ url: reqUrl, qs: options }, (error, response, body) => {
if (response) {
let statusMessage
const { statusCode } = response
})
} else {
setTimeout(() => { sendRequest.bind(self)(callback) }, 1000)
}
})(cb)
} else {
request({ url: reqUrl, qs: options }, (error, response, body) => {
if (response) {
let statusMessage
const { statusCode } = response
if (statusCode >= 200 && statusCode < 300)
statusMessage = chalk.green(statusCode)
else if (statusCode >= 400 && statusCode < 500)
statusMessage = chalk.red(`${statusCode} ${getResponseMessage(statusCode)}`)
else if (statusCode >= 500)
statusMessage = chalk.bold.red(`${statusCode} ${getResponseMessage(statusCode)}`)
if (statusCode >= 200 && statusCode < 300)
statusMessage = chalk.green(statusCode)
else if (statusCode >= 400 && statusCode < 500)
statusMessage = chalk.red(`${statusCode} ${getResponseMessage(statusCode)}`)
else if (statusCode >= 500)
statusMessage = chalk.bold.red(`${statusCode} ${getResponseMessage(statusCode)}`)
if (this.debug) {
console.log(response && statusMessage, reqUrl)
console.log({
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'],
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'],
'x-rate-limit-count': response.headers['x-rate-limit-count'],
'retry-after': response.headers['retry-after']
})
}
if (this.debug) {
console.log(response && statusMessage, reqUrl)
console.log({
'x-app-rate-limit-count': response.headers['x-app-rate-limit-count'],
'x-method-rate-limit-count': response.headers['x-method-rate-limit-count'],
'x-rate-limit-count': response.headers['x-rate-limit-count'],
'retry-after': response.headers['retry-after']
})
}
if (cb) {
if (statusCode >= 400) return cb(statusMessage + ' : ' + chalk.yellow(reqUrl))
else return cb(error, JSON.parse(body))
} else {
if (error) {
return reject('err:', error)
if (cb) {
if (statusCode >= 400) return cb(statusMessage + ' : ' + chalk.yellow(reqUrl))
else return cb(error, JSON.parse(body))
} else {
return resolve(JSON.parse(body))
if (error) {
return reject('err:', error)
} else {
return resolve(JSON.parse(body))
}
}
} else {
console.log(error, reqUrl)
}
} else {
console.log(error, reqUrl)
}
})
}
})
})
}
})
}
if (!cb) return doAsync().catch(doAsync).catch(doAsync).catch(doAsync).then(data => data)
else return doAsync()
}

@@ -204,0 +214,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc