2019-09-11 07:06:21 +00:00
|
|
|
const got = require('got')
|
2019-08-31 16:42:08 +00:00
|
|
|
|
|
|
|
|
class DDragonRequest {
|
|
|
|
|
constructor(endpoint, type, version) {
|
|
|
|
|
this.endpoint = endpoint
|
|
|
|
|
this.type = type
|
|
|
|
|
this.version = version
|
|
|
|
|
|
|
|
|
|
this.lang = 'en_US'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://ddragon.leagueoflegends.com/cdn/${this.$patch}/data/en_US/champion.json
|
|
|
|
|
// https://ddragon.leagueoflegends.com/api/versions.json
|
|
|
|
|
|
|
|
|
|
async execute() {
|
|
|
|
|
let url;
|
|
|
|
|
if (this.version) {
|
|
|
|
|
url = `https://ddragon.leagueoflegends.com/${this.type}/${this.version}/data/${this.lang}/${this.endpoint}`
|
|
|
|
|
} else {
|
|
|
|
|
url = `https://ddragon.leagueoflegends.com/${this.type}/${this.endpoint}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await got(url);
|
|
|
|
|
return JSON.parse(response.body)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error.response.body);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-11 07:06:21 +00:00
|
|
|
module.exports = DDragonRequest
|