From 4d79e112846ac84f3acfb9a5034322b2e4f863c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Jos=C3=A9?= Date: Mon, 17 Dec 2018 21:10:12 -0200 Subject: [PATCH] http binary wip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio José --- lib/bindings/http/binary_0_1.js | 6 ++++++ lib/cloudevent.js | 16 ++++++++++++++++ lib/specs/spec_0_1.js | 16 ++++++++++++++++ lib/specs/spec_0_2.js | 12 ++++++++++++ test/http_binding_0_1.js | 4 ++++ 5 files changed, 54 insertions(+) diff --git a/lib/bindings/http/binary_0_1.js b/lib/bindings/http/binary_0_1.js index 6e47eaf..2454ec3 100644 --- a/lib/bindings/http/binary_0_1.js +++ b/lib/bindings/http/binary_0_1.js @@ -18,6 +18,12 @@ HTTPBinary.prototype.emit = function(cloudevent){ _headers["Content-Type"] = cloudevent.getContenttype(); _headers["CE-EventType"] = cloudevent.getType(); + _headers["CE-CloudEventsVersion"] = cloudevent.getSpecversion(); + + _headers["CE-Source"] = cloudevent.getSource(); + _headers["CE-EventID"] = cloudevent.getId(); + _headers["CE-EventTime"] = cloudevent.getTime(); + _headers["CE-SchemaURL"] = cloudevent.getSchemaurl(); // Set the cloudevent payload _config["data"] = cloudevent.format(); diff --git a/lib/cloudevent.js b/lib/cloudevent.js index 64b5c3b..e3a1591 100644 --- a/lib/cloudevent.js +++ b/lib/cloudevent.js @@ -47,21 +47,37 @@ Cloudevent.prototype.source = function(_source){ return this; }; +Cloudevent.prototype.getSource = function(){ + return this.spec.getSource(); +}; + Cloudevent.prototype.id = function(_id){ this.spec.id(_id); return this; }; +Cloudevent.prototype.getId = function() { + return this.spec.getId(); +}; + Cloudevent.prototype.time = function(_time){ this.spec.time(_time); return this; }; +Cloudevent.prototype.getTime = function() { + return this.spec.getTime(); +}; + Cloudevent.prototype.schemaurl = function(_schemaurl) { this.spec.schemaurl(_schemaurl); return this; }; +Cloudevent.prototype.getSchemaurl = function() { + return this.spec.getSchemaurl(); +}; + Cloudevent.prototype.contenttype = function(_contenttype){ this.spec.contenttype(_contenttype); return this; diff --git a/lib/specs/spec_0_1.js b/lib/specs/spec_0_1.js index c566c3e..aca4164 100644 --- a/lib/specs/spec_0_1.js +++ b/lib/specs/spec_0_1.js @@ -55,21 +55,37 @@ Spec01.prototype.source = function(_source){ return this; }; +Spec01.prototype.getSource = function() { + return this.payload["source"]; +}; + Spec01.prototype.id = function(_id){ this.payload["eventID"] = _id; return this; }; +Spec01.prototype.getId = function() { + return this.payload["eventID"]; +}; + Spec01.prototype.time = function(_time){ this.payload["eventTime"] = _time.toISOString(); return this; }; +Spec01.prototype.getTime = function() { + return this.payload["eventTime"]; +}; + Spec01.prototype.schemaurl = function(_schemaurl){ this.payload["schemaURL"] = _schemaurl; return this; }; +Spec01.prototype.getSchemaurl = function() { + return this.payload["schemaURL"]; +}; + Spec01.prototype.contenttype = function(_contenttype){ this.payload["contentType"] = _contenttype; return this; diff --git a/lib/specs/spec_0_2.js b/lib/specs/spec_0_2.js index a4620c9..9f790fc 100644 --- a/lib/specs/spec_0_2.js +++ b/lib/specs/spec_0_2.js @@ -54,16 +54,28 @@ Spec02.prototype.id = function(_id){ return this; }; +Spec02.prototype.getId = function() { + return this.payload["id"]; +}; + Spec02.prototype.time = function(_time){ this.payload["time"] = _time.toISOString(); return this; }; +Spec02.prototype.getTime = function() { + return this.payload["time"]; +}; + Spec02.prototype.schemaurl = function(_schemaurl){ this.payload["schemaurl"] = _schemaurl; return this; }; +Spec02.prototype.getSchemaurl = function() { + return this.payload["schemaurl"]; +}; + Spec02.prototype.contenttype = function(_contenttype){ this.payload["contenttype"] = _contenttype; return this; diff --git a/test/http_binding_0_1.js b/test/http_binding_0_1.js index 023ce50..89278ae 100644 --- a/test/http_binding_0_1.js +++ b/test/http_binding_0_1.js @@ -6,6 +6,8 @@ const type = "com.github.pull.create"; const source = "urn:event:from:myapi/resourse/123"; const webhook = "https://cloudevents.io/webhook"; const contentType = "application/cloudevents+json; charset=utf-8"; +const now = new Date(); +const schemaurl = "http://cloudevents.io/schema.json" const ceContentType = "application/json"; @@ -21,6 +23,8 @@ var cloudevent = .type(type) .source(source) .contenttype(ceContentType) + .time(now) + .schemaurl(schemaurl) .data(data); var httpcfg = {