From ad41d47b717c7b048a37f41ddd1e61f21b235d72 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Tue, 2 Jul 2013 08:57:53 -0700 Subject: [PATCH] Refactor the code to use StorageService as the facade --- example/app.js | 8 ++--- example/upload.js | 13 +++---- lib/factory.js | 6 ++-- lib/index.js | 81 ++++++++++++++++++++++++++++++++++++++++++ lib/storage-handler.js | 40 +++++++++------------ package.json | 2 +- 6 files changed, 112 insertions(+), 38 deletions(-) create mode 100644 lib/index.js diff --git a/example/app.js b/example/app.js index 34d9b9e..e011ea6 100644 --- a/example/app.js +++ b/example/app.js @@ -1,7 +1,7 @@ -var storage = require('../'); +var StorageService = require('../'); var path = require('path'); -var rs = storage({ +var rs = StorageService({ provider: 'rackspace', username: 'strongloop', apiKey: 'your-rackspace-api-key' @@ -39,7 +39,7 @@ rs.getContainers(function (err, containers) { */ -var s3 = storage({ +var s3 = StorageService({ provider: 'amazon', key: 'your-amazon-key', keyId: 'your-amazon-key-id' @@ -60,7 +60,7 @@ s3.getContainers(function (err, containers) { }); }); -var fs = storage({ +var fs = StorageService({ provider: 'filesystem', root: path.join(__dirname, 'storage') }); diff --git a/example/upload.js b/example/upload.js index 1ce0a30..affb304 100644 --- a/example/upload.js +++ b/example/upload.js @@ -1,4 +1,4 @@ -var Uploader = require('../lib/storage-handler.js'); +var StorageService = require('../'); var express = require('express'); var app = express(); @@ -13,7 +13,7 @@ app.configure(function () { app.use(app.router); }); -var handler = new Uploader({provider: 'filesystem', root: '/tmp/storage'}); +var handler = new StorageService({provider: 'filesystem', root: '/tmp/storage'}); app.get('/', function (req, res, next) { res.setHeader('Content-Type', 'text/html'); @@ -30,7 +30,7 @@ app.get('/', function (req, res, next) { }); app.post('/upload/:container', function (req, res, next) { - handler.processUpload(req, res, function (err, result) { + handler.upload(req, res, function (err, result) { if (!err) { res.setHeader('Content-Type', 'application/json'); res.send(200, result); @@ -41,7 +41,7 @@ app.post('/upload/:container', function (req, res, next) { }); app.get('/download', function (req, res, next) { - handler.client.getContainers(function (err, containers) { + handler.getContainers(function (err, containers) { var html = "

Containers