-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
51 lines (46 loc) · 1.39 KB
/
app.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
50
51
const request = require('request');
const queryString = require('query-string');
module.exports = function (version, apikey) {
var openuv = {};
var endpoint = 'https://api.openuv.io/api/'+version;
var options = {
headers: {
'x-access-token': apikey
}
};
openuv.uv = function (params, cb) {
options.url = endpoint+'/uv?'+queryString.stringify(params);
console.log(options);
request(options, (error, response, body) => {
if (!error && response.statusCode == 200) {
cb(null, JSON.parse(body).result);
}
else {
cb(JSON.parse(body).error, null);
}
})
};
openuv.forecast = function (params, cb) {
options.url = endpoint+'/forecast?'+queryString.stringify(params);
request(options, (error, response, body) => {
if (!error && response.statusCode == 200) {
cb(null, JSON.parse(body).result);
}
else {
cb(JSON.parse(body).error, null);
}
})
};
openuv.protection = function (params, cb) {
options.url = endpoint+'/protection?'+queryString.stringify(params);
request(options, (error, response, body) => {
if (!error && response.statusCode == 200) {
cb(null, JSON.parse(body).result);
}
else {
cb(JSON.parse(body).error, null);
}
})
};
return openuv;
};