Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: privatize makeReq #199

Merged
merged 1 commit into from
Sep 9, 2014
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions lib/storage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Bucket.prototype.list = function(query, callback) {
callback = query;
query = {};
}
this.makeReq('GET', 'o', query, true, function(err, resp) {
this.makeReq_('GET', 'o', query, true, function(err, resp) {
if (err) {
callback(err);
return;
Expand All @@ -159,7 +159,7 @@ Bucket.prototype.list = function(query, callback) {
*/
Bucket.prototype.stat = function(name, callback) {
var path = util.format('o/{name}', { name: name });
this.makeReq('GET', path, null, true, callback);
this.makeReq_('GET', path, null, true, callback);
};

/**
Expand Down Expand Up @@ -196,7 +196,7 @@ Bucket.prototype.copy = function(name, metadata, callback) {
});
delete metadata.name;
delete metadata.bucket;
this.makeReq('POST', path, null, metadata, callback);
this.makeReq_('POST', path, null, metadata, callback);
};

/**
Expand All @@ -210,7 +210,7 @@ Bucket.prototype.copy = function(name, metadata, callback) {
*/
Bucket.prototype.remove = function(name, callback) {
var path = util.format('o/{name}', { name: name });
this.makeReq('DELETE', path, null, true, callback);
this.makeReq_('DELETE', path, null, true, callback);
};

/**
Expand Down Expand Up @@ -375,7 +375,7 @@ Bucket.prototype.write = function(name, options, callback) {

if (typeof data === 'undefined') {
// metadata only write
this.makeReq('PATCH', 'o/' + name, null, metadata, callback);
this.makeReq_('PATCH', 'o/' + name, null, metadata, callback);
return;
}

Expand Down Expand Up @@ -442,13 +442,15 @@ Bucket.prototype.getWritableStream_ = function(name, metadata, callback) {
* Make a new request object from the provided arguments and wrap the callback
* to intercept non-successful responses.
*
* @private
*
* @param {string} method - Action.
* @param {string} path - Request path.
* @param {*} query - Request query object.
* @param {*} body - Request body contents.
* @param {function} callback - The callback function.
*/
Bucket.prototype.makeReq = function(method, path, query, body, callback) {
Bucket.prototype.makeReq_ = function(method, path, query, body, callback) {
var reqOpts = {
method: method,
qs: query,
Expand Down
16 changes: 8 additions & 8 deletions test/storage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Bucket', function() {

it('should list without a query', function(done) {
var bucket = createBucket();
bucket.makeReq = function(method, path, q, body) {
bucket.makeReq_ = function(method, path, q, body) {
assert.strictEqual(method, 'GET');
assert.strictEqual(path, 'o');
assert.deepEqual(q, {});
Expand All @@ -50,7 +50,7 @@ describe('Bucket', function() {

it('should list with a query', function(done) {
var bucket = createBucket();
bucket.makeReq = function(method, path, q, body) {
bucket.makeReq_ = function(method, path, q, body) {
assert.strictEqual(method, 'GET');
assert.strictEqual(path, 'o');
assert.deepEqual(q, { maxResults: 5, pageToken: 'token' });
Expand All @@ -62,7 +62,7 @@ describe('Bucket', function() {

it('should return nextQuery if more results', function() {
var bucket = createBucket();
bucket.makeReq = function(method, path, q, body, callback) {
bucket.makeReq_ = function(method, path, q, body, callback) {
callback(null, { nextPageToken: 'next-page-token', items: [] });
};
bucket.list({ maxResults: 5}, function(err, results, nextQuery) {
Expand All @@ -73,7 +73,7 @@ describe('Bucket', function() {

it('should return no nextQuery if no more results', function() {
var bucket = createBucket();
bucket.makeReq = function(method, path, q, body, callback) {
bucket.makeReq_ = function(method, path, q, body, callback) {
callback(null, { items: [] });
};
bucket.list({ maxResults: 5}, function(err, results, nextQuery) {
Expand All @@ -83,7 +83,7 @@ describe('Bucket', function() {

it('should stat a file', function(done) {
var bucket = createBucket();
bucket.makeReq = function(method, path, q, body) {
bucket.makeReq_ = function(method, path, q, body) {
assert.strictEqual(method, 'GET');
assert.strictEqual(path, 'o/file-name');
assert.strictEqual(q, null);
Expand All @@ -95,7 +95,7 @@ describe('Bucket', function() {

it('should copy a file', function(done) {
var bucket = createBucket();
bucket.makeReq = function(method, path, q, body) {
bucket.makeReq_ = function(method, path, q, body) {
assert.strictEqual(method, 'POST');
assert.strictEqual(path, 'o/file-name/copyTo/b/new-bucket/o/new-name');
assert.strictEqual(q, null);
Expand All @@ -108,7 +108,7 @@ describe('Bucket', function() {

it('should use the same bucket if nothing else is provided', function(done) {
var bucket = createBucket();
bucket.makeReq = function(method, path, q, body) {
bucket.makeReq_ = function(method, path, q, body) {
assert.strictEqual(method, 'POST');
assert.strictEqual(path, 'o/file-name/copyTo/b/bucket-name/o/new-name');
assert.strictEqual(q, null);
Expand All @@ -121,7 +121,7 @@ describe('Bucket', function() {

it('should remove a file', function(done) {
var bucket = createBucket();
bucket.makeReq = function(method, path, q, body) {
bucket.makeReq_ = function(method, path, q, body) {
assert.strictEqual(method, 'DELETE');
assert.strictEqual(path, 'o/file-name');
assert.strictEqual(q, null);
Expand Down