lol-api-client
Version:
A Node client for interfacing with the League of Legends API
38 lines (28 loc) • 994 B
JavaScript
const web = require('./web')
class Games {
constructor (apiKey, region, platformId) {
this.apiKey = apiKey
this.region = region
this.baseCurrentGameUrl = `https://${this.region}.api.pvp.net/observer-mode/rest/` +
`consumer/getSpectatorGameInfo/${platformId}`
}
getCurrent (summonerId) {
const requestUrl = `${this.baseCurrentGameUrl}/${summonerId}?api_key=${this.apiKey}`
return web.makeRequest(requestUrl)
.catch((error) => {
// A 404 for this route simply means the summoner is not currently
// in a game, so we don't actually treat it like an error here.'
if (error.statusCode === 404) {
return { }
}
throw error
})
}
getRecent (summonerId) {
const requestUrl = `https://${this.region}.api.pvp.net/api/lol/${this.region}` +
`/v1.3/game/by-summoner/${summonerId}/recent?api_key=${this.apiKey}`
return web.makeRequest(requestUrl)
}
}
module.exports = Games