-
Notifications
You must be signed in to change notification settings - Fork 3
/
fetchApis.js
109 lines (96 loc) · 3.98 KB
/
fetchApis.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
'use strict';
const fs = require('fs');
const nitro = require('./nitroSdk');
const api = require('./nitroApi/api.js');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
//_____________________________________________________________________________
let config, apiKey, host;
try {
config = require('./config.json');
apiKey = config.nitro.api_key;
host = config.nitro.host;
}
catch (e) {
if (process.argv[2]) {
apiKey = process.argv[2];
host = 'programmes.api.bbc.com';
}
else {
console.log('Please rename config.json.example to config.json and edit for your setup');
process.exit(2);
}
}
let query = nitro.newQuery();
nitro.make_request(host,'/nitro/api',apiKey,query,{headers:{Accept: 'application/json'}},function(obj){
console.log('Nitro JSON API');
fs.writeFileSync('./nitroApi/api.json',JSON.stringify(obj,null,2));
return false;
});
nitro.make_request(host,'/nitro/api',apiKey,query,{headers:{Accept: 'text/xml'}},function(obj){
console.log('Nitro XML API');
fs.writeFileSync('./nitroApi/api.xml',obj);
return false;
});
nitro.make_request(host,'/nitro/api/schema',apiKey,query,{headers:{Accept: 'text/xml'}},function(obj){
console.log('Nitro XML Schema');
fs.writeFileSync('./nitroApi/nitro-schema.xsd',obj);
return false;
});
nitro.make_request('ibl.api.bbci.co.uk','/ibl/v1/schema/ibl.json','',query,{headers:{Accept:'application/json'}},function(obj){
console.log('iBL JSON Schema');
fs.writeFileSync('./iblApi/ibl.json',JSON.stringify(obj,null,2));
return false;
});
let iblKey = 'dummy';
nitro.make_request('ibl.api.bbci.co.uk','/ibl/v1/status',iblKey,query,{},function(obj){
console.log('iBL status '+obj.status.service+' v'+obj.version+' r'+obj.status.release);
fs.writeFileSync('./iblApi/ibl_status.json',JSON.stringify(obj,null,2));
return false;
});
nitro.make_request('rms.api.bbc.co.uk','/docs/swagger.json','',query,{proto:'https'},function(obj){
console.log('RMS (BLUR/PULP) openapi.json');
fs.writeFileSync('./rmsApi/openapi.json',JSON.stringify(obj,null,2));
return false;
});
nitro.make_request('galileo.api.bbc.com','/v2/api-docs','',query,{proto:'https'},function(obj){
console.log('Galileo swagger.json');
fs.writeFileSync('./galileoApi/swagger.json',JSON.stringify(obj,null,2));
return false;
});
nitro.make_request('raw.githubusercontent.com','/bbc/simorgh/latest/data/schema.yaml','',query,{proto:'https',headers:{Accept:'text/x-yaml'}},function(obj){
console.log('Simorgh schema.yaml');
fs.writeFileSync('./simorghApi/openapi.yaml',obj);
return false;
});
nitro.make_request('access.api.bbc.com','/swagger/swagger.yaml','',query,{proto:'https',headers:{Accept:'text/x-yaml'}},function(obj){
console.log('Access API');
fs.writeFileSync('./accessApi/swagger.yaml',obj);
return false;
});
nitro.make_request('locator-service.api.bbci.co.uk','/v2/api-docs','',query,{proto:'https',headers:{Accept:'application/json'}},function(obj){
console.log('Locator API');
fs.writeFileSync('./locatorApi/swagger.json',JSON.stringify(obj,null,2));
return false;
});
nitro.make_request('isl.britbox.co.uk','/api/spec','',query,{proto:'https',headers:{Accept:'application/json'}},function(obj){
console.log('BritBox API');
fs.writeFileSync('./britboxApi/swagger.json',JSON.stringify(obj,null,2));
return false;
});
query.add(api.fProgrammesPartnerPid,'s0000024',true);
query.add(api.fProgrammesPageSize,1);
nitro.make_request(host,api.nitroProgrammes,apiKey,query,{headers:{Accept: 'application/json'}},function(obj){
let total = (typeof obj.nitro.results.total !== 'undefined') ? obj.nitro.results.total : obj.nitro.results.more_than+1;
if (total>0) {
console.log('Internal programmes present');
}
return false;
});
query.add(api.fProgrammesEntityTypeClip);
nitro.make_request(host,api.nitroProgrammes,apiKey,query,{headers:{Accept: 'application/json'}},function(obj){
let total = (typeof obj.nitro.results.total !== 'undefined') ? obj.nitro.results.total : obj.nitro.results.more_than+1;
if (total>0) {
console.log('Internal clips present');
}
return false;
});