-
Notifications
You must be signed in to change notification settings - Fork 0
/
unsubscribe.js
42 lines (35 loc) · 1.01 KB
/
unsubscribe.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
var config = require('./config');
var httpClient = require('./lib/HTTPClient.js');
var fs = require('fs');
var subFile = "./subscription.json";
var fs = require('fs');
if (fs.existsSync(subFile)) {
console.log('Subscribtion file exists already.');
fs.readFile(subFile, 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
console.log('Unsubscribe ' + data);
var options = {
host: config.orion_host,
port: config.orion_port,
path: data,
method: 'DELETE',
headers: {
'Accept' : 'application/json',
'Fiware-Service' : 'organicity'
}
};
httpClient.sendData(config.orion_protocol, options, undefined, undefined, function (status, responseText, headers) {
console.log('Unsubscribe successful.');
fs.unlinkSync(subFile);
console.log(subFile + ' deleted!');
}, function(status, resp) {
console.log('ERROR', status, resp);
fs.unlinkSync(subFile);
console.log(subFile + ' deleted!');
});
});
} else {
console.log('Subscription does not exists.');
}