2019-08-31 16:42:08 +00:00
|
|
|
import RiotRateLimiter from 'riot-ratelimiter'
|
2019-09-01 12:53:03 +00:00
|
|
|
import { STRATEGY } from 'riot-ratelimiter/dist/RateLimiter'
|
2019-08-24 14:56:55 +00:00
|
|
|
|
2019-09-01 12:53:03 +00:00
|
|
|
|
|
|
|
|
import LeagueEndpoint from './Endpoints/LeagueEndpoint'
|
|
|
|
|
import MatchEndpoint from './Endpoints/MatchEndpoint'
|
|
|
|
|
import MatchlistEndpoint from './Endpoints/MatchlistEndpoint'
|
2019-08-24 14:56:55 +00:00
|
|
|
import SummonerEndpoint from './Endpoints/SummonerEndpoint'
|
|
|
|
|
|
2019-08-31 16:42:08 +00:00
|
|
|
import DDragonVersionEndpoint from './Endpoints/DDragonEndpoints/DDragonVersionEndpoint'
|
|
|
|
|
import DDragonChampionEndpoint from './Endpoints/DDragonEndpoints/DDragonChampionEndpoint'
|
|
|
|
|
|
2019-08-24 14:56:55 +00:00
|
|
|
class Jax {
|
|
|
|
|
constructor(key = process.env.API_KEY, region = 'euw1') {
|
2019-08-31 16:42:08 +00:00
|
|
|
|
2019-09-04 18:11:16 +00:00
|
|
|
this.key = key
|
|
|
|
|
const limiterOptions = {
|
|
|
|
|
strategy: STRATEGY.BURST
|
|
|
|
|
}
|
|
|
|
|
this.limiter = new RiotRateLimiter(limiterOptions)
|
|
|
|
|
this.region = region
|
2019-08-31 16:42:08 +00:00
|
|
|
|
2019-09-04 18:11:16 +00:00
|
|
|
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)
|
2019-08-31 16:42:08 +00:00
|
|
|
|
2019-09-04 18:11:16 +00:00
|
|
|
this.initDDragon()
|
|
|
|
|
}
|
2019-08-31 16:42:08 +00:00
|
|
|
|
2019-09-04 18:11:16 +00:00
|
|
|
async initDDragon() {
|
|
|
|
|
this.version = (await new DDragonVersionEndpoint().list())[0]
|
2019-08-24 14:56:55 +00:00
|
|
|
|
2019-09-04 18:11:16 +00:00
|
|
|
this.DDragon = {
|
|
|
|
|
Champion: new DDragonChampionEndpoint(this.version),
|
|
|
|
|
Version: this.version
|
|
|
|
|
}
|
2019-08-24 14:56:55 +00:00
|
|
|
}
|
2019-08-31 16:42:08 +00:00
|
|
|
|
2019-08-24 14:56:55 +00:00
|
|
|
set regionName(regionName) {
|
|
|
|
|
this.region = regionName
|
2019-09-09 16:14:15 +00:00
|
|
|
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 = {
|
2019-09-04 18:11:16 +00:00
|
|
|
Jax: new Jax()
|
2019-08-24 14:56:55 +00:00
|
|
|
}
|