New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

demosteinkjer-api

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

demosteinkjer-api

Node.js client for the Demo Steinkjer API.

  • 0.2.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

demosteinkjer-api

See https://api.demosteinkjer.no/ for documentation. The API requires a key and a secret to be used.

var api = require('demosteinkjer-api')('key', 'secret');

To get time series data for a given meter, a download url must first be obtained.

api.requestDownloadURL(meterID, options, function(downloadURL) {
  console.log(downloadURL);
});

Although you receive a link, it will not be immediately available to use. This can be solved in multiple ways. If one tries to send a GET request to a resource that is not yet available. A response code of 202 will be returned. Thus you can keep on sending requests until it becomes available (check for status code) or you can download the url ahead of time to be somewhat certain it will be available when you need it.

var intervalId = setInterval(function() {
  api.readDownloadURL(downloadURL, function(err, readings) {
    if (err) return;
    console.log(readings);
    clearInterval(intervalId);
  });
}, 1000);

Get the latest reading for a meter

To get the latest reading for a meter, a url must not be obtained first:

api.getLatestMeterReading(meterID, function(err, res) {
  console.log(res);
});

Minute Readers

Some of the meters have minute precision. Their IDs are available in the object api.minuteReaders.

Caching

It is wise to cache results from the API, both meter readings and download urls. Redis is a wise choice for such a task. One way to do it is to create a key hash made of the meter id and the options for that reading

function hash() {
  return [].slice.apply(arguments).reduce(function(h, e) {
    return h + JSON.stringify(e);
  }, '');
}

var key hash(meterID, options)

and store it in redis

var client = require('redis').createClient();
client.set(key, data)

where key is a hash made using any method you'd prefer and data is the data for that request.

License

MIT

FAQs

Package last updated on 27 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc