GithubHelp home page GithubHelp logo

sensors-2's Introduction

LocalData Sensors API

An API for lightweight, time-series data streams

Usage

Create a source

POST /api/v1/sources

The POST can be empty or can have an application/json body with the following structure:

{
  "data" : {
    "field1" : "some value",
    "field2" : "maybe an e-mail address?"
  }
}

The fields under data are optional and flexible. They're intended to convey source metadata, like the email address of the user creating the source, a device name for the source, etc.

The response contains the client ID for the source as well as a secret access token for sending sensor data:

{
  "id": "ci4omwt7k0003nm0u92mt03al",
  "token": "43721161-e044-48e5-af64-7f3761c8f3a9"
}

Get source info

GET /api/v1/sources/ci4omwt7k0003nm0u92mt03al

Response:

{
  "id": "ci4omwt7k0003nm0u92mt03al",
  "data": {
    "name": "Prashant Singh",
    "email": "[email protected]",
    "device": "Roboto 2000",
    "city": "San Francisco"
  }
}

Send data

Sending data requires the authorization token, formatted into a bearer token authorization header. If the token is 43721161-e044-48e5-af64-7f3761c8f3a9, then the bearer string comes from the Base64 encoding of :43721161-e044-48e5-af64-7f3761c8f3a9 (a colon prepended to the token). This is modeled after Heroku's token-based authorization and allows the use of a username/id in the Bearer string if needed later. For this example, the authorization header would be:

Authorization: Bearer OjQzNzIxMTYxLWUwNDQtNDhlNS1hZjY0LTdmMzc2MWM4ZjNhOQ==

A sample POST might be

POST /api/v1/sources/ci4omwt7k0003nm0u92mt03al/entries HTTP/1.1
Host: localdata-sensors.herokuapp.com
Content-Type: application/json
Authorization: Bearer OjQzNzIxMTYxLWUwNDQtNDhlNS1hZjY0LTdmMzc2MWM4ZjNhOQ==

{
  "timestamp": 1420754284000, "air": 1.5, "uv": 0.3, "temp": 44.2, "location": [-122.4136490,37.7756410]
}

Read data

Read data in pages, in ascending chronological order:

GET /api/v1/sources/ci4omwt7k0003nm0u92mt03al/entries?startIndex=0&count=10

Get the latest 10 results (read data in pages, in descending chronological order):

GET /api/v1/sources/ci4omwt7k0003nm0u92mt03al/entries?startIndex=0&count=10&sort=desc

Get the entries in a time range (limited to 1000 results), including the first boundary, excluding the second boundary:

GET /api/v1/sources/ci4omwt7k0003nm0u92mt03al/entries?from=2015-01-14T00:00:00-0800&before=2015-01-15T00:00:00-0800

The API also supports after for an exclusive start time and until for an inclusive end time. startIndex and count are honored for time range queries, in case you need to retrieve more than 1000 results. Alternatively, you can use the last timestamp of the result set as the after parameter of the subsequent query.

Dependencies

The API stores data in a PostgreSQL database. It uses the JSON datatype but does not currently use the PL/V8 language extension.

Tests

Tests use a test.env file to configure environment variables. See test.env.sample for an example. Run tests with

make test

Migrations

The Sequelize configurations point to the DATABASE_URL environment variable. Run migrations against the test db locally with

envrun -e test.env --path node_modules/.bin/sequelize db:migrate

Or use node_modules/.bin/envrun if you don't have envrun installed globally.

sensors-2's People

Contributors

prashtx avatar

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.