Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function Box (options) {
this.folders = new Folders(this.options);
this.files = new Files(this.options);
this.sharedItems = new SharedItems(this.options);
this.collaborations = new Collaborations(this.options);
this.events = new Events(this.options);
this.search = new Search(this.options);
}
Expand Down Expand Up @@ -419,6 +420,126 @@ Folders.prototype.delete = function (folder, recursive, callback) {
});
};

// Get collaborations for folder
Folders.prototype.collaborations = function (folder, callback) {
var url = this.options.base_url+'/'+this.resource+'/'+folder+'/collaborations';
request.get(url)
.set('Authorization', this.options.auth)
.end(function (res) {
if (res.error) {
return callback('Error: '+res.error.message);
}

callback(null, res.body);
});
};

// collaborations Resource
function Collaborations (options) {
this.options = options;
this.resource = 'collaborations';
}

// Get collaboration
Collaborations.prototype.get = function (collaboration, callback) {
request
.get(this.options.base_url+'/'+this.resource+'/'+collaboration)
.set('Authorization', this.options.auth)
.end(function (res) {
if (res.error) {
return callback('Error: '+res.error.message);
}

callback(null, res.body);
});
};

// Creates a new collaboration for a single user (identified via id) to a folder
Collaborations.prototype.createId = function (folder, user, role, callback) {
request
.post(this.options.base_url+'/'+this.resource)
.set('Authorization', this.options.auth)
.send({
item: { id: folder, type: 'folder' },
accessible_by : { type: 'user', id: user },
role: role
})
.end(function (res) {
if (res.error) {
return callback('Error: '+res.error.message);
}

callback(null, res.body);
});
};

// Creates a new collaboration for a single user (identified via email) to a folder
Collaborations.prototype.createEmail = function (folder, user, role, callback) {
request
.post(this.options.base_url+'/'+this.resource)
.set('Authorization', this.options.auth)
.send({
item: { id: folder, type: 'folder' },
accessible_by : { type: 'user', login: user },
role: role
})
.end(function (res) {
if (res.error) {
return callback('Error: '+res.error.message);
}

callback(null, res.body);
});
};

// Sets role for a collaboration
Collaborations.prototype.setRole = function (collaboration, role, callback) {
request
.put(this.options.base_url+'/'+this.resource+'/'+collaboration)
.set('Authorization', this.options.auth)
.send({
role: role
})
.end(function (res) {
if (res.error) {
return callback('Error: '+res.error.message);
}

callback(null, res.body);
});
};

// Sets status for a collaboration
Collaborations.prototype.setStatus = function (collaboration, status, callback) {
request
.put(this.options.base_url+'/'+this.resource+'/'+collaboration)
.set('Authorization', this.options.auth)
.send({
status: status
})
.end(function (res) {
if (res.error) {
return callback('Error: '+res.error.message);
}

callback(null, res.body);
});
};

// Delete collaboration
Collaborations.prototype.delete = function (collaboration, callback) {
request
.del(this.options.base_url+'/'+this.resource+'/'+collaboration)
.set('Authorization', this.options.auth)
.end(function (res) {
if (res.error) {
return callback('Error: '+res.error.message);
}

callback(null, res.body);
});
};

// Shared Items Resource
function SharedItems (options) {
this.options = options;
Expand Down