forked from jmcanterafonseca/showcase.navigator.adaptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbusiness_fwk.js
59 lines (46 loc) · 1.41 KB
/
business_fwk.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
52
53
54
55
56
57
58
59
'use strict';
const Request = require('request');
const config = require('./config.json');
function BfQuery(token) {
this.token = token;
}
BfQuery.prototype.run = function() {
return getPurchasedDatasets(this.token);
}
function getPurchasedDatasets(token) {
console.log('Purchased datasets: ', token);
return new Promise(function(resolve, reject) {
var bfApi = config.businessFrameworkAPI;
console.log(bfApi);
Request({
url: bfApi,
headers: {
'Authorization': 'Bearer ' + token
},
json:true
}, function(err, response, body) {
if (err) {
console.log('Error while querying purchased datasets: ', err);
reject(err);
}
var serviceData = body;
var out = [];
console.log(JSON.stringify(serviceData));
serviceData.forEach(function(aService) {
var productCharacteristics = aService.productCharacteristic;
var obj = Object.create(null);
productCharacteristics.forEach(function(aChar) {
if (aChar.name == 'NGSI Endpoint') {
obj.endPoint = aChar.value;
}
else if (aChar.name == 'NGSIEntityType') {
obj.entityType = aChar.value;
}
});
out.push(obj);
});
resolve({ paidDatasets: out });
});
});
}
module.exports.BfQuery = BfQuery;