Skip to content
Open
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
23 changes: 13 additions & 10 deletions lib/cloudfiles/storage-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,19 @@ var StorageObject = exports.StorageObject = function (client, details) {
};

StorageObject.prototype = {
// Remark: Not fully implemented

addMetadata: function (metadata, callback) {
var newMetadata = clone(this.metadata);
Object.keys(metadata).forEach(function (key) {
newMetadata[key] = metadata[key];
});

var self = this;
var options = {
client: this.client,
uri: this.fullPath,
method: 'POST',
headers: this._createHeaders(newMetadata)
headers: this._createHeaders(metadata)
};

common.rackspace(options, callback, function (body, res) {
this.metadata = newMetadata;
self.metadata = metadata;
callback(null, true);
});
},
Expand All @@ -59,13 +57,18 @@ StorageObject.prototype = {
this.client.destroyFile(this.containerName, this.name, callback);
},

// Remark: Not fully implemented
getMetadata: function (callback) {
common.rackspace('HEAD', this.fullPath, function (body, res) {
var options = {
client: this.client,
uri: this.fullPath,
method: 'HEAD',
};

common.rackspace(options, callback, function (body, res) {
var metadata = {};
Object.keys(res.headers).forEach(function (header) {
var match;
if (match = header.match(/x-object-meta-(\w+)/i)) {
if (match = header.match(/x-object-meta-(.*)/i)) {
metadata[match[1]] = res.headers[header];
}
});
Expand Down
14 changes: 8 additions & 6 deletions test/storage-object-metadata-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var testData = {},
client = helpers.createClient(),
sampleData = fs.readFileSync(path.join(__dirname, '..', 'test', 'fixtures', 'fillerama.txt')).toString();

vows.describe('node-cloudfiles/storage-object').addBatch({
vows.describe('node-cloudfiles/storage-object').addBatch(helpers.requireAuth(client)).addBatch({
"The node-cloudfiles client": {
"an instance of a Container object": {
"the addFile() method": {
Expand Down Expand Up @@ -49,14 +49,16 @@ vows.describe('node-cloudfiles/storage-object').addBatch({
}
}
}
})/*.addBatch({
}).addBatch({
"The node-cloudfiles client": {
"the addMetadata() method": {
topic: function () {
testData.file.addMetadata({ "ninja": "true" }, this.callback);
testData.metadata = { "ninja-metadata": "true" };
testData.file.addMetadata(testData.metadata, this.callback);
},
"should response with true": function (err, added) {
assert.isTrue(added);
assert.deepEqual(testData.file.metadata, testData.metadata);
}
}
}
Expand All @@ -66,12 +68,12 @@ vows.describe('node-cloudfiles/storage-object').addBatch({
topic: function () {
testData.file.getMetadata(this.callback);
},
"should response with true": function (err, added) {
assert.isTrue(added);
"should return the metadata as an object": function (err, metadata) {
assert.deepEqual(metadata, testData.metadata);
}
}
}
})*/.addBatch({
}).addBatch({
"The node-cloudfiles client": {
"the destroyFile() method": {
"for a file that exists": {
Expand Down