-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (41 loc) · 1.1 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
39
40
41
42
43
44
45
46
'use strict';
const https = require("https");
const url = 'https://orion.apiseeds.com/api/exchangerates/';
var convert = function (apikey, from, to, callback,amount) {
if (!amount)
amount = 1;
https.get(url +"convert/"+ from + "/" + to + "?apikey=" + apikey + "&amount=" + amount, res => {
res.setEncoding("utf8");
let body = "";
res.on("data", data => {
body += data;
});
res.on("end", () => {
body = JSON.parse(body);
callback(body, res.headers);
});
res.on("error", (e) => {
callback(false);
});
});
}
var currencies = function (apikey, callback) {
https.get(url +"currencies/?apikey=" + apikey , res => {
res.setEncoding("utf8");
let body = "";
res.on("data", data => {
body += data;
});
res.on("end", () => {
body = JSON.parse(body);
callback(body, res.headers);
});
res.on("error", (e) => {
callback(false);
});
});
}
module.exports = {
convert,
currencies
}