mirror of
https://github.com/jambonz/jambonz-node.git
synced 2025-12-19 05:17:49 +00:00
34 lines
577 B
JavaScript
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;
|