-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignal-request.js
38 lines (34 loc) · 1.07 KB
/
signal-request.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
// requires
var request = require('request'),
xml2js = require('xml2js');
// define our main class
var SignalRetriever = function() {
var that = this;
function retrieve(url, callback) {
request(url, function(error, response, body) {
var xml;
if (!error && response.statusCode == 200) {
// parse the xml returned from the url
xml2js.parseString(body, function(err, result) {
if (err) {
callback.call(this, 'could not parse xml[' + result + ']');
} else {
if (result && result.response) {
// check if a response object exists and return to caller
callback.call(this, null, result.response);
} else {
callback.call(this, 'did not get expected output from url[' + url + ']!');
}
}
});
} else {
callback.call(this, 'could not read url[' + url + ']');
}
}.bind(that));
}
return {
retrieve: retrieve
};
};
// export a new instance of our module
exports.SignalRetriever = new SignalRetriever();