forked from nightscout/minimed-connect-to-nightscout
-
Notifications
You must be signed in to change notification settings - Fork 1
/
nightscout.js
30 lines (27 loc) · 825 Bytes
/
nightscout.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
/* jshint node: true */
"use strict";
var crypto = require('crypto'),
request = require('request');
var logger = require('./logger');
var upload = module.exports.upload = function(entries, endpoint, secret, callback) {
logger.log('POST ' + endpoint + ' ' + JSON.stringify(entries));
request.post(
endpoint,
{
body: entries,
json: true,
headers: {
'api-secret': crypto.createHash('sha1').update(secret).digest('hex')
}
},
function(err, response) {
if(err) {
callback(new Error("Error uploading to Nightscout: can't connect to Nightscout host"));
} else if(response.statusCode !== 200) {
callback(new Error("Error uploading to Nightscout: " + JSON.stringify(response)));
} else {
callback(null, response);
}
}
);
};