New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nodejs-box

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodejs-box - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

84

lib/index.js

@@ -37,2 +37,3 @@ var VERSION = '0.0.1',

this.files = new Files(this.options);
this.sharedItems = new SharedItems(this.options);

@@ -100,3 +101,3 @@ }

// Retrieves a download link for the given file
Files.prototype.download = function(file, callback){
addMethod(Files.prototype, 'download', function(file, callback){
request

@@ -112,4 +113,19 @@ .get(this.options.base_url+'/'+this.resource+ '/' +file+ '/content')

});
};
});
// Retrieves a download link for the given file from a shared item
addMethod(Files.prototype, 'download', function(file, shareLink, callback){
var req = request.get(this.options.base_url+'/'+this.resource+ '/' +file+ '/content');
req.set('Authorization', this.options.auth);
req.set('BoxApi', 'shared_link='+shareLink);
req.redirects(0);
req.end(function(res){
if(res.error)
return callback('Error: '+res.error.message);
callback(null, res.headers.location);
});
});
Files.prototype.info = function(file, fields, callback){

@@ -181,3 +197,3 @@ if(typeof fields === 'function'){

Folders.prototype.items = function(folder, limit, offset, fields, callback){
addMethod(Folders.prototype, 'items', function(folder, limit, offset, fields, callback){
if(typeof fields === 'function'){

@@ -195,13 +211,37 @@ callback = fields;

request
.get(uri)
.set('Authorization', this.options.auth)
.end(function(res){
if(res.error)
return callback('Error: '+res.error.message);
var req = request.get(uri);
req.set('Authorization', this.options.auth);
req.end(function(res){
if(res.error)
return callback('Error: '+res.error.message);
callback(null, res.body);
});
};
callback(null, res.body);
});
});
// Get items in shared folder
addMethod(Folders.prototype, 'items', function(folder, limit, offset, shareLink, fields, callback){
if(typeof fields === 'function'){
callback = fields;
fields = null;
}
var uri = this.options.base_url+'/'+this.resource+'/'+folder+'/items';
if (fields) {
uri += '?fields=' + fields +'&offset=' + offset + '&limit='+ limit;
} else {
uri += '?offset=' + offset + '&limit='+ limit;
}
var req = request.get(uri);
req.set('Authorization', this.options.auth);
req.set('BoxApi', 'shared_link='+shareLink);
req.end(function(res){
if(res.error)
return callback('Error: '+res.error.message);
callback(null, res.body);
});
});
// Creates a new folder given the parent

@@ -243,1 +283,21 @@ Folders.prototype.create = function(name, parent, callback){

};
// Folders Resource
function SharedItems(options){
this.options = options;
this.resource = 'shared_items';
}
SharedItems.prototype.info = function (shareLink, callback) {
request
.get(this.options.base_url+'/'+this.resource)
.set('Authorization', this.options.auth)
.set('BoxApi', 'shared_link='+shareLink)
.end(function(res){
if(res.error)
return callback('Error: '+res.error.message);
callback(null, res.body);
});
};

2

package.json
{
"name": "nodejs-box",
"version": "0.0.5",
"version": "0.0.6",
"description": "Box API client for Node.JS",

@@ -5,0 +5,0 @@ "repository": {

@@ -20,37 +20,3 @@ # Box API Node.JS Client

```
Check out the [tests](../blob/master/test/index.js) for more usage examples.
## Folders
### box.folders.info(folder_id, callback)
Returns info given a folder ID
### box.folders.root(callback)
Returns info for the root folder (ID '0')
### box.folders.create(folder_name, parent_folder_id, callback)
Creates a new folder, given a name and the ID of the parent folder
### box.folders.delete(folder_id, recursive*, callback)
Deletes a folder, given a folder ID.
Optionally takes a second argument, 'recursive', that holds a boolean value, which,
if true, will delete the folder even if it is not empty.
## Files
### box.files.upload(path, folder_id)
Uploads a file given a path and a folder ID
### box.files.createMetadata(metadata, file_id)
Create metadata for a given file (ID)
Note: Your app/account has to be authorized for the Metadata API beta to use this.
## Test
Run `export access_token='YOUR_TOKEN_GOES_HERE' && npm test`
### UPDATED README COMING SOON
var Box = require('../lib/'),
test = require('prova'),
path = require('path'),
async = require('async');

@@ -10,36 +11,78 @@

var box = new Box({
access_token: process.env.token
access_token: 'wUvcSE54t2dPopGTtMudT2LqKIioSB89'
});
test('Module', function(assert){
assert.ok(box.options);
assert.ok(box.options.access_token);
assert.ok(box.files);
assert.ok(box.folders);
assert.end();
});
box.folders.items('2804097017', 1000, 0,'https://app.box.com/s/1lsz05uylsb8cg12ilkh', null, function (err, res) {
if (err) {
console.log(err);
}
test('Resource: Folders', function(t){
var files = res.entries || [];
t.test('Method: root',function(assert){
box.folders.info('2095638196',function(err, res){
res.item_collection.entries.forEach(function(o){
box.files.info(o.id, 'extension,name', function(err, res2){
if(res2.extension === 'txt'){
box.files.download(res2.id, function(err, res3){
var file = fs.createWriteStream('./out/'+res2.name);
var req = request.get(res3);
req.pipe(file);
var outputDir = './testData/';
})
}
})
})
assert.notOk(err);
assert.ok(res);
assert.end();
async.eachLimit(files, 4, function(file, cb) {
console.log('downloading: ' + file.name);
// get file url for download
box.files.download(file.id, 'https://app.box.com/s/1lsz05uylsb8cg12ilkh', function(err, res) {
if (err) {
cb(err);
}
// make request to download file to system
var req = request(res),
filePath = path.join(outputDir, file.name);
req.pipe(fs.createWriteStream(filePath));
req.on('err', function(err){
cb(err);
});
req.on('end', function(){
cb(null);
});
});
}, function(err) {
if (err) {
console.log(err);
} else {
console.log(files.length + ' file(s) downloaded');
}
});
});
});
// test('Module', function(assert){
// assert.ok(box.options);
// assert.ok(box.options.access_token);
// assert.ok(box.files);
// assert.ok(box.folders);
// assert.end();
// });
// test('Resource: Folders', function(t){
// t.test('Method: root',function(assert){
// box.folders.info('2095638196',function(err, res){
// res.item_collection.entries.forEach(function(o){
// box.files.info(o.id, 'extension,name', function(err, res2){
// if(res2.extension === 'txt'){
// box.files.download(res2.id, function(err, res3){
// var file = fs.createWriteStream('./out/'+res2.name);
// var req = request.get(res3);
// req.pipe(file);
// })
// }
// })
// })
// assert.notOk(err);
// assert.ok(res);
// assert.end();
// });
// });
// });
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc