LeagueStats/server/providers/Jax/src/Jax.js

52 lines
1.7 KiB
JavaScript
Raw Normal View History

const RiotRateLimiter = require('riot-ratelimiter')
const { STRATEGY } = require('riot-ratelimiter/dist/RateLimiter')
const LeagueEndpoint = require('./Endpoints/LeagueEndpoint')
const MatchEndpoint = require('./Endpoints/MatchEndpoint')
const MatchlistEndpoint = require('./Endpoints/MatchlistEndpoint')
const SummonerEndpoint = require('./Endpoints/SummonerEndpoint')
2019-08-24 14:56:55 +00:00
const DDragonVersionEndpoint = require('./Endpoints/DDragonEndpoints/DDragonVersionEndpoint')
const DDragonChampionEndpoint = require('./Endpoints/DDragonEndpoints/DDragonChampionEndpoint')
const DDragonRuneEndpoint = require('./Endpoints/DDragonEndpoints/DDragonRuneEndpoint')
2019-08-24 14:56:55 +00:00
class Jax {
constructor(key, env) {
this.key = key
const limiterOptions = {
strategy: env === 'production' ? STRATEGY.SPREAD : STRATEGY.BURST
}
this.limiter = new RiotRateLimiter(limiterOptions)
this.region = 'euw1'
this.League = new LeagueEndpoint(this.limiter, this.region)
this.Match = new MatchEndpoint(this.limiter, this.region)
this.Matchlist = new MatchlistEndpoint(this.limiter, this.region)
this.Summoner = new SummonerEndpoint(this.limiter, this.region)
this.initDDragon()
}
async initDDragon() {
this.version = (await new DDragonVersionEndpoint().list())[0]
2019-08-24 14:56:55 +00:00
this.DDragon = {
Champion: new DDragonChampionEndpoint(this.version),
Rune: new DDragonRuneEndpoint(this.version),
Version: this.version
}
2019-08-24 14:56:55 +00:00
}
2019-08-24 14:56:55 +00:00
set regionName(regionName) {
this.region = regionName
const blacklistedProperties = ['key', 'limiter', 'region', 'version', 'DDragon']
for (const key of Object.getOwnPropertyNames(this)) {
if(blacklistedProperties.includes(key)) continue
this[key].region = regionName
}
2019-08-24 14:56:55 +00:00
}
}
module.exports = Jax