UNPKG

lol-js

Version:

Node.js bindings for the Riot API, with caching and rate limiting

123 lines (111 loc) 4.18 kB
// Generated by CoffeeScript 1.9.2 (function() { var MAX_SUMMONER_IDS_PER_REQUEST, MAX_SUMMONER_NAMES_PER_REQUEST, api, cacheSummoner, ld, pb, summonerByIdCacheParams, summonerByNameCacheParams, toStandardizedSummonerName; ld = require('lodash'); pb = require('promise-breaker'); api = exports.api = { fullname: "summoner-v1.4", name: "summoner", version: "v1.4" }; MAX_SUMMONER_NAMES_PER_REQUEST = 40; MAX_SUMMONER_IDS_PER_REQUEST = 40; toStandardizedSummonerName = function(name) { return name.toLowerCase().replace(/\ /g, ''); }; exports.methods = { getSummonersByName: pb["break"](function(region, summonerNames) { var i, len, namesToStandardizedNames, standardizedName, standardizedNames, summonerName; namesToStandardizedNames = {}; standardizedNames = []; for (i = 0, len = summonerNames.length; i < len; i++) { summonerName = summonerNames[i]; standardizedName = toStandardizedSummonerName(summonerName); namesToStandardizedNames[summonerName] = standardizedName; standardizedNames.push(standardizedName); } return this._riotMultiGet(region, { caller: "getSummonersByName", baseUrl: (this._makeUrl(region, api)) + "/by-name", ids: standardizedNames, getCacheParamsFn: summonerByNameCacheParams, cacheResultFn: cacheSummoner, maxObjs: MAX_SUMMONER_NAMES_PER_REQUEST }).then(function(result) { var answer, j, len1; answer = {}; for (j = 0, len1 = summonerNames.length; j < len1; j++) { summonerName = summonerNames[j]; standardizedName = namesToStandardizedNames[summonerName]; answer[summonerName] = result[standardizedName]; } return answer; }); }), getSummonersById: pb["break"](function(region, summonerIds) { return this._riotMultiGet(region, { caller: "getSummonersById", baseUrl: this._makeUrl(region, api), ids: summonerIds, getCacheParamsFn: summonerByIdCacheParams('summoner'), maxObjs: MAX_SUMMONER_NAMES_PER_REQUEST }); }), getSummonerNames: pb["break"](function(region, summonerIds) { return this.getSummonersById(region, summonerIds).then(function(summoners) { return ld.mapValues(summoners, function(x) { var ref; return (ref = x != null ? x.name : void 0) != null ? ref : null; }); }); }), getSummonerMasteries: pb["break"](function(region, summonerIds) { return this._riotMultiGet(region, { caller: "getSummonerMasteries", baseUrl: this._makeUrl(region, api), ids: summonerIds, urlSuffix: "/masteries", getCacheParamsFn: summonerByIdCacheParams('masteries'), maxObjs: MAX_SUMMONER_NAMES_PER_REQUEST }); }), getSummonerRunes: pb["break"](function(region, summonerIds) { return this._riotMultiGet(region, { caller: "getSummonerRunes", baseUrl: this._makeUrl(region, api), ids: summonerIds, urlSuffix: "/runes", getCacheParamsFn: summonerByIdCacheParams('runes'), maxObjs: MAX_SUMMONER_NAMES_PER_REQUEST }); }) }; cacheSummoner = function(client, region, summoner) { client.cache.set(summonerByIdCacheParams(this, region, summoner.id), summoner); return client.cache.set(summonerByNameCacheParams(this, region, summoner.name), summoner); }; summonerByNameCacheParams = function(client, region, summonerName) { return { key: api.fullname + "-summonerByName-" + region + "-" + (summonerName.toLowerCase()), api: api, region: region, objectType: 'summonerByName', params: { summonerName: summonerName.toLowerCase() } }; }; summonerByIdCacheParams = function(objectType) { return function(client, region, summonerId) { return { key: api.fullname + "-" + objectType + "-" + region + "-" + summonerId, api: api, region: region, objectType: objectType, params: { summonerId: summonerId } }; }; }; }).call(this);