-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwarframe.js
More file actions
137 lines (117 loc) · 2.84 KB
/
Copy pathwarframe.js
File metadata and controls
137 lines (117 loc) · 2.84 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use strict';
const fetch = require('node-fetch');
/**
* Warframe Class
*
* Warframe.js by Luca Kiebel
* Contributors:
* - Tobiah <tobiah@pm.me>
*
* Docs and more: https://github.com/WFCD/Warframe.js
*/
class Warframe {
/**
* Construct a worldstate with specified default platform
* @param {string<'pc'|'ps4'|'xb1'|'swi'>} [platform] optional platform param
* @constructor
*/
constructor({ platform = 'pc' } = { platform: 'pc' }) {
this.system = platform || 'pc';
this.BASE = 'https://api.warframestat.us';
}
/**
* Get data from specified endpoint
* @param {string} endpoint endpoint to fetch
* @param {function} [map] mapping function to alter or filter data
* @param {boolean} [skipPlatform] option to skip platform. useful for non-worldstate lookups
* @returns {Promise}
*/
get(endpoint, { map, skipPlatform = false } = { skipPlatform: false }) {
return new Promise((resolve, reject) => fetch(`${this.BASE}/${skipPlatform ? '' : `${this.system}/`}${endpoint}`)
.then((d) => d.json())
.then((data) => (Array.isArray(data) && map ? data.map(map) : data))
.then((data) => resolve(data))
.catch((e) => reject(e)));
}
set platform(platform) {
this.system = platform;
}
/**
* Test whether the API can be reached
* @returns {Promise<Object>}
*/
get heartbeat() {
return this.get('heartbeat', { skipPlatform: true });
}
/**
* The alerts and all data associated with them
* @returns {Promise<Array>}
*/
get alerts() {
return this.get('alerts');
}
/**
* The current sorties and their conditions
* @returns {Promise}
*/
get sorties() {
return this.get('sortie');
}
/**
* The current day/nighttime on cetus
* @returns {Promise}
*/
get cycleCetus() {
return this.get('cetusCycle');
}
/**
* The current day/nighttime on earth
* @returns {Promise}
*/
get cycleEarth() {
return this.get('earthCycle');
}
/**
* When the Void Trader arrives/leaves and what goodies they carry
* @returns {Promise}
*/
get voidTrader() {
return this.get('voidTrader');
}
/**
* TODO: when an event is live, look at the data
* @returns {Promise}
*/
get events() {
return this.get('events');
}
/**
* The current news in every language available
* @returns {Promise}
*/
get news() {
return this.get('news');
}
get syndicateMissions() {
return this.get('syndicateMissions');
}
get fissures() {
return this.get('fissures');
}
get darkSectors() {
return this.get('darkSectors');
}
get invasions() {
return this.get('invasions');
}
get dailyDeals() {
return this.get('dailyDeals');
}
get simaris() {
return this.get('simaris');
}
get conclaveChallenges() {
return this.get('conclaveChallenges');
}
}
module.exports = Warframe;