#Initial State Initial State is a hosted service that allows you to easily push event based data.
This library wraps Initial State Event API (aka groker).
Instantiate the InitialState class with your Access Key, Bucket Key, and optionally, Bucket Name:
is <- InitialState(IS_ACCESS_KEY, IS_BUCKET_KEY, "optional bucket name");
There are two methods to send events to Initial State. One method is.sendEvent
is for singular events. The other method is.sendEvents
is for a batch of events. If a third parameter, a callback function, is supplied, the request will be made asyncronously and the callback will be fired when the request is complete. If the callback function is ommited, the request will be made syncronously, and result will be returned. Examples of each usage are below:
####Sending Single Event
// send an event sycronously
local result = is.sendEvent("temperature", 72);
if (result.err != null) {
server.log("Error: " + result.err);
}
// send an event asyncronously
is.sendEvent("temperature", 72, function(err, data) {
if (err != null) {
server.log("Error: " + err);
}
});
####Sending Multiple Events (i.e. sensor readings)
// send an event sycronously
local result = is.sendEvents([
{"key": "temperature", "value": 72},
{"key": "humidity", "value": 55}
]);
if (result.err != null) {
server.log("Error: " + result.err);
}
// send an event asyncronously
is.sendEvents([
{"key": "temperature", "value": 72},
{"key": "humidity", "value": 55}
], function(err, data) {
if (err != null) {
server.log("Error: " + err);
}
});
You can optionally override the timestamp of an event by passing in an epoch
to the .sendEvent
or .sendEvents
methods. Here is how to achieve this respectively:
// override timestamp for single event
local time = time();
is.sendEvent("temperature", 72, time);
// override timestamp for multiple events
is.sendEvents([
{"key": "temperature", "value": 72, "epoch": time },
{"key": "humidity", "value": 55, "epoch": time }
]);
The Initial State library is licensed under the MIT License.