From ceb5c4531af02a720e6dd8e10b6b28bd3453ce1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Jos=C3=A9?= Date: Wed, 14 Nov 2018 22:15:40 -0200 Subject: [PATCH] Document the binding usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio José --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index a4656ce..6b021d3 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,11 @@ Every Spec class must implement these methods to work properly. ```js +/* + * The constructor must receives the Cloudevent type. + */ +Spec(Cloudevent) + /* * Check the spec constraints, throwing an error if do not pass. */ @@ -168,6 +173,35 @@ var formatted = cloudevent.format(); ``` +## Hot to emit the event? + +```js +// The event +var cloudevent = new Cloudevent() + .type("com.github.pull.create") + .source("urn:event:from:myapi/resourse/123"); + +// The binding configuration using POST +var config = { + method: 'POST', + url : 'https://mywebhook.com' +}; + +// The binding instance +var binding = Cloudevent.bindings['http-structured0.1'](config); + +// Emit the event using Promise +binding.emit(cloudevent) + .then(response => { + // Treat the response + console.log(response.data); + + }).catch(err => { + // Treat the error + console.error(err); + }); +``` + > See how to implement the method injection [here](lib/specs/spec_0_1.js#L17) > > Learn about [Builder Design Pattern](https://en.wikipedia.org/wiki/Builder_pattern)