Files
jambonz-node/lib/jambonz/webhook-response.js
2021-02-17 20:06:23 -05:00

34 lines
577 B
JavaScript

const {validate, specs} = require('./utils');
class WebhookResponse {
constructor() {
this.payload = [];
}
get length() {
return this.payload.length;
}
set length(len) {
this.payload.length = len;
}
toJSON() {
return this.payload;
}
addVerb(verb, payload) {
validate(verb, payload);
this.payload.push({verb, ...payload});
}
}
for (const [verb] of specs) {
WebhookResponse.prototype[verb] = function(payload) {
return WebhookResponse.prototype.addVerb.call(this, verb, payload);
};
}
module.exports = WebhookResponse;