1.0.11 • Published 4 years ago

@kuuki/luftdaten-events v1.0.11

Weekly downloads
12
License
ISC
Repository
-
Last release
4 years ago

lerna GitHub

kuuki/luftdaten-events is an event based API wrapper for Luftdaten, written in TypeScript.

More info on Luftdaten APIs here.

This library provides the following functionality:

  • Load the state from a leveldb automatically.
  • Poll API endpoints with a crontab setting.
  • Retrieve all latest (5min) measurements.
  • Retrieve all latest measurements with sensor type filter.
  • Retrieve all latest measurements with area filter.
  • Retrieve all latest measurements with box filter.
  • Retrieve all latest measurements with country filter.
  • Retrieve an average of all latest measurements of a sensor (5min).
  • Retrieve an average of all measurements of a sensor (1h).
  • Retrieve an average of all measurements of a sensor (24h).
  • Strictly typed models.

Provided events:

  • measurement - Emitted when a unique measurement has been registered.
  • log - TODO
  • error - TODO

About

This library focuses on providing a strictly type API definition and acces to EventEmitter, exposing further functionality. What's happening under the hood is, that the state is stored in LevelDB and updated once in a while, emitting a measurement event to the listeners on each unique measurement insert operation.

If you only need something simple - check out @kuuki/lufdaten.

Installation

@kuuki/luftdaten-events requires Node.js to run on the backend.

$ npm install --save @kuuki/luftdaten @kuuki/luftdaten-events

Usage

const luftdaten = require("@kuuki/luftdaten");
const luftdatenEvents = require("@kuuki/luftdaten-events");

const ld = new luftdaten.LuftdatenService();
const repo = new luftdatenEvents.MeasurementRepository();
const lde = new luftdatenEvents.LuftdatenEventsService(ld, repo);

(async () => {
  await lde.track({ // insert only the endpoints you want to poll for
    getLatestMeasurements: {
      crontab: "* * * * * *" // fire an update every minute
      // ...other args if needed
    }
  });
  lde.on("measurement", m => {
    // save to db or some other stuff
    console.log([m.data.id, m.data.timestamp]);
    console.log(m);
  })
})();

Documentation

Generated docs are placed in the root /docs folder, you can preview them under this link, however the d.ts files should do just fine if you have your code editor and environment set up correctly.

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago