Keymetrics API Wrapper
This module lets you implement a fully customizable Keymetrics client, receiving live data from the Keymetrics API.
You will need to retrieve your Keymetrics user token to use it.
For more informations about the data structures and API calls check out the documentation.
We designed 2 ways to start the module: via callback or events.
Install
With NPM:
$ npm install keymetrics-api --save
Usage example
var Keymetrics = ; var km = token: '[token]' public_key: '[public_key]' realtime: true; km;
Options
token
(Required): Refresh token obtained from the Keymetrics dashboard.token_type
(Optional): Token type (refresh_token
oraccess_token
)public_key
(Optional): When defined, lets you retrieve the correct bucket.realtime
(Optional): When defined with public_key, launches the websocket session at start.
This snippet makes 3 successive calls (if all options are set):
- POST to get and access_token from the servers
- GET to retrieve the correct bucket informations
- POST to set the Bucket active and initialize the Websocket connection.
Basic use - events
bus
is broadcasting events corresponding to every step of the authentication process.
In this example we start the authentication, then retrieve the bucket and finally start the realtime interaction.
var km = token: '[token]'; //When authenticatedkmbus; //When bucket is retrievedkmbus; //When realtime startskmbus; //Retrieve access_tokenkm;
List of broadcasted events:
Authenticate
- auth:ready
Bucket
- bucket:active
Realtime
- realtime:on
- realtime:off
- realtime:reconnect
- realtime:reconnect-timeout
- realtime:auth
- raw:[server_name]:status
- data:[server_name]:status
- data:[server_name]:server_name
- data:[server_name]:monitoring
User
- user:logged_in
- user:logged_out
Error
- error:auth
- error:realtime
- error:bucket
DEBUG=*
allows verbose mode for received realtime data.
License
Apache 2.0