displayer-api-client
v0.1.2
Published
A client library for the Backpack Displayer API
Downloads
8
Readme
displayer-api-client
Example
var DisplayerAPI = require("displayer-api-client");
var api = new DisplayerAPI("http://backpack.openbadges.org");
var user = api.user("[email protected]");
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: "[email protected]"
});
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);
});