kindred-api
Advanced tools
Comparing version 1.1.6 to 1.1.7
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define('kindred-api', ['module', 'double-ended-queue', 'request', 'chalk', 'xregexp'], factory); | ||
define('kindred-api', ['module', 'double-ended-queue', 'request', 'chalk', 'xregexp', 'query-string'], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(module, require('double-ended-queue'), require('request'), require('chalk'), require('xregexp')); | ||
factory(module, require('double-ended-queue'), require('request'), require('chalk'), require('xregexp'), require('query-string')); | ||
} else { | ||
@@ -10,6 +10,6 @@ var mod = { | ||
}; | ||
factory(mod, global.doubleEndedQueue, global.request, global.chalk, global.xregexp); | ||
factory(mod, global.doubleEndedQueue, global.request, global.chalk, global.xregexp, global.queryString); | ||
global.kindredApi = mod.exports; | ||
} | ||
})(this, function (module, Deque, request, chalk, XRegExp) { | ||
})(this, function (module, Deque, request, chalk, XRegExp, queryString) { | ||
'use strict'; | ||
@@ -302,3 +302,7 @@ | ||
return 'https://' + region + '.api.riotgames.com/' + prefix + encodeURI(query) + '?api_key=' + this.key; | ||
var url = 'https://' + region + '.api.riotgames.com/' + prefix + encodeURI(query); | ||
if (url.lastIndexOf('?') === -1) url += '?';else url += '&'; | ||
url += 'api_key=' + this.key; | ||
return url; | ||
} | ||
@@ -327,4 +331,8 @@ }, { | ||
var proxy = staticReq ? 'global' : region; | ||
var reqUrl = _this._makeUrl(endUrl, proxy, staticReq, status, observerMode, championMastery); | ||
var stringified = queryString.stringify(options); | ||
var postfix = stringified ? '?' + stringified : ''; | ||
var reqUrl = _this._makeUrl(endUrl + postfix, proxy, staticReq, status, observerMode, championMastery); | ||
if (_this.limits) { | ||
@@ -340,3 +348,3 @@ var self = _this; | ||
request({ url: reqUrl, qs: options }, function (error, response, body) { | ||
request({ url: reqUrl }, function (error, response, body) { | ||
if (response && body) { | ||
@@ -404,3 +412,3 @@ var statusMessage = void 0; | ||
} else { | ||
request({ url: reqUrl, qs: options }, function (error, response, body) { | ||
request({ url: reqUrl }, function (error, response, body) { | ||
if (response) { | ||
@@ -848,3 +856,4 @@ var statusMessage = void 0; | ||
names = _ref25.names, | ||
name = _ref25.name; | ||
name = _ref25.name, | ||
options = _ref25.options; | ||
@@ -856,3 +865,3 @@ var cb = arguments[1]; | ||
endUrl: 'by-summoner/' + (ids || summonerIDs || playerIDs).join(','), | ||
region: region | ||
region: region, options: options | ||
}, cb); | ||
@@ -862,3 +871,3 @@ } else if (Number.isInteger(ids || id || summonerIDs || summonerID || playerIDs || playerID)) { | ||
endUrl: 'by-summoner/' + (ids || id || summonerIDs || summonerID || playerIDs || playerID), | ||
region: region | ||
region: region, options: options | ||
}, cb); | ||
@@ -896,3 +905,3 @@ } else if (checkAll.string(names)) { | ||
return _this7._leagueRequest({ endUrl: 'by-summoner/' + args.join(','), region: region }, cb); | ||
return _this7._leagueRequest({ endUrl: 'by-summoner/' + args.join(','), region: region, options: options }, cb); | ||
}); | ||
@@ -905,3 +914,3 @@ } else if (_typeof(arguments[0]) === 'object' && (typeof names === 'string' || typeof name === 'string')) { | ||
endUrl: 'by-summoner/' + data[_this7._sanitizeName(names || name)].id, | ||
region: region | ||
region: region, options: options | ||
}, cb); | ||
@@ -998,3 +1007,3 @@ }); | ||
endUrl: 'challenger', region: region, options: options | ||
}, cb = region ? cb : arguments[0]); | ||
}, cb = region || options ? cb : arguments[0]); | ||
} | ||
@@ -1013,3 +1022,3 @@ }, { | ||
endUrl: 'master', region: region, options: options | ||
}, cb = region ? cb : arguments[0]); | ||
}, cb = region || options ? cb : arguments[0]); | ||
} | ||
@@ -1016,0 +1025,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 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(500===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}); | ||
!function(e,r){if("function"==typeof define&&define.amd)define("kindred-api",["module","double-ended-queue","request","chalk","xregexp","query-string"],r);else if("undefined"!=typeof exports)r(module,require("double-ended-queue"),require("request"),require("chalk"),require("xregexp"),require("query-string"));else{var t={exports:{}};r(t,e.doubleEndedQueue,e.request,e.chalk,e.xregexp,e.queryString),e.kindredApi=t.exports}}(this,function(e,r,t,n,i,o){"use strict";function s(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}var a="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},u=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}}(),l=function(){function e(t,n){s(this,e),this.allowedRequests=t,this.seconds=n,this.madeRequests=new r}return u(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}(),m={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"},g={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"},h={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},p={int:function(e){return e.every(function(e){return Number.isInteger(e)})},string:function(e){return e.every(function(e){return"string"==typeof e})}},y={int:function(e){return e&&Array.isArray(e)&&p.int(e)&&e.length>0},string:function(e){return e&&Array.isArray(e)&&p.string(e)&&e.length>0}},c={400:"Bad Request",403:"Forbidden",404:"Not Found",415:"Unsupported Media Type",429:"Rate Limit Exceeded",500:"Internal Service Error",503:"Service Unavailable"},v=function(e){var r=c[e];if(r)return r},f=i("^[0-9\\p{L} _\\.]+$"),I=function(){function e(r){var t=r.key,i=r.defaultRegion,o=void 0===i?g.NORTH_AMERICA:i,a=r.debug,u=void 0!==a&&a,m=r.limits;s(this,e),this.key=t;var d=void 0,h=!0,p=!1,c=void 0;try{for(var v,f=Object.keys(g)[Symbol.iterator]();!(h=(v=f.next()).done);h=!0){var I=v.value;g[I]===o&&(d=!0)}}catch(e){p=!0,c=e}finally{try{!h&&f.return&&f.return()}finally{if(p)throw c}}if(this.defaultRegion=d?o:void 0,this.defaultRegion||(console.log(""+n.red("Initialization of Kindred failed: "+n.yellow(o)+" 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=u,m){(Array.isArray(m)&&2!==m.length||!y.int(m[0])||2!==m[0].length||!y.int(m[1])||2!==m[1].length)&&"dev"!==m&&"prod"!==m&&(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"===m&&(m=[[10,10],[500,600]]),"prod"===m&&(m=[[3e3,10],[18e4,600]]);var R=!0,_=!1,q=void 0;try{for(var U,D=Object.keys(g)[Symbol.iterator]();!(R=(U=D.next()).done);R=!0){var b=U.value;this.limits[g[b]]=[new l(m[0][0],m[0][1]),new l(m[1][0],m[1][1])]}}catch(e){_=!0,q=e}finally{try{!R&&D.return&&D.return()}finally{if(_)throw q}}}}return u(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 f.test(e)}},{key:"_makeUrl",value:function(e,r,t,n,i,o){var s=t?"":r+"/",a=n||i||o?"":"api/lol/"+s,u="https://"+r+".api.riotgames.com/"+a+encodeURI(e);return u+=u.lastIndexOf("?")===-1?"?":"&",u+="api_key="+this.key}},{key:"_baseRequest",value:function(e,r){var i=this,s=e.endUrl,a=e.region,u=void 0===a?this.defaultRegion:a,l=e.status,m=void 0!==l&&l,g=e.observerMode,d=void 0!==g&&g,h=e.staticReq,p=void 0!==h&&h,y=e.championMastery,c=void 0!==y&&y,f=e.options,I=void 0===f?{}:f,R=function(){return new Promise(function(e,a){var l=p?"global":u,g=o.stringify(I),h=g?"?"+g:"",y=i._makeUrl(s+h,l,p,m,d,c);if(i.limits){var f=i;!function r(i){f.canMakeRequest(u)?(p||(f.limits[u][0].addRequest(),f.limits[u][1].addRequest()),t({url:y},function(t,o,s){if(o&&s){var u=void 0,l=o.statusCode;if(l>=200&&l<300?u=n.green(l):l>=400&&l<500?u=n.red(l+" "+v(l)):l>=500&&(u=n.bold.red(l+" "+v(l))),f.debug&&(console.log(u,y),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&&(f.debug&&console.log("!!! resending request !!!"),setTimeout(function(){r.bind(f)(i)},1e3)),429===l&&(f.debug&&console.log("!!! resending request !!!"),setTimeout(function(){r.bind(f)(i)},1e3*o.headers["retry-after"]+50)),l>=400?i(u+" : "+n.yellow(y)):i(t,JSON.parse(s));if(500===l)f.debug&&console.log("!!! resending promise request !!!"),setTimeout(function(){return a("retry")},1e3);else{if(429!==l)return t||l>=400?a("err:",t,l):e(JSON.parse(s));f.debug&&console.log("!!! resending promise request !!!"),setTimeout(function(){return a("retry")},1e3*o.headers["retry-after"]+50)}}else console.log(t,y)})):setTimeout(function(){r.bind(f)(i)},1e3)}(r)}else t({url:y},function(t,o,s){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+" "+v(l)):l>=500&&(u=n.bold.red(l+" "+v(l))),i.debug&&(console.log(o&&u,y),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(y)):r(t,JSON.parse(s)):t?a("err:",t):e(JSON.parse(s))}console.log(t,y)})})};return r?R():R().catch(R).catch(R).catch(R).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"+h.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"+h.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"+h.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"+h.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"+h.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"+h.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"+h.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"+h.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"+h.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=m[d[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,s=r.summonerID,u=r.playerID,l=r.name,g=r.options,h=arguments[1];if(Number.isInteger(o||s||u)){var p=m[d[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||s||u)+"/champions",region:i,options:g},h)}if("object"===a(arguments[0])&&"string"==typeof l){var y=m[d[i]];return this.getSummoner({name:l,region:i},function(r,t){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+t[e._sanitizeName(l)].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,s=r.summonerID,u=r.playerID,l=r.name,g=r.options,h=arguments[1];if(Number.isInteger(o||s||u)){var p=m[d[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||s||u)+"/score",region:i,options:g},h)}if("object"===a(arguments[0])&&"string"==typeof l){var y=m[d[i]];return this.getSummoner({name:l,region:i},function(r,t){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+t[e._sanitizeName(l)].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,s=r.summonerID,u=r.playerID,l=r.name,g=r.options,h=arguments[1];if(Number.isInteger(o||s||u)){var p=m[d[i]];return this._championMasteryRequest({endUrl:p+"/player/"+(o||s||u)+"/topchampions",region:i,options:g},h)}if("object"===a(arguments[0])&&"string"==typeof l){var y=m[d[i]];return this.getSummoner({name:l,region:i},function(r,t){return r?h(r):e._championMasteryRequest({endUrl:y+"/player/"+t[e._sanitizeName(l)].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,s=r.summonerID,u=r.playerID,l=r.name,g=arguments[1],h=m[d[i]];return Number.isInteger(o||s||u)?this._currentGameRequest({endUrl:""+(o||s||u),platformId:h,region:i},g):"object"===a(arguments[0])&&"string"==typeof l?this.getSummoner({name:l,region:i},function(r,t){return r?g(r):e._currentGameRequest({endUrl:""+t[e._sanitizeName(l)].id,platformId:h,region:i},g)}):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,s=r.playerID,u=r.name,l=arguments[1];return Number.isInteger(i||o||s)?this._gameRequest({endUrl:"by-summoner/"+(i||o||s)+"/recent",region:t},l):"object"===a(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,s=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=r.options,p=arguments[1];return y.int(i||s||l)?this._leagueRequest({endUrl:"by-summoner/"+(i||s||l).join(","),region:t,options:h},p):Number.isInteger(i||o||s||u||l||m)?this._leagueRequest({endUrl:"by-summoner/"+(i||o||s||u||l||m),region:t,options:h},p):y.string(g)?this.getSummoners({names:g,region:t},function(r,n){if(r)return p(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,options:h},p)}):"object"!==a(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?p(r):e._leagueRequest({endUrl:"by-summoner/"+n[e._sanitizeName(g||d)].id,region:t,options:h},p)})}},{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,s=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return y.int(i||s||l)?this._leagueRequest({endUrl:"by-summoner/"+(i||s||l).join(",")+"/entry",region:t},h):Number.isInteger(i||o||s||u||l||m)?this._leagueRequest({endUrl:"by-summoner/"+(i||o||s||u||l||m)+"/entry",region:t},h):y.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"!==a(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||n?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||n?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,s=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||s)?this._matchListRequest({endUrl:""+(i||o||s),region:t,options:m},g):"object"===a(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,s=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return y.int(i||s||l)?this._runesMasteriesRequest({endUrl:(i||s||l).join()+"/runes",region:t},h):Number.isInteger(i||o||s||u||l||m)?this._runesMasteriesRequest({endUrl:(i||o||s||u||l||m)+"/runes",region:t},h):y.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"!==a(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,s=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return y.int(i||s||l)?this._runesMasteriesRequest({endUrl:(i||s||l).join()+"/masteries",region:t},h):Number.isInteger(i||o||s||u||l||m)?this._runesMasteriesRequest({endUrl:(i||o||s||u||l||m)+"/masteries",region:t},h):y.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"!==a(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,s=r.playerID,u=r.name,l=r.options,m=arguments[1];return Number.isInteger(i||o||s)?this._statsRequest({endUrl:(i||o||s)+"/ranked",region:t,options:l},m):"object"===a(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,s=r.playerID,u=r.name,l=r.options,m=arguments[1];return Number.isInteger(i||o||s)?this._statsRequest({endUrl:(i||o||s)+"/summary",region:t,options:l},m):"object"===a(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,s=r.summonerIDs,u=r.summonerID,l=r.playerIDs,m=r.playerID,g=r.names,d=r.name,h=arguments[1];return y.int(i||s||l)?this._summonerRequest({endUrl:""+(i||s||l).join(","),region:t},h):Number.isInteger(i||o||s||u||l||m)?this._summonerRequest({endUrl:""+(i||o||s||u||l||m),region:t},h):y.string(g)?this._summonerRequest({endUrl:"by-name/"+g.map(function(r){return e._sanitizeName(r)}).join(","),region:t},h):"object"!==a(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,s=e.name,u=arguments[1];return Number.isInteger(t||i||o)?this.getSummoners({region:r,ids:[t||i||o]},u):"object"===a(arguments[0])&&"string"==typeof s?this.getSummoners({region:r,names:[s]},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 y.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}(),R={Kindred:I,REGIONS:g};e.exports=R}); |
{ | ||
"name": "kindred-api", | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"description": "Kindred is a thin Node.js wrapper on top of Riot Games API for League of Legends", | ||
@@ -64,2 +64,3 @@ "main": "index.js", | ||
"double-ended-queue": "^2.1.0-0", | ||
"query-string": "^4.3.2", | ||
"request": "^2.81.0", | ||
@@ -66,0 +67,0 @@ "xregexp": "^3.1.1" |
@@ -17,2 +17,4 @@ # Kindred | ||
* Retries on 429 and >= 500 (should it just be 500?). | ||
* Promise-based requests retry up to three times. | ||
* Callback-based requests are infinite at the moment. | ||
* Tells you what parameters you can pass in when you make a parameter-related error. | ||
@@ -19,0 +21,0 @@ |
const request = require('request') | ||
const chalk = require('chalk') | ||
const XRegExp = require('xregexp') | ||
const queryString = require('query-string') | ||
@@ -91,3 +92,8 @@ import RateLimit from './rate-limit' | ||
return `https://${region}.api.riotgames.com/${prefix}${encodeURI(query)}?api_key=${this.key}` | ||
let url = `https://${region}.api.riotgames.com/${prefix}${encodeURI(query)}` | ||
if (url.lastIndexOf('?') === -1) url += '?' | ||
else url += '&' | ||
url += `api_key=${this.key}` | ||
return url | ||
} | ||
@@ -99,7 +105,11 @@ | ||
const proxy = staticReq ? 'global' : region | ||
const reqUrl = this._makeUrl(endUrl, proxy, staticReq, status, observerMode, championMastery) | ||
const stringified = queryString.stringify(options) | ||
const postfix = stringified ? '?' + stringified : '' | ||
const reqUrl = this._makeUrl(endUrl + postfix, proxy, staticReq, status, observerMode, championMastery) | ||
if (this.limits) { | ||
var self = this; | ||
(function sendRequest(callback) { | ||
@@ -112,3 +122,3 @@ if (self.canMakeRequest(region)) { | ||
request({ url: reqUrl, qs: options }, (error, response, body) => { | ||
request({ url: reqUrl }, (error, response, body) => { | ||
if (response && body) { | ||
@@ -173,3 +183,3 @@ let statusMessage | ||
} else { | ||
request({ url: reqUrl, qs: options }, (error, response, body) => { | ||
request({ url: reqUrl }, (error, response, body) => { | ||
if (response) { | ||
@@ -481,7 +491,7 @@ let statusMessage | ||
/* LEAGUE-V2.5 */ | ||
getLeagues({ region, ids, id, summonerIDs, summonerID, playerIDs, playerID, names, name } = {}, cb) { | ||
getLeagues({ region, ids, id, summonerIDs, summonerID, playerIDs, playerID, names, name, options } = {}, cb) { | ||
if (checkAll.int(ids || summonerIDs || playerIDs)) { | ||
return this._leagueRequest({ | ||
endUrl: `by-summoner/${(ids || summonerIDs || playerIDs).join(',')}`, | ||
region | ||
region, options | ||
}, cb) | ||
@@ -491,3 +501,3 @@ } else if (Number.isInteger(ids || id || summonerIDs || summonerID || playerIDs || playerID)) { | ||
endUrl: `by-summoner/${ids || id || summonerIDs || summonerID || playerIDs || playerID}`, | ||
region | ||
region, options | ||
}, cb) | ||
@@ -503,3 +513,3 @@ } else if (checkAll.string(names)) { | ||
return this._leagueRequest({ endUrl: `by-summoner/${args.join(',')}`, region }, cb) | ||
return this._leagueRequest({ endUrl: `by-summoner/${args.join(',')}`, region, options }, cb) | ||
}) | ||
@@ -512,3 +522,3 @@ } else if (typeof arguments[0] === 'object' && (typeof names === 'string' || typeof name === 'string')) { | ||
endUrl: `by-summoner/${data[this._sanitizeName(names || name)].id}`, | ||
region | ||
region, options | ||
}, cb) | ||
@@ -565,3 +575,3 @@ }) | ||
endUrl: 'challenger', region, options | ||
}, cb = region ? cb : arguments[0]) | ||
}, cb = region || options ? cb : arguments[0]) | ||
} | ||
@@ -572,3 +582,3 @@ | ||
endUrl: 'master', region, options | ||
}, cb = region ? cb : arguments[0]) | ||
}, cb = region || options ? cb : arguments[0]) | ||
} | ||
@@ -575,0 +585,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
318731
2726
470
5
+ Addedquery-string@^4.3.2
+ Addedobject-assign@4.1.1(transitive)
+ Addedquery-string@4.3.4(transitive)
+ Addedstrict-uri-encode@1.1.0(transitive)