victorops
Version:
VictorOps client
51 lines (39 loc) • 1.18 kB
JavaScript
// Generated by CoffeeScript 1.6.3
(function() {
var HttpClient, VictorOps;
HttpClient = require('./http_client');
VictorOps = (function() {
var END_POINT, failOnError;
END_POINT = 'https://alert.victorops.com/integrations/generic/20131114/';
VictorOps.create = function(apiKey) {
return new VictorOps(apiKey, new HttpClient());
};
function VictorOps(apiKey, httpClient) {
this.apiKey = apiKey;
this.httpClient = httpClient;
}
VictorOps.prototype.alert = function(parameters, routingKey) {
if (routingKey == null) {
routingKey = 'everyone';
}
return this.httpClient.request({
method: 'POST',
url: END_POINT + ("alert/" + this.apiKey + "/" + routingKey),
body: JSON.stringify(parameters),
headers: {
'Content-Type': 'application/json'
},
done: failOnError
});
};
failOnError = function(response) {
var data;
data = JSON.parse(response);
if (data.result !== 'success') {
throw "Error " + data.messages;
}
};
return VictorOps;
})();
module.exports = VictorOps;
}).call(this);