-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.js
More file actions
58 lines (53 loc) · 1.29 KB
/
Copy pathtest.js
File metadata and controls
58 lines (53 loc) · 1.29 KB
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
var HttpError = require('./index.js').HttpError;
var API = require('./index.js').API;
var getResults = require('./index.js').Results;
var getAll = require('./index.js').All;
var Count = require('./index.js').Count;
var api = API(process.env.DOL_API_KEY);
var log = console.log;
function filter(ary){
return ary.map(function(item){ return item.datasetPath; });
}
// Get a list of all the API endpoints that are listed in the API APIMetadata endpoint.
api.APIMetadata.APIMetadatas()
.then(getResults)
.then(filter)
.map(function(endpoint){
return api.getDataFromEndpoint(endpoint)
.then(function(set){
return set.EntitySets;
})
.map(function(entity){
return {
endpoint:endpoint,
entity: entity
};
})
.catch(HttpError, function(e){
console.log(e.message, e.response.statusCode, e.response.req.path);
})
;
})
.then(function(ary){
return ary.filter(
function(value){ return value !== undefined; }
);
})
.then(function(ary){
var merged = [];
return merged.concat.apply(merged, ary);
})
.then(function(ary){
return ary.map(
function(item){
item.endpoint = item.endpoint.substr(22);
return item
}
);
})
.then(function(ary){
for(var i = 0; i < ary.length; i++){
console.log(ary[i].endpoint, ary[i].entity);
}
})
;