-
Notifications
You must be signed in to change notification settings - Fork 23
/
tonicdev.js
41 lines (38 loc) · 853 Bytes
/
tonicdev.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
//Tonic Example File. For https://tonicdev.com
const
JSONstat = require('jsonstat'),
got = require("got"),
unr = function(arr){
got( "https://json-stat.org/samples/oecd.json" )
.then(response => {
var ds = JSONstat(JSON.parse(response.body));
if(ds.length){
arr.forEach(o => {
var
value = ds.Data(o).value,
label = (d => {
return ds.Dimension(d).Category(o[d]).label;
})
;
console.log(
"Unemployment rate in " +
label("area") + " in " +
label("year") + " was " +
value + " %."
);
});
}else{
console.log("Response is not valid JSON-stat.");
}
})
.catch(error => {
console.log(error.response.body);
})
;
}
;
//Time: 2003-2014 Geo: AU, AT, BE, CA...
unr([
{year: "2003", area: "DE"},
{year: "2003", area: "GR"}
]);