backblaze-b2
Advanced tools
Comparing version 0.9.1 to 0.9.2
@@ -0,1 +1,9 @@ | ||
### v0.9.2 (November 21, 2015) - The bucket list release | ||
Features | ||
- List buckets | ||
- Update bucket | ||
- Get upload url for bucket | ||
### v0.9.1 (November 21, 2015) - The moar tests release | ||
@@ -2,0 +10,0 @@ |
@@ -35,2 +35,41 @@ var utils = require('./../utils'); | ||
exports.list = function(b2) { | ||
var options = { | ||
url: getListUrl(b2), | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
accountId: b2.accountId | ||
}), | ||
headers: utils.getAuthHeaderObjectWithToken(b2) | ||
}; | ||
return request.sendRequest(options); | ||
}; | ||
exports.update = function(b2, bucketId, bucketType) { | ||
var options = { | ||
url: getUpdateUrl(b2), | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
accountId: b2.accountId, | ||
bucketId: bucketId, | ||
bucketType: bucketType | ||
}), | ||
headers: utils.getAuthHeaderObjectWithToken(b2) | ||
}; | ||
return request.sendRequest(options); | ||
}; | ||
exports.getUploadUrl = function(b2, bucketId) { | ||
var options = { | ||
url: getGetUploadUrl(b2), | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
bucketId: bucketId | ||
}), | ||
headers: utils.getAuthHeaderObjectWithToken(b2) | ||
}; | ||
return request.sendRequest(options); | ||
}; | ||
function getCreateUrl(b2) { | ||
@@ -41,7 +80,19 @@ return getApiUrl(b2) + '/b2_create_bucket'; | ||
function getDeleteUrl(b2) { | ||
return getApiUrl(b2) + '/b2_delete_bucket' | ||
return getApiUrl(b2) + '/b2_delete_bucket'; | ||
} | ||
function getListUrl(b2) { | ||
return getApiUrl(b2) + '/b2_list_buckets'; | ||
} | ||
function getUpdateUrl(b2) { | ||
return getApiUrl(b2) + '/b2_update_bucket'; | ||
} | ||
function getGetUploadUrl(b2) { | ||
return getApiUrl(b2) + '/b2_get_upload_url'; | ||
} | ||
function getApiUrl(b2) { | ||
return b2.apiUrl + '/b2api/v1'; | ||
} |
@@ -11,2 +11,4 @@ var actions = require('./actions'); | ||
B2.prototype.BUCKET_TYPES = actions.bucket.TYPES; | ||
B2.prototype.authorize = function() { | ||
@@ -24,4 +26,14 @@ return actions.auth.authorize(this, this.accountId, this.applicationKey); | ||
B2.prototype.listBuckets = function() { | ||
return actions.bucket.list(this); | ||
}; | ||
B2.prototype.updateBucket = function(bucketId, bucketType) { | ||
return actions.bucket.update(this, bucketId, bucketType); | ||
}; | ||
B2.prototype.getUploadUrl = function(bucketId) { | ||
return actions.bucket.getUploadUrl(this, bucketId); | ||
}; | ||
/* | ||
B2.prototype.list_buckets = function() {}; | ||
@@ -36,3 +48,2 @@ B2.prototype.delete_file_version = function() {}; | ||
B2.prototype.get_upload_url = function() {}; | ||
@@ -45,4 +56,2 @@ B2.prototype.hide_file = function() {}; | ||
B2.prototype.update_bucket = function() {}; | ||
B2.prototype.upload_file = function() {}; | ||
@@ -49,0 +58,0 @@ */ |
{ | ||
"name": "backblaze-b2", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"description": "Node.js Library for the Backblaze B2 Storage Service", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,3 @@ | ||
### Backblaze B2 Node.js Library | ||
### Backblaze B2 Node.js Library | ||
[![npm version](https://badge.fury.io/js/backblaze-b2.svg)](https://badge.fury.io/js/backblaze-b2) [![Build Status](https://travis-ci.org/yakovkhalinsky/backblaze-b2.svg?branch=master)](https://travis-ci.org/yakovkhalinsky/backblaze-b2) | ||
@@ -20,3 +21,2 @@ This library uses promises, so all actions on a `B2` instance return a promise in the following pattern | ||
var B2 = require('backblaze-b2'); | ||
@@ -38,1 +38,10 @@ | ||
b2.deleteBucket(bucketId); // returns promise | ||
// list buckets | ||
b2.listBuckets(); // returns promise | ||
// update bucket2 | ||
b2.updateBucket(bucketId, bucketType); // returns promise | ||
// get upload url | ||
b2.getUploadUrl(bucketId); // returns promise |
30
test.js
var B2 = require('./index.js'); | ||
var bucketTypes = require('./lib/actions').bucket.TYPES; | ||
@@ -16,12 +15,23 @@ var accountId = '1e73b07b61fe'; | ||
b2.createBucket('thngs-foo', bucketTypes.ALL_PRIVATE) | ||
.then(function(response) { | ||
console.log('created bucket with id', response.bucketId); | ||
//b2.updateBucket('918e27b37be0372b56110f1e', b2.BUCKET_TYPES.ALL_PUBLIC).then(function(response) { | ||
// console.log(response); | ||
//}); | ||
b2.deleteBucket(response.bucketId).then(function(response) { | ||
console.log('delete response', response); | ||
}, function(error) { | ||
console.log('delete error', error); | ||
}); | ||
}); | ||
b2.getUploadUrl('f15e07a37be0372b56110f1e').then(function(response) { | ||
console.log(response); | ||
}); | ||
//b2.listBuckets().then(function(bucketList) { | ||
// console.log(bucketList); | ||
//}); | ||
//b2.createBucket('thngs-foo', bucketTypes.ALL_PRIVATE) | ||
// .then(function(response) { | ||
// console.log('created bucket with id', response.bucketId); | ||
// | ||
// b2.deleteBucket(response.bucketId).then(function(response) { | ||
// console.log('delete response', response); | ||
// }, function(error) { | ||
// console.log('delete error', error); | ||
// }); | ||
// }); | ||
}); |
@@ -118,2 +118,152 @@ var expect = require('expect.js'); | ||
describe('list', function() { | ||
describe('with good response', function() { | ||
beforeEach(function(done) { | ||
response = { | ||
buckets:[ | ||
{ | ||
accountId: '1234abcd', | ||
bucketId: '1234abcd', | ||
bucketName: 'bucket-foo', | ||
bucketType: 'allPrivate' | ||
}, | ||
{ | ||
accountId: '1234abcd', | ||
bucketId: '2456efgh', | ||
bucketName: 'thngs-bar', | ||
bucketType: 'allPrivate' | ||
} | ||
] | ||
}; | ||
bucket.list(b2).then(function(response) { | ||
actualResponse = response; | ||
done(); | ||
}); | ||
}); | ||
it('should set correct options and resolve with good response', function() { | ||
expect(actualResponse).to.eql(response); | ||
expect(requestOptions).to.eql({ | ||
method: 'POST', | ||
url: 'https://foo/b2api/v1/b2_list_buckets', | ||
body: "{\"accountId\":\"98765\"}", | ||
headers: { Authorization: 'unicorns and rainbows' } | ||
}); | ||
}); | ||
}); | ||
describe('with error response', function() { | ||
beforeEach(function(done) { | ||
errorMessage = 'Something went wrong'; | ||
bucket.list(b2).then(null, function(error) { | ||
actualResponse = error; | ||
done(); | ||
}); | ||
}); | ||
it('Should respond with an error and reject promise', function() { | ||
expect(actualResponse).to.be(errorMessage); | ||
}); | ||
}); | ||
}); | ||
describe('update', function() { | ||
describe('with good response', function() { | ||
beforeEach(function(done) { | ||
response = { | ||
accountId: '1234abcd', | ||
bucketId: '1234abcd', | ||
bucketName: 'bucket-foo', | ||
bucketType: 'allPublic' | ||
}; | ||
bucket.update(b2, '1234abcd', bucket.TYPES.ALL_PUBLIC).then(function(response) { | ||
actualResponse = response; | ||
done(); | ||
}); | ||
}); | ||
it('should set correct options and resolve with good response', function() { | ||
expect(actualResponse).to.eql(response); | ||
expect(requestOptions).to.eql({ | ||
method: 'POST', | ||
url: 'https://foo/b2api/v1/b2_update_bucket', | ||
body: "{\"accountId\":\"98765\",\"bucketId\":\"1234abcd\",\"bucketType\":\"allPublic\"}", | ||
headers: { Authorization: 'unicorns and rainbows' } | ||
}); | ||
}); | ||
}); | ||
describe('with error response', function() { | ||
beforeEach(function(done) { | ||
errorMessage = 'Something went wrong'; | ||
bucket.update(b2, '1234abcd', bucket.TYPES.ALL_PUBLIC).then(null, function(error) { | ||
actualResponse = error; | ||
done(); | ||
}); | ||
}); | ||
it('Should respond with an error and reject promise', function() { | ||
expect(actualResponse).to.be(errorMessage); | ||
}); | ||
}); | ||
}); | ||
describe('getUploadUrl', function() { | ||
describe('with good response', function() { | ||
beforeEach(function(done) { | ||
response = { | ||
authorizationToken: 'this_is_your_auth_token', | ||
bucketId: '1234abcd', | ||
uploadUrl: 'https://foo-001.backblaze.com/b2api/v1/b2_upload_file/abcd1234/unicorns_and_rainbows' | ||
}; | ||
bucket.getUploadUrl(b2, '1234abcd').then(function(response) { | ||
actualResponse = response; | ||
done(); | ||
}); | ||
}); | ||
it('should set correct options and resolve with good response', function() { | ||
expect(actualResponse).to.eql(response); | ||
expect(requestOptions).to.eql({ | ||
method: 'POST', | ||
url: 'https://foo/b2api/v1/b2_get_upload_url', | ||
body: "{\"bucketId\":\"1234abcd\"}", | ||
headers: { Authorization: 'unicorns and rainbows' } | ||
}); | ||
}); | ||
}); | ||
describe('with error response', function() { | ||
beforeEach(function(done) { | ||
errorMessage = 'Something went wrong'; | ||
bucket.getUploadUrl(b2, '1234abcd').then(null, function(error) { | ||
actualResponse = error; | ||
done(); | ||
}); | ||
}); | ||
it('Should respond with an error and reject promise', function() { | ||
expect(actualResponse).to.be(errorMessage); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
29006
676
46
0