0.2.3 • Published 6 years ago
pyroclast v0.2.3
pyroclast-js
Browser + Node.js support for sending events to a Pyroclast topic.
Installation
npm install --save pyroclast
Topic APIs
Write events
First, start the client.
const pyroclast = require('pyroclast');
const topicClient = new pyroclast.PyroclastTopicClient({
writeApiKey: "<your api token>",
readApiKey: "<your api token>",
topicId: "<your topic ID>"
});
Send one event asynchronously
topicClient
.sendEvent({value: {type: "page-visit", page: "/home", timestamp: 1495072835000}})
.then((result) => {
// ...
});
Send a batch of events asynchronously
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) => {
// ...
});
Reading events
Start the client.
const pyroclast = require('pyroclast');
const topicClient = new pyroclast.PyroclastTopicClient({
readApiKey: "<your api token>",
topicId: "<your topic ID>"
});
Subscribe to a topic
topicClient.subscribe("my-example-subscription").then(
(consumerInstance) => {
//...
})
Poll subscribed topic
consumerInstance.poll()
.then((result) => {
// ...
});
Commit read records
consumerInstance.commit()
.then((result) => {
// ...
});
Supplying a Fetch implementation
By default:
- In the browser, the native
window.fetch
implementation is used, if available (as in modern browsers). - In Node.js,
node-fetch
is used.
To override this behavior:
- (Browser/Node.js) Pass the implementation as the
fetchImpl
option, or - (Browser only) Use a polyfill to define fetch globally.
Note that to support older browsers, you will likely also need a Promise polyfill.
License
(The MIT License)
Copyright © 2017 Distributed Masonry