mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 21:07:27 +00:00
Start Jax: Riot Api Wrapper
This commit is contained in:
parent
b8ec9ca80f
commit
3683776e24
5 changed files with 81 additions and 0 deletions
18
server/Jax/Endpoints/SummonerEndpoint.js
Normal file
18
server/Jax/Endpoints/SummonerEndpoint.js
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import JaxRequest from '../JaxRequest'
|
||||||
|
|
||||||
|
class SummonerEnpoint {
|
||||||
|
constructor(limiter, region) {
|
||||||
|
this.limiter = limiter
|
||||||
|
this.region = region
|
||||||
|
}
|
||||||
|
|
||||||
|
summonerName(summonerName) {
|
||||||
|
return new JaxRequest(
|
||||||
|
`summoner/v4/summoners/by-name/${encodeURI(summonerName)}`,
|
||||||
|
this.limiter,
|
||||||
|
this.region
|
||||||
|
).execute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SummonerEnpoint
|
||||||
21
server/Jax/Jax.js
Normal file
21
server/Jax/Jax.js
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
const RiotRateLimiter = require('riot-ratelimiter')
|
||||||
|
|
||||||
|
import SummonerEndpoint from './Endpoints/SummonerEndpoint'
|
||||||
|
|
||||||
|
class Jax {
|
||||||
|
constructor(key = process.env.API_KEY, region = 'euw1') {
|
||||||
|
this.key = key
|
||||||
|
this.limiter = new RiotRateLimiter()
|
||||||
|
this.region = region
|
||||||
|
|
||||||
|
this.Summoner = new SummonerEndpoint(this.limiter, this.region)
|
||||||
|
}
|
||||||
|
|
||||||
|
set regionName(regionName) {
|
||||||
|
this.region = regionName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
Jax
|
||||||
|
}
|
||||||
26
server/Jax/JaxRequest.js
Normal file
26
server/Jax/JaxRequest.js
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
class JaxRequest {
|
||||||
|
constructor(endpoint, limiter, region) {
|
||||||
|
this.endpoint = endpoint
|
||||||
|
this.region = region
|
||||||
|
this.limiter = limiter
|
||||||
|
this.region = region
|
||||||
|
}
|
||||||
|
|
||||||
|
async execute() {
|
||||||
|
try {
|
||||||
|
const resp = await this.limiter.executing({
|
||||||
|
url: `https://${this.region}.api.riotgames.com/lol/${this.endpoint}`,
|
||||||
|
token: process.env.API_KEY,
|
||||||
|
resolveWithFullResponse: false
|
||||||
|
})
|
||||||
|
|
||||||
|
return JSON.parse(resp)
|
||||||
|
|
||||||
|
} catch ({ statusCode, ...rest }) {
|
||||||
|
console.log('error: ' + statusCode, rest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default JaxRequest
|
||||||
1
server/Jax/index.js
Normal file
1
server/Jax/index.js
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
module.exports = require('./Jax')
|
||||||
|
|
@ -7,6 +7,7 @@ const Promise = require("bluebird");
|
||||||
const responseTime = require('response-time')
|
const responseTime = require('response-time')
|
||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const app = express()
|
const app = express()
|
||||||
|
import { Jax } from "./Jax";
|
||||||
|
|
||||||
/* Global Variables */
|
/* Global Variables */
|
||||||
const data = {
|
const data = {
|
||||||
|
|
@ -19,6 +20,9 @@ const data = {
|
||||||
finalJSON: []
|
finalJSON: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Setup Riot API Wrapper */
|
||||||
|
const jax = new Jax()
|
||||||
|
|
||||||
/* Set Port */
|
/* Set Port */
|
||||||
app.set('port', (process.env.PORT || 5000))
|
app.set('port', (process.env.PORT || 5000))
|
||||||
|
|
||||||
|
|
@ -69,10 +73,21 @@ app.post('/api', function (req, res) {
|
||||||
console.time('all')
|
console.time('all')
|
||||||
data.region = req.body.region;
|
data.region = req.body.region;
|
||||||
data.username = req.body.summoner;
|
data.username = req.body.summoner;
|
||||||
|
|
||||||
|
jax.regionName = req.body.region
|
||||||
|
newVersion()
|
||||||
|
|
||||||
data.finalJSON = [];
|
data.finalJSON = [];
|
||||||
getAccountInfos(res);
|
getAccountInfos(res);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* Refactor with the Jax Wrapper */
|
||||||
|
async function newVersion() {
|
||||||
|
const { id, accountId } = await jax.Summoner.summonerName(data.username)
|
||||||
|
|
||||||
|
console.log(id, accountId)
|
||||||
|
}
|
||||||
|
|
||||||
// Get account infos of an username
|
// Get account infos of an username
|
||||||
const getAccountInfos = function (res) {
|
const getAccountInfos = function (res) {
|
||||||
request(`https://${data.region}.api.riotgames.com/lol/summoner/v4/summoners/by-name/${encodeURIComponent(data.username)}?api_key=${data.key}`, function (error, response, body) {
|
request(`https://${data.region}.api.riotgames.com/lol/summoner/v4/summoners/by-name/${encodeURIComponent(data.username)}?api_key=${data.key}`, function (error, response, body) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue