logify-alert
Version:
Node.js client for Logify Alert
68 lines (59 loc) • 2.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var request = require('request');
var nodeReportSender = function () {
function nodeReportSender() {
_classCallCheck(this, nodeReportSender);
}
_createClass(nodeReportSender, [{
key: 'sendReport',
value: function sendReport(apiKey, reportData, sendCallback) {
this._apiKey = apiKey;
this._sendData = reportData;
this._sendCallback = sendCallback;
this._sendingAttemptCount = 0;
this.sendReportCore();
}
}, {
key: 'callSendReportCallback',
value: function callSendReportCallback(e) {
if (this._sendCallback != undefined) this._sendCallback(e);
}
}, {
key: 'sendReportCore',
value: function sendReportCore() {
var callback = function callback(error, response, body) {
if (error) {
this.callSendReportCallback(error);
return;
}
if (response != null && response != undefined && response.statusCode != 200) {
if (this._sendingAttemptCount < 3) {
this._sendingAttemptCount++;
this.sendReportCore();
} else {
this.callSendReportCallback("The report was not sent");
}
} else {
this.callSendReportCallback();
}
};
request({
url: "https://logify.devexpress.com/api/report/newreport",
method: "POST",
json: true,
body: this._sendData,
headers: {
"Authorization": "amx " + this._apiKey,
"Content-Type": "application/json; charset=UTF-8"
}
}, callback.bind(this));
}
}]);
return nodeReportSender;
}();
exports.default = nodeReportSender;