refactor: remove old ddragon code

This commit is contained in:
Valentin Kaelin 2020-02-13 20:24:17 +01:00
parent dacd3873e8
commit 47e255c64a
11 changed files with 3 additions and 184 deletions

View file

@ -1,6 +1,5 @@
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import * as ddragon from '@/store/modules/ddragon'
import * as detailedMatch from '@/store/modules/detailedMatch' import * as detailedMatch from '@/store/modules/detailedMatch'
import * as notification from '@/store/modules/notification' import * as notification from '@/store/modules/notification'
import * as settings from '@/store/modules/settings' import * as settings from '@/store/modules/settings'
@ -12,7 +11,6 @@ const debug = process.env.NODE_ENV !== 'production'
export default new Vuex.Store({ export default new Vuex.Store({
modules: { modules: {
ddragon,
detailedMatch, detailedMatch,
notification, notification,
settings, settings,

View file

@ -1,46 +0,0 @@
import { axios } from '@/plugins/axios'
export const namespaced = true
export const state = {
champions: [],
runes: [],
version: ''
}
export const mutations = {
PUSH_CHAMPIONS(state, champions) {
state.champions = champions
},
PUSH_RUNES(state, runes) {
state.runes = runes
},
PUSH_VERSION(state, version) {
state.version = version
}
}
export const actions = {
async getChampions({ commit }) {
console.log('API CALL FOR CHAMPIONS')
const endpoint = 'Champion'
const resp = await axios(({ url: 'ddragon', data: { endpoint }, method: 'POST' }))
commit('PUSH_CHAMPIONS', resp.data.data)
},
async getRunes({ commit }) {
console.log('API CALL FOR RUNES')
const endpoint = 'Rune'
const resp = await axios(({ url: 'ddragon', data: { endpoint }, method: 'POST' }))
commit('PUSH_RUNES', resp.data)
},
getVersion({ commit }, version) {
commit('PUSH_VERSION', version)
},
}
export const getters = {
areChampionsLoaded: state => !!state.champions.Aatrox,
version: state => state.version
}

View file

@ -1,17 +0,0 @@
'use strict'
const Jax = use('Jax')
class DDragonController {
/**
* POST - Return infos about all static Ddragon data
*/
async index({ request, response }) {
console.log('DDragon Request')
const endpoint = request.input('endpoint')
const result = await Jax.DDragon[endpoint].list()
response.json(result)
}
}
module.exports = DDragonController

View file

@ -10,7 +10,7 @@ const Helpers = use('App/helpers')
*/ */
class MatchTransformer { class MatchTransformer {
/** /**
* Get global Context with DDragon Data * Get global Context with CDragon Data
*/ */
async getContext() { async getContext() {
const items = await Jax.CDragon.items() const items = await Jax.CDragon.items()

View file

@ -1,33 +0,0 @@
const got = require('got')
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);
}
}
}
module.exports = DDragonRequest

View file

@ -1,17 +0,0 @@
const DDragonRequest = require('../../DDragonRequest')
class DDragonChampionEndpoint {
constructor(version) {
this.version = version
}
list() {
return new DDragonRequest(
`champion.json`,
'cdn',
this.version
).execute()
}
}
module.exports = DDragonChampionEndpoint

View file

@ -1,17 +0,0 @@
const DDragonRequest = require('../../DDragonRequest')
class DDragonItemEndpoint {
constructor(version) {
this.version = version
}
list() {
return new DDragonRequest(
`item.json`,
'cdn',
this.version
).execute()
}
}
module.exports = DDragonItemEndpoint

View file

@ -1,17 +0,0 @@
const DDragonRequest = require('../../DDragonRequest')
class DDragonRuneEndpoint {
constructor(version) {
this.version = version
}
list() {
return new DDragonRequest(
`runesReforged.json`,
'cdn',
this.version
).execute()
}
}
module.exports = DDragonRuneEndpoint

View file

@ -1,13 +0,0 @@
const DDragonRequest = require('../../DDragonRequest')
class DDragonVersionEndpoint {
list() {
return new DDragonRequest(
`versions.json`,
'api',
null
).execute()
}
}
module.exports = DDragonVersionEndpoint

View file

@ -5,11 +5,6 @@ const MatchlistEndpoint = require('./Endpoints/MatchlistEndpoint')
const SpectatorEndpoint = require('./Endpoints/SpectatorEndpoint') const SpectatorEndpoint = require('./Endpoints/SpectatorEndpoint')
const SummonerEndpoint = require('./Endpoints/SummonerEndpoint') const SummonerEndpoint = require('./Endpoints/SummonerEndpoint')
const DDragonVersionEndpoint = require('./Endpoints/DDragonEndpoints/DDragonVersionEndpoint')
const DDragonChampionEndpoint = require('./Endpoints/DDragonEndpoints/DDragonChampionEndpoint')
const DDragonRuneEndpoint = require('./Endpoints/DDragonEndpoints/DDragonRuneEndpoint')
const DDragonItemEndpoint = require('./Endpoints/DDragonEndpoints/DDragonItemEndpoint')
const CDragonEndpoint = require('./Endpoints/CDragonEndpoint') const CDragonEndpoint = require('./Endpoints/CDragonEndpoint')
class Jax { class Jax {
@ -27,25 +22,12 @@ class Jax {
this.Spectator = new SpectatorEndpoint(this.config, this.limiter) this.Spectator = new SpectatorEndpoint(this.config, this.limiter)
this.Summoner = new SummonerEndpoint(this.config, this.limiter) this.Summoner = new SummonerEndpoint(this.config, this.limiter)
this.initDDragon()
this.CDragon = new CDragonEndpoint() this.CDragon = new CDragonEndpoint()
} }
async initDDragon() {
this.version = (await new DDragonVersionEndpoint().list())[0]
this.DDragon = {
Champion: new DDragonChampionEndpoint(this.version),
Item: new DDragonItemEndpoint(this.version),
Rune: new DDragonRuneEndpoint(this.version),
Version: this.version
}
}
set regionName(regionName) { set regionName(regionName) {
this.config.region = regionName this.config.region = regionName
const blacklistedProperties = ['key', 'limiter', 'config', 'version', 'DDragon'] const blacklistedProperties = ['key', 'limiter', 'config', 'version', 'CDragon']
for (const key of Object.getOwnPropertyNames(this)) { for (const key of Object.getOwnPropertyNames(this)) {
if(blacklistedProperties.includes(key)) continue if(blacklistedProperties.includes(key)) continue

View file

@ -20,7 +20,7 @@ const Match = use('App/Models/Match')
Route.get('/', async () => { Route.get('/', async () => {
return { return {
greeting: 'Hello world in JSON', greeting: 'Hello world from LeagueStats.gg',
match: await Match.first() match: await Match.first()
} }
}) })
@ -30,7 +30,6 @@ Route.post('/summoner-overview', 'SummonerController.overview')
Route.post('/summoner-champions', 'SummonerController.champions') Route.post('/summoner-champions', 'SummonerController.champions')
Route.post('/summoner-records', 'SummonerController.records') Route.post('/summoner-records', 'SummonerController.records')
Route.post('/summoner-live', 'SummonerController.liveMatchDetails') Route.post('/summoner-live', 'SummonerController.liveMatchDetails')
Route.post('/ddragon', 'DDragonController.index')
Route.post('/match', 'MatchController.index') Route.post('/match', 'MatchController.index')
Route.post('/match-details', 'MatchController.show') Route.post('/match-details', 'MatchController.show')
Route.post('/match-details-ranks', 'MatchController.showRanks') Route.post('/match-details-ranks', 'MatchController.showRanks')