forked from everapihq/currencyapi-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (38 loc) · 1007 Bytes
/
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
39
40
41
42
43
44
45
46
47
48
49
'use strict';
class CurrencyAPI {
baseUrl = 'https://api.currencyapi.com/v3/';
constructor(apiKey = '') {
this.headers = {
apikey: apiKey
};
}
call (endpoint, params = {}) {
const paramString = new URLSearchParams({
...params
}).toString();
return fetch(`${this.baseUrl}${endpoint}?${paramString}`, { headers: this.headers })
.then(response => response.json())
.then(data => {
return data;
});
}
status () {
return this.call('status');
}
currencies (params) {
return this.call('currencies', params);
}
latest (params) {
return this.call('latest', params);
}
historical (params) {
return this.call('historical', params);
}
range (params) {
return this.call('range', params);
}
convert (params) {
return this.call('convert', params);
}
}
export default CurrencyAPI;