apigeek-affirm
Version:
A BDD/Gherkin micro-framework for REST APIs
42 lines (31 loc) • 926 B
JavaScript
var _ = require("lodash");
var assert = require("assert");
module.exports = function(options) {
options = options || {}
var self = this;
self.webhooks = {};
// dynamic load and configure webhook plugins
_.each(options, function(config, hook) {
var Webhook = require(config.requires || "./webhooks/"+hook);
self.webhooks[hook] = new Webhook(config);
});
var SendEvent = function(type,args) {
_.each(self.webhooks, function(fn, hook) {
fn[type] && fn[type].apply(self, args);
})
}
// broadcast events
this.started = function() {
SendEvent("started", arguments);
}
this.success = function() {
SendEvent("success", arguments);
}
this.failure = function() {
SendEvent("failure", arguments);
}
this.finished = function() {
SendEvent("finished", arguments);
}
return this;
}