-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
38 lines (30 loc) · 1.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const fetch = require('isomorphic-unfetch');
const rankings = require('./lib/rankings');
const player = require('./lib/player');
const match = require('./lib/match');
const gamesSummary = require('./lib/gamesSummary');
const leaderboard = require('./lib/leaderboard');
const API_URL = "https://quake-stats.bethesda.net/api/";
const API_VERSION = "v2";
class QuakeChampionsClient {
constructor({ apiUrl, apiVersion } = {}) {
this._apiUrl = apiUrl || API_URL;
this._apiVersion = apiVersion || API_VERSION;
this._apiEndpoint = `${this._apiUrl}${this._apiVersion}`;
this.rankings = rankings;
this.player = player.bind(this)();
this.match = match.bind(this)();
this.gamesSummary = gamesSummary.bind(this)();
this.leaderboard = leaderboard.bind(this)();
}
async request(url) {
const request = `${this._apiEndpoint}${url}`;
return fetch(request).catch((e) => {
throw new Error(e);
});
}
toJson(res) {
return typeof res.json === "function" ? res.json() : res;
}
}
module.exports = QuakeChampionsClient;