Permalink
Browse files

[api test doc] Refactored node-cloudfiles to support multiple clients

  • Loading branch information...
1 parent c38bb57 commit cd976530db2ccaca28efaa3352f57a3970039589 @indexzero indexzero committed Dec 1, 2010
View
@@ -10,23 +10,14 @@ require.paths.unshift(__dirname);
var cloudfiles = exports;
-// Core
-cloudfiles.config = require('cloudfiles/config').config;
-cloudfiles.setAuth = require('cloudfiles/core').setAuth;
-
-// Containers
+// Resources
+cloudfiles.Config = require('cloudfiles/config').Config;
cloudfiles.Container = require('cloudfiles/container').Container;
-cloudfiles.createContainer = require('cloudfiles/core').createContainer;
-cloudfiles.getContainers = require('cloudfiles/core').getContainers;
-cloudfiles.getContainer = require('cloudfiles/core').getContainer;
-cloudfiles.destroyContainer = require('cloudfiles/core').destroyContainer;
-
-// Storage Object
cloudfiles.StorageObject = require('cloudfiles/storage-object').StorageObject;
-cloudfiles.getFiles = require('cloudfiles/core').getFiles;
-cloudfiles.getFile = require('cloudfiles/core').getFile;
-cloudfiles.addFile = require('cloudfiles/core').addFile;
-cloudfiles.destroyFile = require('cloudfiles/core').destroyFile;
+
+// Core methods
+cloudfiles.createClient = require('cloudfiles/core').createClient;
+cloudfiles.Cloudfiles = require('cloudfiles/core').Cloudfiles;
// Mime types
cloudfiles.mime = require('cloudfiles/mime').mime;
View
@@ -5,25 +5,48 @@
* MIT LICENSE
*
*/
-
-var Config = function () {
+var fs = require('fs'),
+ path = require('path');
+
+//
+// function createConfig (defaults)
+// Creates a new instance of the configuration
+// object based on default values
+//
+exports.createConfig = function (options) {
+ return new Config(options);
+};
+
+//
+// Config (defaults)
+// Constructor for the Config object
+//
+var Config = exports.Config = function (options) {
+ if (!options.auth) throw new Error ('options.auth is required to create Config');
+
+ this.auth = {
+ username: options.auth.username,
+ apiKey: options.auth.apiKey
+ };
+
+ if (options.cdn) {
+ this.cdn.ttl = options.cdn.ttl || this.cdn.ttl;
+ this.logRetention = options.cdn.logRetention || this.cdn.logRetention;
+ }
+
+ var cachePath = path.join(this.cache.path, this.auth.username);
+ this.cache.path = options.cache ? options.cache.cachePath || cachePath : cachePath;
};
Config.prototype = {
- // Remark: Put your Rackspace API Key here
- auth: {
- username: 'your-username',
- apiKey: 'your-api-key'
- },
-
cdn: {
ttl: 43200, // Default X-TTL time-out to 12 hours,
logRetention: true // Default X-LOG-RETENTION to true
+ },
+ cache: {
+ path: path.join(__dirname, '..', '..', '.cache')
}
};
-exports.config = new (Config);
-
-
@@ -12,35 +12,35 @@ var cloudfiles = require('cloudfiles'),
sys = require('sys'),
utils = require('./utils');
-var Container = function (details) {
+var Container = exports.Container = function (client, details) {
if (!details) {
throw new Error("Container must be constructed with at least basic details.")
}
this.files = [];
+ this.client = client;
this._setProperties(details);
};
Container.prototype = {
- // Remark: Not fully implemented
addFile: function (file, local, callback) {
- cloudfiles.addFile(this.name, file, local, callback);
+ this.client.addFile(this.name, file, local, callback);
},
destory: function (callback) {
- cloudfiles.destoryContainer(this.name, callback);
+ this.client.destoryContainer(this.name, callback);
},
getFiles: function (callback) {
var self = this;
- cloudfiles.getFiles(this.name, function (err, files) {
+ this.client.getFiles(this.name, function (err, files) {
self.files = files;
callback(null, files);
});
},
removeFile: function (file, callback) {
- cloudfiles.destroyFile(this.name, file, callback);
+ this.client.destroyFile(this.name, file, callback);
},
// Remark: Not fully implemented
@@ -61,6 +61,4 @@ Container.prototype = {
this.count = details.count || 0;
this.bytes = details.bytes || 0;
}
-};
-
-exports.Container = Container;
+};
Oops, something went wrong.

0 comments on commit cd97653

Please sign in to comment.