Git Product home page Git Product logo

gaugesjs's Introduction

gauges.js

Exposing the gauges API to NodeJS - one endpoint at a time. Maybe two.

Advanced Usage

Initializing the API

Initialize the gauges API. This part might seem a bit unnecessary, but it is required for GaugesJS to learn Gauges endpoints. Instead of hard-coding them, GaugesJS reads the gauges API and exposes them as necessary.

var gauges = require('gaugesjs'),
    client = gaugesjs.client();

client.init(function get_api(err, api) {
  # The `api` object is what we use to access the Gauges API.
  # After this is called, endpoints are also accessible as `client.api`.
});

Normally, GaugesJS will look for an environment variable called GAUGES_TOKEN. In order to get your authenticatino token. If you prefer to provide this via any other means, you may also pass it as an option to the client function.

var gauges = require('gaugesjs'),
    client = gauges.client({
      token: '...'
    });

Listing your gauges

After initializing the API's endpoints, you can get a list of your gauges like this:

var gaugesjs = require('gaugesjs'),
    client = gaugesjs.client();

client.init(function get_api(err, api) {
  api.gauges(function get_gauges(err, gauges) {
    # The `gauges` variable now contains a list of your gauges.
  })
});

Listing your clients

After initializing the API's endpoints, you can get a list of your API clients like this:

var gaugesjs = require('gaugesjs'),
    client = gaugesjs.client();

client.init(function get_api(err, api) {
  api.clients(function get_clients(err, clients) {
    # The `clients` variable now contains a list of your API's
    # authorized clients.
  })
});

Raw usage

As the Gauges API is always evolving, it is important to provide raw API access to developers. The internal mechanism that is used to create API requests is exposed by GaugesJS for this reason. When Gauges gives you an API URL, you can make use of this method to make the request.

As one example, you might want to see which locations are being tracked by a gauge. Here's an example:

var gaugesjs = require('gaugesjs'),
    client = gaugesjs.client();

client.init(function get_api(err, api) {
  api.gauges(function get_clients(err, gauges) {
    var get_locations = api.make_request(gauges.gauges[0].urls.locations);

    get_locations(function (err, locations) {
      # The `locations` variable now contains all locations related to
      # your first gauge in the `gauges` variable.
    });
  })
});

gaugesjs's People

Contributors

monokrome avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

monokrome

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.