You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

displayer-api-client

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

displayer-api-client

A client library for the Backpack Displayer API

0.1.2
latest
Source
npmnpm
Version published
Weekly downloads
8
100%
Maintainers
1
Weekly downloads
 
Created
Source

displayer-api-client

Example

  var DisplayerAPI = require("displayer-api-client");
  var api = new DisplayerAPI("http://backpack.openbadges.org");

  var user = api.user("someone@example.org");

  user.id(function (err, id) {
    console.log("Looked up user id, and it is", id);
  });

  user.groups(function (err, groups) {
    console.log("Looked up user groups, and they are", groups);
  });

  user.group(10, function (err, badges) {
    console.log("Looked up group 10, and the badges in it are", badges);
  });

ID lookups are cached, but group lookups are not. You may also provide the user id if known to skip that step, like so:

  var user = api.user({
    id: 1,
    email: "optional@example.org"
  });

Callback Styles

All of the user methods support three styles of invocation:

  user.id(function callback (err, id) {});                        // node style callback
  user.id(function success (id) {}, function failure (err) {});   // success/failure style callbacks
  var idPromise = user.id();                                      // promises 

If additional arguments are needed, they preceed the callbacks (if any).

Promises are implemented by bluebird.

Streams

There are two additional methods that return JSONStream streams:

  var g = user.getGroupStream();
  g.on("data", function (data) {
    console.log("A group:", data);
  });

  var b = user.getBadgeStream(10);
  b.on("data", function (data) {
    console.log("A badge in group 10:", data);
  });

FAQs

Package last updated on 09 Apr 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