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
26 changes: 24 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ addMethod(Folders.prototype, 'items', function (folder, limit, offset, fields, c
}
var uri = this.options.base_url+'/'+this.resource+'/'+folder+'/items';

if (fields) {
if (fields) {
uri += '?fields=' + fields +'&offset=' + offset + '&limit='+ limit;
} else {
uri += '?offset=' + offset + '&limit='+ limit;
Expand All @@ -255,7 +255,7 @@ addMethod(Folders.prototype, 'items', function (folder, limit, offset, shareLink
}
var uri = this.options.base_url+'/'+this.resource+'/'+folder+'/items';

if (fields) {
if (fields) {
uri += '?fields=' + fields +'&offset=' + offset + '&limit='+ limit;
} else {
uri += '?offset=' + offset + '&limit='+ limit;
Expand Down Expand Up @@ -291,6 +291,28 @@ Folders.prototype.create = function (name, parent, callback) {
});
};

// upsert a folder
Folders.prototype.upsert = function (name, parent, callback) {
request
.post(this.options.base_url+'/'+this.resource)
.set('Authorization', this.options.auth)
.send({
name: name,
parent : { id: parent }
})
.end(function (res) {
if (res.status == 409) {
var existingFolder = res.body.context_info.conflicts.filter( function(conflict) { return ((conflict.type == 'folder') && (conflict.name == name)) })[0];
return callback(null, existingFolder);
}
else if (res.error) {
return callback('Error: '+res.error.message);
}

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

// Deletes a folder. Recursive arguement must be included in order to delete folders that have items inside of them
Folders.prototype.delete = function (folder, recursive, callback) {
if (typeof recursive === 'function') {
Expand Down