-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
48 lines (38 loc) · 1.01 KB
/
index.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
'use strict';
const https = require('https');
const path = require('path');
const Q = require('q');
function request(resource, callback) {
let deferred = Q.defer();
let options = {
host: 'api.opensource.org',
path: resource,
method: 'GET'
}
https.get(options, function (res) {
let body = '';
res.on('data', function(data) {
body += data;
});
res.on('end', function() {
let data = JSON.parse(body)
if (data.errors)
deferred.reject(data.errors);
else
deferred.resolve(data);
});
});
return deferred.promise.nodeify(callback);
}
// Get list of all known licenses
module.exports.all = function all(callback) {
return request('/licenses/', callback);
}
// Get license by it's OSI ID
module.exports.get = function get(id, callback) {
return request(path.join('/license', id), callback);
}
// Get license by a keyword
module.exports.tagged = function tagged(keyword, callback) {
return request(path.join('/licenses', keyword), callback);
}