box-view-api
Version:
Box View API, node.js client library
59 lines (51 loc) • 1.72 kB
JavaScript
// Core node module dependencies
//
var inspect = require('util').inspect;
// 3rd party library dependencies
//
var inheritance = require('soak');
// Internal dependencies
//
var BoxViewError = require('./error');
var ErrorTypes = BoxViewError.errors; // aliasing for brevity
// Use the base rest API.
//
var API = require('./rest');
// Extend and export the API
//
// Takes a BoxView API Token in its constructor,
// and exposes wrapper methods to the generic API methods which automatically pass in the
// API token.
//
var BoxViewAPI = module.exports = inheritance.inherit(API, {
constructor: function BoxViewAPI(apiToken) {
// Validate the constructor arguments
if (arguments.length !== 1) {
throw new BoxViewError(ErrorTypes.INVALID_USE, 'Incorrect number of arguments passed to '+this.constructor.name+' constructor: '+arguments.length);
}
if (typeof apiToken !== 'string') {
throw new BoxViewError(ErrorTypes.INVALID_TYPE, 'Supplied API Token is not a string: '+(typeof apiToken)+' ['+inspect(apiToken)+']');
}
if (apiToken.length <= 0) {
throw new BoxViewError(ErrorTypes.INVALID_API_TOKEN, 'Supplied API Token "'+apiToken+'" is too short');
}
this.uriString = API.uriString;
API.constructor.call(this, apiToken);
this.get = function() {
return API.get.apply(this, arguments);
};
this.post = function() {
return API.post.apply(this, arguments);
};
this.put = function () {
return API.put.apply(this, arguments);
};
this.del = function() {
return API.del.apply(this, arguments);
};
}
}, {
extend: function (instance, statics) {
return inheritance.inherit(this, instance, statics);
}
});