-
Notifications
You must be signed in to change notification settings - Fork 0
/
dryg.js
34 lines (29 loc) · 789 Bytes
/
dryg.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
const request = require('request-promise');
const url = require('url');
function fetchDay(date) {
let dateUrl = 'http://api.dryg.net/dagar/v2.1/' + date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate();
let options = {
method: 'GET',
url: url.parse(dateUrl),
json: true
};
return new Promise((resolve, reject) => {
request(options)
.then(function(data) {
let day = buildDayObject(data.dagar[0]);
resolve(day);
})
.catch(function(err) {
reject(err);
});
});
}
function buildDayObject(data) {
return {
weekday: data.veckodag,
week: parseInt(data.vecka),
holiday: data.hasOwnProperty('helgdag') ? data.helgdag : null,
nameDays: data.namnsdag
}
}
exports.fetchDay = fetchDay;