-
Notifications
You must be signed in to change notification settings - Fork 54
/
apikeydriver.js
44 lines (39 loc) · 945 Bytes
/
apikeydriver.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
39
40
41
42
43
44
const Driver = require('../models/driver');
const request = require('../lib/request');
const Ticker = require('../models/ticker');
/**
* Example showing a driver that uses an API requiring a key.
*
* @memberof Driver
* @augments Driver
*/
class ApiKeyDriver extends Driver {
// Indicate that this driver requires an API key.
constructor() {
super({
requires: {
key: true,
},
});
}
/**
* @augments Driver.fetchTickers
* @returns {Promise.Array<Ticker>} Returns a promise of an array with tickers.
*/
async fetchTickers() {
// The API key can now be accessed through this.key.
const data = await request(`http://...?key=${this.key}`);
return data.map((item) => {
const {
base, quote, close, baseVolume,
} = item;
return new Ticker({
base,
quote,
close,
baseVolume,
});
});
}
}
module.exports = ApiKeyDriver;