diff --git a/.gitignore b/.gitignore
index 5fff1d9..815d867 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
pkg
+*.swp
+*.gem
diff --git a/Gemfile.lock b/Gemfile.lock
index 017fd23..270e641 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,23 +1,20 @@
PATH
remote: .
specs:
- dummy_dropbox (0.0.5)
- dropbox
+ dummy_dropbox_sdk (0.0.11)
+ dropbox-sdk (>= 1.1)
GEM
remote: http://rubygems.org/
specs:
- dropbox (1.3.0)
- json (>= 1.2.0)
- multipart-post (>= 1.1.0)
- oauth (>= 0.3.6)
- json (1.5.3)
- multipart-post (1.1.3)
- oauth (0.4.5)
+ dropbox-sdk (1.1)
+ json
+ json (1.6.1)
PLATFORMS
ruby
DEPENDENCIES
bundler (>= 1.0.0.rc.6)
- dummy_dropbox!
+ dropbox-sdk (>= 1.1)
+ dummy_dropbox_sdk!
diff --git a/README.rdoc b/README.rdoc
index 574233e..78121ed 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -4,27 +4,27 @@ http://farm5.static.flickr.com/4136/4925714505_3a3a0a6134_o.jpg
I can image a Dropbox session, just for testing.
-Very simple library for mocking the dropbox_ruby_gem[http://rubygems.org/gems/dropbox].
+Very simple library for mocking the dropbox-sdk gem
+[https://www.dropbox.com/developers/start/setup#ruby].
You can test your application without making real calls to Dropbox API using a *local* *folder* to fake a Dropbox account.
== Install
- $ [sudo] gem install dummy_dropbox
+ $ [sudo] gem install dummy_dropbox_sdk
== Usage
- require 'dummy_dropbox'
+ require 'dummy_dropbox_sdk'
# Optional:
# Point where your local folder structure is located.
# It will be used as if the real Dropbox structure was been reading.
DummyDropbox.root_path =
- session = Dropbox::Session.new('key', 'secret')
- assert_equal( File.read( "/file1.txt" ) , @session.download( '/file1.txt' ) )
+ session = DropboxSession.new('x','y')
See the *test* folder.
@@ -38,6 +38,10 @@ Please fork it and complete the holes as you need it, them send me your pull req
== Credits
-Author:: Fernando Guillen: http://fernandoguillen.info
-Copyright:: Copyright (c) 2010 Fernando Guillen
-License:: Released under the MIT license.
\ No newline at end of file
+This is an adapted version of the dummy_dropbox gem mocking another dropbox
+library [https://github.com/fguillen/DummyDropbox].
+
+Original Author:: Fernando Guillen: http://fernandoguillen.info
+Author:: Panter llc: http://www.panter.ch
+Copyright:: Copyright (c) 2011 Panter llc
+License:: Released under the MIT license.
diff --git a/dummy_dropbox.gemspec b/dummy_dropbox_sdk.gemspec
similarity index 51%
rename from dummy_dropbox.gemspec
rename to dummy_dropbox_sdk.gemspec
index c832463..11a5715 100644
--- a/dummy_dropbox.gemspec
+++ b/dummy_dropbox_sdk.gemspec
@@ -3,19 +3,19 @@ $:.push File.expand_path("../lib", __FILE__)
require "version"
Gem::Specification.new do |s|
- s.name = "dummy_dropbox"
+ s.name = "dummy_dropbox_sdk"
s.version = DummyDropbox::VERSION
- s.authors = ["Fernando Guillen"]
- s.email = ["fguillen.mail@gmail.com"]
- s.homepage = "https://github.com/fguillen/DummyDropbox"
- s.summary = "Dummy monkey patching for the dropbox ruby gem: 'dropbox'"
- s.description = "Dummy monkey patching for the dropbox ruby gem: 'dropbox'. You can test your Dropbox utility using a local folder to simulate your Dropbox folder."
+ s.authors = ["Panter llc"]
+ s.email = ["info@panter.ch"]
+ s.homepage = "https://github.com/panter/dummy_dropbox_sdk"
+ s.summary = "Dummy monkey patching for the dropbox-sdk ruby gem: 'dropbox-sdk'"
+ s.description = "Dummy monkey patching for the dropbox-sdk ruby gem: 'dropbox-sdk'. You can test your Dropbox utility using a local folder to simulate your Dropbox folder."
s.rubyforge_project = "DummyDropbox"
s.add_development_dependency "bundler", ">= 1.0.0.rc.6"
- s.add_dependency "dropbox"
+ s.add_dependency "dropbox-sdk", ">= 1.1"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
diff --git a/lib/dummy_dropbox.rb b/lib/dummy_dropbox.rb
deleted file mode 100644
index 72fbf07..0000000
--- a/lib/dummy_dropbox.rb
+++ /dev/null
@@ -1,151 +0,0 @@
-begin
- require 'dropbox'
-rescue LoadError
- require 'rubygems'
- require 'dropbox'
-end
-require 'ostruct'
-
-module DummyDropbox
- @@root_path = File.expand_path( "#{File.dirname(__FILE__)}/../test/fixtures/dropbox" )
-
- def self.root_path=(path)
- @@root_path = path
- end
-
- def self.root_path
- @@root_path
- end
-end
-
-module Dropbox
- class Session
- def initialize(oauth_key, oauth_secret, options={})
- @ssl = false
- @consumer = OpenStruct.new( :key => "dummy key consumer" )
- @request_token = "dummy request token"
- end
-
- def authorize_url(*args)
- return 'https://www.dropbox.com/0/oauth/authorize'
- end
-
- def authorize(options={})
- return true
- end
-
- def authorized?
- return true
- end
-
- def serialize
- return 'dummy serial'
- end
-
- def self.deserialize(data)
- return Dropbox::Session.new( 'dummy_key', 'dummy_secret' )
- end
-
- #################
- # API methods
- #################
-
- def download(path, options={})
- File.read( "#{Dropbox.files_root_path}/#{path}" )
- end
-
- def delete(path, options={})
- FileUtils.rm_rf( "#{Dropbox.files_root_path}/#{path}" )
-
- return true
- end
-
- def create_folder(path, options={})
- FileUtils.mkdir( "#{Dropbox.files_root_path}/#{path}" )
-
- return self.metadata( path )
- end
-
- # TODO: the original gem method allow a lot of types for 'local_path' parameter
- # this dummy version only allows a file_path
- def upload(local_file_path, remote_folder_path, options={})
- if(local_file_path.kind_of? StringIO)
- local_file = Tempfile.new("dummy_dropbox_#{Time.now.to_i}") do |f|
- f.write local_file_path.to_s
- end
- local_file_path = local_file.path
- FileUtils.cp( local_file_path, "#{Dropbox.files_root_path}/#{remote_folder_path}/#{options[:as]}" )
- outfile = "#{remote_folder_path}/#{options[:as]}"
- else
- FileUtils.cp( local_file_path, "#{Dropbox.files_root_path}/#{remote_folder_path}/" )
- outfile = "#{remote_folder_path}/#{File.basename(local_file_path)}"
- end
-
- return self.metadata( outfile )
- end
-
- def metadata(path, options={})
- response = <<-RESPONSE
- {
- "thumb_exists": false,
- "bytes": "#{File.size( "#{Dropbox.files_root_path}/#{path}" )}",
- "modified": "Tue, 04 Nov 2008 02:52:28 +0000",
- "path": "#{path}",
- "is_dir": #{File.directory?( "#{Dropbox.files_root_path}/#{path}" )},
- "size": "566.0KB",
- "root": "dropbox",
- "icon": "page_white_acrobat",
- "hash": "theHash"
- }
- RESPONSE
- return parse_metadata(JSON.parse(response).symbolize_keys_recursively).to_struct_recursively
- end
-
- def list(path, options={})
- result = []
-
- Dir["#{Dropbox.files_root_path}/#{path}/**"].each do |element_path|
- element_path.gsub!( "#{Dropbox.files_root_path}/", '' )
-
- element =
- OpenStruct.new(
- :icon => 'folder',
- :'directory?' => File.directory?( "#{Dropbox.files_root_path}/#{element_path}" ),
- :path => element_path,
- :thumb_exists => false,
- :modified => Time.parse( '2010-01-01 10:10:10' ),
- :revision => 1,
- :bytes => 0,
- :is_dir => File.directory?( "#{Dropbox.files_root_path}/#{element_path}" ),
- :size => '0 bytes'
- )
-
- result << element
- end
-
- return result
- end
-
- def account
- response = <<-RESPONSE
- {
- "country": "",
- "display_name": "John Q. User",
- "email": "john@user.com",
- "quota_info": {
- "shared": 37378890,
- "quota": 62277025792,
- "normal": 263758550
- },
- "uid": "174"
- }
- RESPONSE
-
- return JSON.parse(response).symbolize_keys_recursively.to_struct_recursively
- end
- end
-
- def self.files_root_path
- return DummyDropbox::root_path
- end
-end
\ No newline at end of file
diff --git a/lib/dummy_dropbox_sdk.rb b/lib/dummy_dropbox_sdk.rb
new file mode 100644
index 0000000..59921d8
--- /dev/null
+++ b/lib/dummy_dropbox_sdk.rb
@@ -0,0 +1,150 @@
+begin
+ require 'dropbox_sdk'
+rescue LoadError
+ require 'rubygems'
+ require 'dropbox_sdk'
+end
+require 'ostruct'
+
+module DummyDropbox
+ @@root_path = File.expand_path( "#{File.dirname(__FILE__)}/../test/fixtures/dropbox" )
+
+ def self.root_path=(path)
+ @@root_path = path
+ end
+
+ def self.root_path
+ @@root_path
+ end
+end
+
+class DropboxSession
+ def initialize(oauth_key, oauth_secret, options={})
+ @ssl = false
+ @consumer = OpenStruct.new( :key => "dummy key consumer" )
+ @request_token = "dummy request token"
+ end
+
+ def self.deserialize(data)
+ return DropboxSession.new( 'dummy_key', 'dummy_secret' )
+ end
+
+ def get_authorize_url(*args)
+ return 'https://www.dropbox.com/0/oauth/authorize'
+ end
+
+ def serialize
+ return 'dummy serial'.to_yaml
+ end
+
+ def authorized?
+ return true
+ end
+
+ def dummy?
+ return true
+ end
+
+end
+
+class DropboxClient
+
+ def initialize(session, root="app_folder", locale=nil)
+ @session = session
+ end
+
+ def file_create_folder(path, options={})
+ FileUtils.mkdir( "#{DummyDropbox::root_path}/#{path}" )
+ # intercepted result:
+ # {"modified"=>"Wed, 23 Nov 2011 10:24:37 +0000", "bytes"=>0, "size"=>"0
+ # bytes", "is_dir"=>true, "rev"=>"2f04dc6147", "icon"=>"folder",
+ # "root"=>"app_folder", "path"=>"/test_from_console", "thumb_exists"=>false,
+ # "revision"=>47}
+ return self.metadata( path )
+ end
+
+ def metadata(path, options={})
+ response = <<-RESPONSE
+ {
+ "thumb_exists": false,
+ "bytes": "#{File.size( "#{DummyDropbox::root_path}/#{path}" )}",
+ "modified": "Tue, 04 Nov 2008 02:52:28 +0000",
+ "path": "#{path}",
+ "is_dir": #{File.directory?( "#{DummyDropbox::root_path}/#{path}" )},
+ "size": "566.0KB",
+ "root": "dropbox",
+ "icon": "page_white_acrobat",
+ "hash": "theHash"
+ }
+ RESPONSE
+ return JSON.parse(response)
+ end
+
+ def put_file(to_path, file_obj, overwrite=false, parent_rev=nil)
+ File.join(DummyDropbox::root_path, to_path)
+ FileUtils.copy_file(file_obj.path, File.join(DummyDropbox::root_path, to_path))
+ return self.metadata(to_path)
+ end
+
+ # TODO these methods I don't used yet. They are commented out because they
+ # have to be checked against the api if the signature match
+
+ # def download(path, options={})
+ # File.read( "#{Dropbox.files_root_path}/#{path}" )
+ # end
+ #
+ # def delete(path, options={})
+ # FileUtils.rm_rf( "#{Dropbox.files_root_path}/#{path}" )
+ #
+ # return true
+ # end
+ #
+ # def upload(local_file_path, remote_folder_path, options={})
+ # end
+ #
+ #
+ # def list(path, options={})
+ # result = []
+ #
+ # Dir["#{Dropbox.files_root_path}/#{path}/**"].each do |element_path|
+ # element_path.gsub!( "#{Dropbox.files_root_path}/", '' )
+ #
+ # element =
+ # OpenStruct.new(
+ # :icon => 'folder',
+ # :'directory?' => File.directory?( "#{Dropbox.files_root_path}/#{element_path}" ),
+ # :path => element_path,
+ # :thumb_exists => false,
+ # :modified => Time.parse( '2010-01-01 10:10:10' ),
+ # :revision => 1,
+ # :bytes => 0,
+ # :is_dir => File.directory?( "#{Dropbox.files_root_path}/#{element_path}" ),
+ # :size => '0 bytes'
+ # )
+ #
+ # result << element
+ # end
+ #
+ # return result
+ # end
+ #
+ # def account
+ # response = <<-RESPONSE
+ # {
+ # "country": "",
+ # "display_name": "John Q. User",
+ # "email": "john@user.com",
+ # "quota_info": {
+ # "shared": 37378890,
+ # "quota": 62277025792,
+ # "normal": 263758550
+ # },
+ # "uid": "174"
+ # }
+ # RESPONSE
+ #
+ # return JSON.parse(response).symbolize_keys_recursively.to_struct_recursively
+ # end
+
+end
+
diff --git a/test/dummy_dropbox_sdk_test.rb b/test/dummy_dropbox_sdk_test.rb
new file mode 100644
index 0000000..44badef
--- /dev/null
+++ b/test/dummy_dropbox_sdk_test.rb
@@ -0,0 +1,74 @@
+require 'test/unit'
+require "#{File.dirname(__FILE__)}/../lib/dummy_dropbox_sdk.rb"
+
+class DummyDropboxSdkTest < Test::Unit::TestCase
+ def setup
+ @session = DropboxSession.new('key', 'secret')
+ @client = DropboxClient.new(@session)
+ end
+
+ def test_serialize
+ assert_equal("--- dummy serial\n", @session.serialize )
+ end
+
+ def test_get_authorize_url
+ assert_not_nil(@session.get_authorize_url)
+ end
+
+ def test_deserialize
+ assert_not_nil(DropboxSession.deserialize(nil))
+ end
+
+ def test_metadata
+ assert( !@client.metadata( '/file1.txt' )['is_dir'] )
+ assert( @client.metadata( '/folder1' )['is_dir'] )
+ end
+
+ def test_create_folder
+ FileUtils.rm_r( "#{DummyDropbox.root_path}/tmp_folder" ) if File.exists?( "#{DummyDropbox.root_path}/tmp_folder" )
+ metadata = @client.file_create_folder '/tmp_folder'
+ assert( File.directory?( "#{DummyDropbox.root_path}/tmp_folder" ) )
+ assert_equal(true, metadata["is_dir"])
+
+ FileUtils.rm_r( "#{DummyDropbox.root_path}/tmp_folder" )
+ end
+
+ def test_upload
+ FileUtils.rm_r( "#{DummyDropbox.root_path}/file.txt" ) if File.exists?( "#{DummyDropbox.root_path}/file.txt" )
+ file_fixture = File.new("#{File.dirname(__FILE__)}/fixtures/file.txt")
+ metadata = @client.put_file('file.txt', file_fixture)
+ assert_equal(
+ file_fixture.read,
+ File.read( "#{DummyDropbox.root_path}/file.txt" )
+ )
+ assert( !metadata['is_dir'] )
+ FileUtils.rm_r( "#{DummyDropbox.root_path}/file.txt" )
+ end
+
+ # TODO these methods I don't used yet. They are commented out because they
+ # have to be checked against the api if the signature match
+
+ # def test_download
+ # assert_equal( "File 1", @session.download( '/file1.txt' ) )
+ # end
+ #
+ # def test_list
+ # assert_equal(['/file1.txt', '/folder1'], @session.list('').map{ |e| e.path } )
+ # assert_equal(['folder1/file2.txt', 'folder1/file3.txt'], @session.list('folder1').map{ |e| e.path } )
+ # end
+ #
+ # def test_delete
+ # FileUtils.mkdir_p( "#{DummyDropbox.root_path}/tmp_folder" )
+ # 3.times { |i| FileUtils.touch( "#{DummyDropbox.root_path}/tmp_folder/#{i}.txt" ) }
+ #
+ # assert( File.exists?( "#{DummyDropbox.root_path}/tmp_folder" ) )
+ # assert( File.exists?( "#{DummyDropbox.root_path}/tmp_folder/0.txt" ) )
+ #
+ # metadata = @session.delete '/tmp_folder/0.txt'
+ # assert( !File.exists?( "#{DummyDropbox.root_path}/tmp_folder/0.txt" ) )
+ #
+ # metadata = @session.delete '/tmp_folder'
+ # assert( !File.exists?( "#{DummyDropbox.root_path}/tmp_folder" ) )
+ # end
+
+end
diff --git a/test/dummy_dropbox_test.rb b/test/dummy_dropbox_test.rb
deleted file mode 100644
index 99c879b..0000000
--- a/test/dummy_dropbox_test.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-require 'test/unit'
-require "#{File.dirname(__FILE__)}/../lib/dummy_dropbox.rb"
-
-class DummyDropboxTest < Test::Unit::TestCase
- def setup
- @session = Dropbox::Session.new('key', 'secret')
- end
-
- def test_session
- assert_equal( "#", @session.inspect )
- end
-
- def test_download
- assert_equal( "File 1", @session.download( '/file1.txt' ) )
- end
-
- def test_metadata
- assert( !@session.metadata( '/file1.txt' ).directory? )
- assert( @session.metadata( '/folder1' ).directory? )
- end
-
- def test_list
- assert_equal(['/file1.txt', '/folder1'], @session.list('').map{ |e| e.path } )
- assert_equal(['folder1/file2.txt', 'folder1/file3.txt'], @session.list('folder1').map{ |e| e.path } )
- end
-
- def test_delete
- FileUtils.mkdir_p( "#{DummyDropbox.root_path}/tmp_folder" )
- 3.times { |i| FileUtils.touch( "#{DummyDropbox.root_path}/tmp_folder/#{i}.txt" ) }
-
- assert( File.exists?( "#{DummyDropbox.root_path}/tmp_folder" ) )
- assert( File.exists?( "#{DummyDropbox.root_path}/tmp_folder/0.txt" ) )
-
- metadata = @session.delete '/tmp_folder/0.txt'
- assert( !File.exists?( "#{DummyDropbox.root_path}/tmp_folder/0.txt" ) )
-
- metadata = @session.delete '/tmp_folder'
- assert( !File.exists?( "#{DummyDropbox.root_path}/tmp_folder" ) )
- end
-
- def test_create_folder
- FileUtils.rm_r( "#{DummyDropbox.root_path}/tmp_folder" ) if File.exists?( "#{DummyDropbox.root_path}/tmp_folder" )
- metadata = @session.create_folder '/tmp_folder'
- assert( File.directory?( "#{DummyDropbox.root_path}/tmp_folder" ) )
- assert( metadata.directory? )
-
- FileUtils.rm_r( "#{DummyDropbox.root_path}/tmp_folder" )
- end
-
- def test_upload
- FileUtils.rm_r( "#{DummyDropbox.root_path}/file.txt" ) if File.exists?( "#{DummyDropbox.root_path}/file.txt" )
- metadata = @session.upload( "#{File.dirname(__FILE__)}/fixtures/file.txt", '/' )
- assert_equal(
- File.read( "#{File.dirname(__FILE__)}/fixtures/file.txt" ),
- File.read( "#{DummyDropbox.root_path}/file.txt" )
- )
- assert( !metadata.directory? )
- FileUtils.rm_r( "#{DummyDropbox.root_path}/file.txt" )
-
- metadata = @session.upload( StringIO.new("stuff"), '/', :as => "stringio.txt")
- assert( File.exists?( "#{DummyDropbox.root_path}/#{metadata.path}" ) )
- FileUtils.rm_r( "#{DummyDropbox.root_path}/stringio.txt" ) if File.exists?( "#{DummyDropbox.root_path}/stringio.txt" )
- end
-end
\ No newline at end of file