Skip to content
This repository was archived by the owner on Jul 11, 2018. It is now read-only.

PyroclastIO/pyroclast-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A JavaScript client for Pyroclast

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •