bothan-api

0.0.2 • Public • Published

Build Status Code Climate Coverage Status NPM Version License

bothan.js

A node.js client for Bothan, a simple platform for storing and publishing metrics.

Installation

npm install bothan-api

Testing

npm test

Usage

First require the Bothan client:

bothan = require('bothan')

Then initialize a connection with your username, password and the url of your Bothan endpoint:

bothan = new Bothan({user: 'username', pass: 'password', endpoint: 'https://demo.bothan.io'})

You will then be able to interact with your Bothan API like so:

Get all metrics

Returns a list of available metrics as an array of objects

bothan.listMetrics(function(data) {
  console.log(data)
})

Find a metric

Latest value

Returns the latest value for a specified metric as an object

bothan.getMetric({'metric': 'simple-metric'}, function(data) {
  console.log(data)
})

For a specific DateTime

Returns the most recent value of a metric at the specified datetime.

bothan.getMetric({'metric': 'simple-metric', 'time': '2016-12-12T07:00:24.465+00:00'}, function(data) {
  console.log(data)
})

For a specific DateTime range

Returns all values of the metric between the specified times.

bothan.getMetric({'metric': 'simple-metric', 'from': '2016-12-01T07:00:22.851+00:00', 'to': '2016-12-05T07:00:22.459+00:00'}, function(data) {
  console.log(data)
})

Create a metric

The Bothan API supports four types of metric, all supported by the gem.

Create a simple metric

// Create a metric called 'my-new-metric' with a value of '12' at the current datetime
bothan.createMetric({name: 'my-new-metric', value: 123}, function(data) {
  console.log(data)
})
// Create a metric with a specific datetime
bothan.createMetric({name: 'my-new-metric', value: 123, time: '2016-12-23T00:00:00.000+00:00'}, function(data) {
  console.log(data)
})

Create a metric with a target

// Create a metric called 'my-new-metric' with a value of '1091000', an annual target of '2862000' and a ytd target of '1368000' at the current datetime
bothan.createTargetMetric({name: 'my-new-target-metric', actual: 1091000, annual_target: 2862000, ytd_target: 1368000}, function() {
  console.log(data)
})
// Create a metric with a target at a specific datetime
bothan.createTargetMetric({name: 'my-new-target-metric', actual: 1091000, annual_target: 2862000, ytd_target: 1368000, time: '2016-12-23T00:00:00.000+00:00'}, function() {
  console.log(data)
})
// Create a metric without a ytd target
bothan.createTargetMetric({name: 'my-new-target-metric', actual: 1091000, annual_target: 2862000}, function() {
  console.log(data)
})
// Create a metric without a ytd target at a specific datetime
bothan.createTargetMetric({name: 'my-new-target-metric', actual: 1091000, annual_target: 2862000, time: '2016-12-23T00:00:00.000+00:00'}, function() {
  console.log(data)
})

Create a metric with multiple values

// Create a metric called 'my-new-metric' with multiple values with the current datetime
bothan.createMultipleMetric({name: 'my-new-metric', values: {
  'value1': 123,
  'value2': 23213,
  'value4': 1235
}}, function(data) {
  console.log(data)
})
 
// Create a metric called 'my-new-metric' with multiple values with a specific datetime
bothan.createMultipleMetric({name: 'my-new-metric', values: {
  'value1': 123,
  'value2': 23213,
  'value4': 1235
}, time: '2016-12-23T00:00:00.000+00:00'}, function(data) {
  console.log(data)
})

Create a metric with geodata

// Create a geodata metric called 'my-new-metric' with the current datetime
bothan.createGeoMetric({name: 'my-new-metric', values: {
  'type' => 'Feature',
  'geometry' => {
    'type' => 'Point',
    'coordinates' => [-2.6156582783015017, 54.3497405310758]
  }
},
{
  'type' => 'Feature',
  'geometry' => {
    'type' => 'Point',
     'coordinates' => [-6.731370299641439, 55.856756177781186]
  }
}
}, function(data) {
  console.log(data)
})
 
// Create a geodata metric called 'my-new-metric' with a specific datetime
bothan.createGeoMetric({name: 'my-new-geometric', values: {
  'type' => 'Feature',
  'geometry' => {
    'type' => 'Point',
    'coordinates' => [-2.6156582783015017, 54.3497405310758]
  }
},
{
  'type' => 'Feature',
  'geometry' => {
    'type' => 'Point',
     'coordinates' => [-6.731370299641439, 55.856756177781186]
  }
}, time: '2016-12-23T00:00:00.000+00:00'}, function(data) {
  console.log(data)
})

Development

After checking out the repo, run npm install to install dependencies. Then, run npm test to run the tests.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/theodi/bothan.js. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Readme

Keywords

none

Package Sidebar

Install

npm i bothan-api

Weekly Downloads

3

Version

0.0.2

License

none

Last publish

Collaborators

  • pezholio