diff --git a/lib/bindings/http/emitter_binary_0_2.js b/lib/bindings/http/emitter_binary_0_2.js index ce6e976..d5fdfe3 100644 --- a/lib/bindings/http/emitter_binary_0_2.js +++ b/lib/bindings/http/emitter_binary_0_2.js @@ -3,35 +3,18 @@ var empty = require("is-empty"); const Constants = require("./constants.js"); -const Headers02 = { - TYPE : "ce-type", - SPEC_VERSION : "ce-specversion", - SOURCE : "ce-source", - ID : "ce-id", - TIME : "ce-time", - SCHEMA_URL : "ce-schemaurl", - EXTENSIONS_PREFIX : "ce-" -}; - const required_headers = []; -required_headers.push(Headers02.TYPE); -required_headers.push(Headers02.SPEC_VERSION); -required_headers.push(Headers02.SOURCE); -required_headers.push(Headers02.ID); +required_headers.push(Constants.BINARY_HEADERS_02.TYPE); +required_headers.push(Constants.BINARY_HEADERS_02.SPEC_VERSION); +required_headers.push(Constants.BINARY_HEADERS_02.SOURCE); +required_headers.push(Constants.BINARY_HEADERS_02.ID); -function validate_args(payload, attributes) { - if(!payload){ - throw {message: "payload is null or undefined"}; - } - - if(!attributes) { - throw {message: "attributes is null or undefined"}; - } - - if((typeof payload) !== "object"){ - throw {message: "payload must be an object", erros: [typeof payload]}; - } -} +const setter_reflections = {}; +setter_reflections[Constants.BINARY_HEADERS_02.TYPE] = "type"; +setter_reflections[Constants.BINARY_HEADERS_02.SOURCE] = "source"; +setter_reflections[Constants.BINARY_HEADERS_02.ID] = "id"; +setter_reflections[Constants.BINARY_HEADERS_02.TIME] = "time"; +setter_reflections[Constants.BINARY_HEADERS_02.SCHEMA_URL] = "schemaurl"; function HTTPBinary02(configuration){ this.config = configuration; @@ -45,26 +28,6 @@ function HTTPBinary02(configuration){ Constants.MIME_CE_JSON + "; charset=" + Constants.CHARSET_DEFAULT; } -HTTPBinary02.prototype.check = function(payload, headers) { - // Validation Level 0 - validate_args(payload, headers); - - // Validation Level 1 - for(i in required_headers){ - if(!headers[required_headers[i]]){ - throw {message: "header '" + required_headers[i] + "' not found"}; - } - } - - // No erros! Its contains the minimum required attributes -} - -HTTPBinary02.prototype.parse = function(payload, headers) { - this.check(payload, headers); - - -} - HTTPBinary02.prototype.emit = function(cloudevent){ // Create new request object @@ -75,14 +38,15 @@ HTTPBinary02.prototype.emit = function(cloudevent){ _headers[Constants.HEADER_CONTENT_TYPE] = cloudevent.getContenttype(); - _headers[Headers02.TYPE] = cloudevent.getType(); - _headers[Headers02.SPEC_VERSION] = cloudevent.getSpecversion(); - _headers[Headers02.SOURCE] = cloudevent.getSource(); - _headers[Headers02.ID] = cloudevent.getId(); + _headers[Constants.BINARY_HEADERS_02.TYPE] = cloudevent.getType(); + _headers[Constants.BINARY_HEADERS_02.SPEC_VERSION] = + cloudevent.getSpecversion(); + _headers[Constants.BINARY_HEADERS_02.SOURCE] = cloudevent.getSource(); + _headers[Constants.BINARY_HEADERS_02.ID] = cloudevent.getId(); if(cloudevent.getTime()) { - _headers[Headers02.TIME] = cloudevent.getTime(); + _headers[Constants.BINARY_HEADERS_02.TIME] = cloudevent.getTime(); } - _headers[Headers02.SCHEMA_URL] = cloudevent.getSchemaurl(); + _headers[Constants.BINARY_HEADERS_02.SCHEMA_URL] = cloudevent.getSchemaurl(); // Set the cloudevent payload _config["data"] = cloudevent.format().data; @@ -91,7 +55,7 @@ HTTPBinary02.prototype.emit = function(cloudevent){ var exts = cloudevent.getExtensions(); for(var ext in exts){ if({}.hasOwnProperty.call(exts, ext)){ - _headers[Headers02.EXTENSIONS_PREFIX + ext] = exts[ext]; + _headers[Constants.BINARY_HEADERS_02.EXTENSIONS_PREFIX + ext] = exts[ext]; } } @@ -100,6 +64,5 @@ HTTPBinary02.prototype.emit = function(cloudevent){ }; module.exports = { - HTTPBinary02, - Headers02 + HTTPBinary02 };