npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

imp-api

v0.2.9

Published

Javascript wrapper for the Electric Imp Build API

Downloads

31

Readme

Imp Build

A Javascript wrapper for the Electric Imp Build API.

NOTE: Electric Imp's Build API is currently in a closed beta. This note will be removed when the API is ready for public consumption.

Installation

npm install imp-api

Instantation

The imp object must be instantiated with an apiKey - you can optionally pass an apiBase and apiVersion parameter to overload the defaults.

var Imp = require("imp-api");

var imp = new Imp({
  "apiKey": "<-- YOUR API KEY -->"
});

Devices

imp.getDevices(options, callback)

Returns a list of devices associted to the account. You can pass a table with any of the following options to filter the list: device_id, mac_address, model_id, name.

// get all devices with 'test' in the name
imp.getDevices({ "name": "test", function(err, data) {
  if (err) {
    console.log(err);
    return;
  }

  data.devices.forEach(function(device) {
    console.log(device);
  });
});

imp.getDevice(deviceId, callback)

Returns information about a specific device.

imp.getDevice("<-- device_id -->", function(err, data) {
  if(err) {
    console.log(err);
    return;
  }

  console.log(data);
});

imp.assignDevice(deviceId, modelId, callback)

Assigns a device to a specific model, and immediatly starts running the code.

imp.assignDevice("<-- device_id -->", "<-- model_id -->", function(err, data) {
  if (err) {
    console.log(err);
    return;
  }

  console.log("Success!!");
});

Passing null as the modelId will unassign the device from it's current model.

imp.deleteDevice(deviceId, callback)

Deletes a device from your account (note: the next time the device comes online / communicates with the Electric Imp service it will re-register itself with your account).

imp.deleteDevice("<-- device_id -->", function(err, data) {
  if (err) {
    console.log(err);
    return;
  }

  console.log("Success!!");
});

Device Logs

imp.getDeviceLogs(deviceId, options, callback)

Returns up to the last 200 messages from a specified device and its agent. You can pass a table with any of the following options to filter the list: since (), type ().

// Get agent messages
imp.getDeviceLogs("<-- device_id -->", { "type": "agent.log" }, function(err, data) {
  if (err) {
    cons.log(err);
    return;
  }

  data.logs.forEach(function(log) {
    console.log(log.timestamp + " " + log.type + "\t" + log.message);
  });
});

imp.streamDeviceLogs(deviceId, callback)

Continuously streams logs from the specified device and its agent. Each time new logs appear, the callback will be invoked:

imp.StreamDeviceLogs("<-- device_id -->", function(err, data) {
  if (err) {
    console.log(err);
    return;
  }

  data.logs.forEach(function(log) {
    console.log(log.timestamp + " " + log.type + "\t" + log.message);
  });
});

Models

imp.getModels(options, callback)

Returns a list of models associted to the account. You can pass a table with any of the following options to filter the list: name.

// get all models with 'test' in the name
imp.getModels({ "name": "test", function(err, data) {
  if (err) {
    console.log(err);
    return;
  }

  data.models.forEach(function(model) {
    console.log(model);
  });
});

imp.getModel(modelId, callback)

Returns information about a specific model.

imp.getModel("<-- model_id -->", function(err, data) {
  if(err) {
    console.log(err);
    return;
  }

  console.log(data);
});

imp.createModel(options, callback)

Creates a new model in the associated account.

imp.createModel("New Model Name", function(err, data) {
  if(err) {
    console.log(err);
    return;
  }

  console.log("Success - created model with id: " + data.model.id);
});

imp.restartModel(modelId, callback)

Restarts all devices and agents associated to a model.

imp.restartModel("<-- model_id -->", function(err, data) {
  if(err) {
    console.log(err);
    return;
  }

  console.log("Success!!");
});

imp.deleteModel(modelId, callback)

Deletes the specified model and all code associated with it - you cannot delete a model that has devices assigned to it.

imp.deleteModel("<-- model_id -->", function(err, data) {
  if(err) {
    console.log(err);
    return;
  }

  console.log("Success!!");
});

Model Revisions

imp.getModelRevisions(modelId, options, callback)

Returns a list of code revisions for the specified model. You can pass a table with any of the following options to filter the list: since, until, build_min, build_max.

// 1800000 milliseconds = 30 minutes
var thirtyMinutesAgo = Date.now() - 1800000;

imp.getModelRevisions("<-- model_id -->", { "since": thirtyMinutesAgo }, function(err, data) {
  if (err) {
    console.log(err);
    return;
  }

  data.revisions.forEach(function(revision) {
    console.log(revision);
  });
});

imp.getModelRevision(modelId, version, callback)

Returns the code and metadata of a specified version.

imp.getModelRevision("<-- model_id -->", versionNumber, function(err, data) {
  if (err) {
    console.log(err);
    return;
  }

  console.log(data.revision);
});

imp.createModelRevision(modelId, model, callback)

Pushes a new revision to the model. After creating a new revision, you need to call restartModel for the code to be sent to the devices assigned to the specified model. The model object must contain agent_code and device_code and can also include release_notes and marker (63 characters max that can be used like GIT tags).

var deviceCode = "server.log(\"Device Started!\");";
var agentCode = "server.log(\"Agent Started!\");";

var model = { "device_code": deviceCode, "agent_code": agentCode };

imp.createModelRevision("<-- model_id -->", model, function(err, data) {
  if (err) {
    console.log(err);
    return;
  }

  imp.restartModel("<-- model_id -->", function(err, data) {
    if (err) {
      console.log(err);
      return;
    }

    console.log("Success!");
  });
});

LICENSE

imp.js is licenced under the MIT License.