svb-book-transfers
Version:
Helper API to issue wire transfers
79 lines (69 loc) • 1.82 kB
JavaScript
//
// svb-ach
// index.js
//
// For full documentation: http://docs.svbplatform.com/authentication/
// Email apisupport@svb.com for help!
//
const _genericGet = function(client, type, id, callback) {
let url = ['/v1', type, id];
if (!id) {
url.pop();
}
client.get(url.join('/'), '', (err, body) => {
if (err) {
return callback(err);
}
if (body && body.data) {
callback(null, body.data);
}
});
};
const _genericPatch = function(client, type, id, data, callback) {
client.patch(['/v1', type, id].join('/'), data, (err, body) => {
if (err) {
return callback(err);
}
if (body && body.data) {
callback(null, body.data);
}
});
};
const _genericPost = function(client, type, data, callback) {
client.post(['/v1', type].join('/'), data, (err, body) => {
if (err) {
return callback(err);
}
if (body && body.data) {
callback(null, body.data);
}
});
};
function SVBBookTransfers(client) {
if (!client) {
throw Error('SVB Book Transfers helper requires an SVB Client object');
}
this.client = client;
}
SVBBookTransfers.prototype = {
create: function(bookData, callback) {
_genericPost(this.client, 'book', bookData, callback);
},
get: function(bookID, callback) {
_genericGet(this.client, 'book', bookID, callback);
},
updateStatus: function(bookID, bookStatus, callback) {
if (typeof bookStatus === 'object') {
if (bookStatus.status) {
bookStatus = bookStatus.status;
} else {
throw Error('send a book transfer status string or { status: status } parameter');
}
}
_genericPatch(this.client, 'book', bookID, { status: bookStatus }, callback);
},
all: function(callback) {
this.get('', callback);
}
};
module.exports = SVBBookTransfers;