box-view-api
Version:
Box View API, node.js client library
53 lines (38 loc) • 1.59 kB
JavaScript
// Core node module dependencies
//
// 3rd party library dependencies
//
var _ = require('underscore');
// Internal dependencies
//
var BoxViewError = require('./error');
var ErrorTypes = BoxViewError.errors; // aliasing for brevity
var BoxViewAPI = require('./boxView');
var SessionAPI = module.exports = BoxViewAPI.extend({
constructor: function SessionAPI() {
BoxViewAPI.apply(this, arguments);
_.bindAll(this, 'create');
},
// create(uuid, [options,] callback)
create: function(id) {
// Validate params
if (arguments.length < 2 || arguments.length > 3) {
throw new BoxViewError(ErrorTypes.INVALID_USE, 'Incorrect number of arguments passed to ' + this.constructor.name + '.create(): ' + arguments.length);
}
var cb = arguments[arguments.length - 1];
var options = (arguments.length === 3) ? arguments[1] : {};
if (typeof id !== 'string' || id.length <= 0) {
throw new BoxViewError(ErrorTypes.INVALID_TYPE, this.constructor.name+'.create() was not passed a non-blank string document id: '+(typeof id));
}
if (typeof options !== 'object') {
throw new BoxViewError(ErrorTypes.INVALID_TYPE, this.constructor.name + '.create() was not passed a valid options object: ' + (typeof options));
}
if (typeof cb !== 'function') {
throw new BoxViewError(ErrorTypes.INVALID_TYPE, this.constructor.name + '.create() was not passed a valid callback function: ' + (typeof cb));
}
options.document_id = id;
return this.post(SessionAPI.resource, {json: options}, cb);
}
}, {
resource: 'sessions'
});