Helper for the BigPlans Connector modules
kriskowal/q
library
See more at [ https://github.com/kriskowal/q ]
Wrapper around the mikeal/request
See more at [ https://github.com/mikeal/request ]
Used to create promises
var hook1 = helper.promise(function(done) {
// ...
done();
});
var hook2 = helper.promise(function(done) {
//...
done();
});
hook1.then(hook2).done(function() {
//...
});
Used to apply query string params for the URI
applyParams('http://host.tld/user/%{userId}/account', { userId: 1 });
// => 'http://host.tld/user/1/account'
Translator object
methods: ruleFor(name, ruleFunc)
, to(name, object)
translator.ruleFor('goal', function(ticket) {
return {
title: ticket.title,
description: ticket.body
};
});
translator.to('goal', ticket);
//=> { title: <ticket.title>, description: <ticket.body> };
JSEND decorator object
methods: toJsend(obj || err)
, toJsendError(err || String)
var result = { name: 'goalName' };
decorator.toJsend(result);
//=> { status: 'success', data: { name: 'goalName' }, message: '' }
var err = 'No response provided';
decorator.toJsendError(err);
//=> { status: 'error', data: {}, message: 'No response provided' }
decorator.toJsend(err);
//=> { status: 'fail', data: {}, message: 'No response provided' }
var err = new Error('No response provided');
decorator.toJsend(err);
//=> { status: 'error', data: {}, message: 'No response provided' }
Captures provided object and transforms it to JSEND
Wrapper around the decorator.toJsend
Is a shortcut for callback( decorator.toJsend( { id: 1 } ) )
var respondWith = respondTo(callback);
respondWith({ id: 1 });
//=> callback(decorator.toJsend({ id: 1 ))