This repository has been archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
cms.js
68 lines (56 loc) · 1.51 KB
/
cms.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
"use strict";
var https = require('https'),
Q = require('q'),
token = process.env.CMS_KEY || require('./config.js').cms_key;
var defaults = {
method: "GET",
host: 'cms.union.rpi.edu',
headers: {
"Authorization": "Token " + token,
"Content-Type": "application/json"
}
};
var endpoints = {
rcs: '/api/users/view_rcs/%/',
rin: '/api/users/view_rin/%/',
wtg: '/api/users/get_if_wtg/%/',
rne: '/api/users/get_if_rne/%/'
};
var execute = function(path) {
var options = {
method: defaults.method,
host: defaults.host,
path: path,
headers: defaults.headers
};
var deferred = Q.defer();
var req = https.request(options, function(response) {
response.setEncoding('utf8');
var responseData = '';
response.on('data', function(data) {
responseData += data;
});
response.on('end', function() {
deferred.resolve(responseData);
});
});
req.on('error', function(err) {
deferred.reject(err);
});
req.end();
return deferred.promise;
};
module.exports = {
getRCS: function (rcs_id) {
return execute(endpoints.rcs.replace(/%/g, rcs_id));
},
getRIN: function (rin) {
return execute(endpoints.rin.replace(/%/g, rin));
},
getWTG: function(rcs_id) {
return execute(endpoints.wtg.replace(/%/g, rcs_id));
},
getRNE: function(rcs_id) {
return execute(endpoints.rne.replace(/%/g, rcs_id));
}
};