obf-connector
Version:
An API connector for Open Badge Factory
109 lines (90 loc) • 2.69 kB
JavaScript
const OBFConnector = require('./lib/obf/Connector');
const uuid = require('uuid/v4');
const cool = require('cool-ascii-faces');
module.exports = OBFConnector;
const connector = new OBFConnector('NM70OHe7HCeO', 'certificate', 'obf.key');
switch (process.argv[2].toLowerCase()) {
case 'createbadge': testCreateBadge(); break;
case 'getearnablebadges': testGetEarnableBadges(); break;
case 'getearnablebadge': testGetEarnableBadge(); break;
case 'getevents': testGetEvents(); break;
case 'addcreator': addCreator(); break;
case 'getcreatorslist': getCreatorsList(); break;
case 'modifybadge': modifyBadge(); break;
case 'modifycreator': modifyCreator(); break;
case 'applyforbadge': applyForBadge(); break;
case 'reviewapplications': reviewApplications(); break;
default: console.warn('Unrecognized test');
}
function logJSON(object) {
console.log(JSON.stringify(object));
}
function testGetEarnableBadges() {
connector.getEarnableBadges((err, response) => {
if (err) throw err;
logJSON(response);
});
}
function testGetEarnableBadge() {
connector.getEarnableBadge('OM3L92a22Ca4V', (err, response) => {
if (err) throw err;
logJSON(response);
});
}
function testGetEvents() {
connector.getEvents((err, response) => {
if (err) throw err;
logJSON(response);
});
}
function testCreateBadge() {
const badge = {
name: 'API-Created-Badge' + uuid(),
description: 'This badge has been created via the API',
draft: true
}
connector.createBadge(null, badge, (err, response) => {
if (err) throw err;
logJSON(response);
});
}
function addCreator() {
connector.addCreator({id: 'someid'}, (err, response) => {
if (err) throw err;
logJSON(response);
});
}
function getCreatorsList() {
connector.getCreatorsList((err, response) => {
if (err) throw err;
logJSON(response);
});
}
function modifyBadge() {
const badgePatch = {
id: 'O9U46BaAA4aY',
name: cool()
}
connector.modifyBadge(null, badgePatch, (err, response) => {
if (err) throw err;
logJSON(response);
})
}
function modifyCreator() {
connector.modifyCreator({id: 'O9H4HEaKF8a10'}, (err, response) => {
if (err) throw err;
logJSON(response);
});
}
function applyForBadge() {
connector.applyForBadge(null, 'OM3L92a22Ca4V', (err, response) => {
if (err) throw err;
logJSON(response);
});
}
function reviewApplications() {
connector.reviewApplications(null, 'OJPK62a4E6aP', (err, response) => {
if (err) throw err;
logJSON(response);
});
}