Browser + Node.js support for sending events to a Pyroclast topic.
npm install --save pyroclastFirst, start the client.
const pyroclast = require('pyroclast');
const topicClient = new pyroclast.PyroclastTopicClient({
writeApiKey: "<your api token>",
readApiKey: "<your api token>",
topicId: "<your topic ID>"
});topicClient
.sendEvent({value: {type: "page-visit", page: "/home", timestamp: 1495072835000}})
.then((result) => {
// ...
});topicClient
.sendEvents([
{value: {type: "page-visit", page: "/home", timestamp: 1495072835000}},
{value: {type: "page-visit", page: "/home", timestamp: 1495072836000}},
{value: {type: "page-visit", page: "/home", timestamp: 1495072837000}}
])
.then((results) => {
// ...
});Start the client.
const pyroclast = require('pyroclast');
const topicClient = new pyroclast.PyroclastTopicClient({
readApiKey: "<your api token>",
topicId: "<your topic ID>"
});topicClient.subscribe("my-example-subscription").then(
(consumerInstance) => {
//...
})consumerInstance.poll()
.then((result) => {
// ...
});consumerInstance.commit()
.then((result) => {
// ...
});Supplying a Fetch implementation
By default:
- In the browser, the native
window.fetchimplementation is used, if available (as in modern browsers). - In Node.js,
node-fetchis used.
To override this behavior:
- (Browser/Node.js) Pass the implementation as the
fetchImploption, or - (Browser only) Use a polyfill to define fetch globally.
Note that to support older browsers, you will likely also need a Promise polyfill.
(The MIT License)
Copyright © 2017 Distributed Masonry