Skip to content

Avocarrot/reporting-api-client

Repository files navigation

reporting-api-client

CircleCI

A thin Avocarrot reporting API consumer

Development

Please see the CONTRIBUTING instructions before contributing to this repository


Getting Started

Install the required dependencies

make yarn
make npm

To build the library use

npm start

Tests

To run the tests use

npm test

To produce a test coverage report use

npm run cov

You can access the report by running open coverage/lcov-report/index.html.

▶️ Code coverage results for the latest build


API Reference

To generate the JSDoc API Reference run

npm run docs

You can access the generated docs by running open docs/index.html

▶️ API Reference for the latest build


Usage

Setup

Initialize client

/**
 * Initialize ReportingAPIClient
 */
var ReportingAPIClient = require('reporting-api-client');

var client = new ReportingAPIClient({
  host: 'http://reporting.avocarrot.com/v1'
});

Configure credentials

/**
 * Set your credentials and resource to fetch data from
 *
 * @memberof ReportingAPIClient
 * @method setCredentials
 * @param {String} resource - The resource to fetch from
 * @param {String} access_token - The access token to use
 * @return {Void}
 */
client.setCredentials('<resource>', '<access_token>');

Fetch data

Fetch totals

/**
 * Returns totals from API
 *
 * @memberof ReportingAPIClient
 * @method getTotals
 * @param {Array} propertiesArray
 * @param {Object} propertiesArray[0] - properties: The configuration properties to use (timestamp, filters)
 * @return {Promise}
 */
client.getTotals([{
  timestamp: {
    from: '2016-01-07T00:00:00.000Z',
    to: '2016-01-08T00:00:00.000Z'
  },
  filters: {
    country: 'USA',
    // ...
  }
}]).then(function(data) {
  //...
});

Fetch breakdown

/**
 * Returns breakdown data from Reporting API
 *
 * @memberof ReportingAPIClient
 * @method getBreakdown
 * @param {Array} propertiesArray
 * @param {Object} propertiesArray[0] - properties: The configuration properties to use (timestamp, filters, granularity, groups)
 * @return {Promise}
 */
client.getBreakdown([{
  timestamp: {
    from: '2016-01-07T00:00:00.000Z',
    to: '2016-01-08T00:00:00.000Z'
  },
  filters: {
    country: 'USA',
    // ...
  },
  group: {
    groups: ['country', 'platform'],
    // ...
  }
}]).then(function(data) {
  //...
});

Fetch timeseries

/**
 * Returns timeseries from Reporting API
 *  - Granularity split should always be in the back of the splits queue
 *
 * @memberof ReportingAPIClient
 * @method getTimeseries
 * @param {Array} propertiesArray
 * @param {Object} propertiesArray[0] - properties: The configuration properties to use (timestamp, filters, granularity, groups)
 * @return {Promise}
 */
client.getBreakdown([{
  timestamp: {
    from: '2016-01-07T00:00:00.000Z',
    to: '2016-01-08T00:00:00.000Z'
  },
  filters: {
    country: 'USA',
    // ...
  },
  granularity: 'hour',
  group: {
    groups: ['granularity', 'platform'],
    // ...
  }
}]).then(function(data) {
  //...
});

Versioning

For the versions available, see the releases for this repository.