dummy_dropbox_sdk 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.bundle/config +2 -0
- data/.gitignore +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +20 -0
- data/README.rdoc +43 -0
- data/Rakefile +17 -0
- data/dummy_dropbox_sdk.gemspec +24 -0
- data/lib/dummy_dropbox_sdk.rb +150 -0
- data/lib/version.rb +3 -0
- data/test/dummy_dropbox_sdk_test.rb +74 -0
- data/test/fixtures/.DS_Store +0 -0
- data/test/fixtures/dropbox/file1.txt +1 -0
- data/test/fixtures/dropbox/folder1/file2.txt +1 -0
- data/test/fixtures/dropbox/folder1/file3.txt +1 -0
- data/test/fixtures/file.txt +1 -0
- metadata +120 -0
data/.bundle/config
ADDED
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.8.7@dummy_dropbox
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dummy_dropbox_sdk (0.0.11)
|
5
|
+
dropbox-sdk (>= 1.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
dropbox-sdk (1.1)
|
11
|
+
json
|
12
|
+
json (1.6.1)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
bundler (>= 1.0.0.rc.6)
|
19
|
+
dropbox-sdk (>= 1.1)
|
20
|
+
dummy_dropbox_sdk!
|
data/README.rdoc
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
= DummyDropbox
|
2
|
+
|
3
|
+
http://farm5.static.flickr.com/4136/4925714505_3a3a0a6134_o.jpg
|
4
|
+
|
5
|
+
<b>I can image a Dropbox session, just for testing.</b>
|
6
|
+
|
7
|
+
Very simple library for mocking the dropbox_ruby_gem[http://rubygems.org/gems/dropbox].
|
8
|
+
|
9
|
+
You can test your application without making real calls to Dropbox API using a *local* *folder* to fake a Dropbox account.
|
10
|
+
|
11
|
+
|
12
|
+
== Install
|
13
|
+
|
14
|
+
$ [sudo] gem install dummy_dropbox
|
15
|
+
|
16
|
+
|
17
|
+
== Usage
|
18
|
+
|
19
|
+
require 'dummy_dropbox'
|
20
|
+
|
21
|
+
# Optional:
|
22
|
+
# Point where your local folder structure is located.
|
23
|
+
# It will be used as if the real Dropbox structure was been reading.
|
24
|
+
DummyDropbox.root_path = <your_local_folder>
|
25
|
+
|
26
|
+
session = Dropbox::Session.new('key', 'secret')
|
27
|
+
assert_equal( File.read( "<your_local_folder>/file1.txt" ) , @session.download( '/file1.txt' ) )
|
28
|
+
|
29
|
+
See the *test* folder.
|
30
|
+
|
31
|
+
|
32
|
+
== TODO
|
33
|
+
|
34
|
+
The status of this dummy implementation is not very much completed, I just implemented enough for my proposes.
|
35
|
+
|
36
|
+
Please fork it and complete the holes as you need it, them send me your pull request.
|
37
|
+
|
38
|
+
|
39
|
+
== Credits
|
40
|
+
|
41
|
+
Author:: Fernando Guillen: http://fernandoguillen.info
|
42
|
+
Copyright:: Copyright (c) 2010 Fernando Guillen
|
43
|
+
License:: Released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'bundler'
|
6
|
+
|
7
|
+
include Rake::DSL
|
8
|
+
|
9
|
+
Bundler::GemHelper.install_tasks
|
10
|
+
|
11
|
+
task :default => :test
|
12
|
+
|
13
|
+
Rake::TestTask.new do |t|
|
14
|
+
t.libs << '.'
|
15
|
+
t.test_files = FileList['test/*_test.rb']
|
16
|
+
t.verbose = true
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "dummy_dropbox_sdk"
|
7
|
+
s.version = DummyDropbox::VERSION
|
8
|
+
s.authors = ["Panter llc"]
|
9
|
+
s.email = ["info@panter.ch"]
|
10
|
+
s.homepage = "https://github.com/panter/DummyDropbox"
|
11
|
+
s.summary = "Dummy monkey patching for the dropbox-sdk ruby gem: 'dropbox-sdk'"
|
12
|
+
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."
|
13
|
+
|
14
|
+
s.rubyforge_project = "DummyDropbox"
|
15
|
+
|
16
|
+
s.add_development_dependency "bundler", ">= 1.0.0.rc.6"
|
17
|
+
|
18
|
+
s.add_dependency "dropbox-sdk", ">= 1.1"
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
begin
|
2
|
+
require 'dropbox_sdk'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'dropbox_sdk'
|
6
|
+
end
|
7
|
+
require 'ostruct'
|
8
|
+
|
9
|
+
module DummyDropbox
|
10
|
+
@@root_path = File.expand_path( "#{File.dirname(__FILE__)}/../test/fixtures/dropbox" )
|
11
|
+
|
12
|
+
def self.root_path=(path)
|
13
|
+
@@root_path = path
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.root_path
|
17
|
+
@@root_path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class DropboxSession
|
22
|
+
def initialize(oauth_key, oauth_secret, options={})
|
23
|
+
@ssl = false
|
24
|
+
@consumer = OpenStruct.new( :key => "dummy key consumer" )
|
25
|
+
@request_token = "dummy request token"
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.deserialize(data)
|
29
|
+
return DropboxSession.new( 'dummy_key', 'dummy_secret' )
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_authorize_url(*args)
|
33
|
+
return 'https://www.dropbox.com/0/oauth/authorize'
|
34
|
+
end
|
35
|
+
|
36
|
+
def serialize
|
37
|
+
return 'dummy serial'.to_yaml
|
38
|
+
end
|
39
|
+
|
40
|
+
def authorized?
|
41
|
+
return true
|
42
|
+
end
|
43
|
+
|
44
|
+
def dummy?
|
45
|
+
return true
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
class DropboxClient
|
51
|
+
|
52
|
+
def initialize(session, root="app_folder", locale=nil)
|
53
|
+
@session = session
|
54
|
+
end
|
55
|
+
|
56
|
+
def file_create_folder(path, options={})
|
57
|
+
FileUtils.mkdir( "#{DummyDropbox::root_path}/#{path}" )
|
58
|
+
# intercepted result:
|
59
|
+
# {"modified"=>"Wed, 23 Nov 2011 10:24:37 +0000", "bytes"=>0, "size"=>"0
|
60
|
+
# bytes", "is_dir"=>true, "rev"=>"2f04dc6147", "icon"=>"folder",
|
61
|
+
# "root"=>"app_folder", "path"=>"/test_from_console", "thumb_exists"=>false,
|
62
|
+
# "revision"=>47}
|
63
|
+
return self.metadata( path )
|
64
|
+
end
|
65
|
+
|
66
|
+
def metadata(path, options={})
|
67
|
+
response = <<-RESPONSE
|
68
|
+
{
|
69
|
+
"thumb_exists": false,
|
70
|
+
"bytes": "#{File.size( "#{DummyDropbox::root_path}/#{path}" )}",
|
71
|
+
"modified": "Tue, 04 Nov 2008 02:52:28 +0000",
|
72
|
+
"path": "#{path}",
|
73
|
+
"is_dir": #{File.directory?( "#{DummyDropbox::root_path}/#{path}" )},
|
74
|
+
"size": "566.0KB",
|
75
|
+
"root": "dropbox",
|
76
|
+
"icon": "page_white_acrobat",
|
77
|
+
"hash": "theHash"
|
78
|
+
}
|
79
|
+
RESPONSE
|
80
|
+
return JSON.parse(response)
|
81
|
+
end
|
82
|
+
|
83
|
+
def put_file(to_path, file_obj, overwrite=false, parent_rev=nil)
|
84
|
+
File.join(DummyDropbox::root_path, to_path)
|
85
|
+
FileUtils.copy_file(file_obj.path, File.join(DummyDropbox::root_path, to_path))
|
86
|
+
return self.metadata(to_path)
|
87
|
+
end
|
88
|
+
|
89
|
+
# TODO these methods I don't used yet. They are commented out because they
|
90
|
+
# have to be checked against the api if the signature match
|
91
|
+
|
92
|
+
# def download(path, options={})
|
93
|
+
# File.read( "#{Dropbox.files_root_path}/#{path}" )
|
94
|
+
# end
|
95
|
+
#
|
96
|
+
# def delete(path, options={})
|
97
|
+
# FileUtils.rm_rf( "#{Dropbox.files_root_path}/#{path}" )
|
98
|
+
#
|
99
|
+
# return true
|
100
|
+
# end
|
101
|
+
#
|
102
|
+
# def upload(local_file_path, remote_folder_path, options={})
|
103
|
+
# end
|
104
|
+
#
|
105
|
+
#
|
106
|
+
# def list(path, options={})
|
107
|
+
# result = []
|
108
|
+
#
|
109
|
+
# Dir["#{Dropbox.files_root_path}/#{path}/**"].each do |element_path|
|
110
|
+
# element_path.gsub!( "#{Dropbox.files_root_path}/", '' )
|
111
|
+
#
|
112
|
+
# element =
|
113
|
+
# OpenStruct.new(
|
114
|
+
# :icon => 'folder',
|
115
|
+
# :'directory?' => File.directory?( "#{Dropbox.files_root_path}/#{element_path}" ),
|
116
|
+
# :path => element_path,
|
117
|
+
# :thumb_exists => false,
|
118
|
+
# :modified => Time.parse( '2010-01-01 10:10:10' ),
|
119
|
+
# :revision => 1,
|
120
|
+
# :bytes => 0,
|
121
|
+
# :is_dir => File.directory?( "#{Dropbox.files_root_path}/#{element_path}" ),
|
122
|
+
# :size => '0 bytes'
|
123
|
+
# )
|
124
|
+
#
|
125
|
+
# result << element
|
126
|
+
# end
|
127
|
+
#
|
128
|
+
# return result
|
129
|
+
# end
|
130
|
+
#
|
131
|
+
# def account
|
132
|
+
# response = <<-RESPONSE
|
133
|
+
# {
|
134
|
+
# "country": "",
|
135
|
+
# "display_name": "John Q. User",
|
136
|
+
# "email": "john@user.com",
|
137
|
+
# "quota_info": {
|
138
|
+
# "shared": 37378890,
|
139
|
+
# "quota": 62277025792,
|
140
|
+
# "normal": 263758550
|
141
|
+
# },
|
142
|
+
# "uid": "174"
|
143
|
+
# }
|
144
|
+
# RESPONSE
|
145
|
+
#
|
146
|
+
# return JSON.parse(response).symbolize_keys_recursively.to_struct_recursively
|
147
|
+
# end
|
148
|
+
|
149
|
+
end
|
150
|
+
|
data/lib/version.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require "#{File.dirname(__FILE__)}/../lib/dummy_dropbox_sdk.rb"
|
3
|
+
|
4
|
+
class DummyDropboxSdkTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@session = DropboxSession.new('key', 'secret')
|
7
|
+
@client = DropboxClient.new(@session)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_serialize
|
11
|
+
assert_equal("--- dummy serial\n", @session.serialize )
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_get_authorize_url
|
15
|
+
assert_not_nil(@session.get_authorize_url)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_deserialize
|
19
|
+
assert_not_nil(DropboxSession.deserialize(nil))
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_metadata
|
23
|
+
assert( !@client.metadata( '/file1.txt' )['is_dir'] )
|
24
|
+
assert( @client.metadata( '/folder1' )['is_dir'] )
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_create_folder
|
28
|
+
FileUtils.rm_r( "#{DummyDropbox.root_path}/tmp_folder" ) if File.exists?( "#{DummyDropbox.root_path}/tmp_folder" )
|
29
|
+
metadata = @client.file_create_folder '/tmp_folder'
|
30
|
+
assert( File.directory?( "#{DummyDropbox.root_path}/tmp_folder" ) )
|
31
|
+
assert_equal(true, metadata["is_dir"])
|
32
|
+
|
33
|
+
FileUtils.rm_r( "#{DummyDropbox.root_path}/tmp_folder" )
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_upload
|
37
|
+
FileUtils.rm_r( "#{DummyDropbox.root_path}/file.txt" ) if File.exists?( "#{DummyDropbox.root_path}/file.txt" )
|
38
|
+
file_fixture = File.new("#{File.dirname(__FILE__)}/fixtures/file.txt")
|
39
|
+
metadata = @client.put_file('file.txt', file_fixture)
|
40
|
+
assert_equal(
|
41
|
+
file_fixture.read,
|
42
|
+
File.read( "#{DummyDropbox.root_path}/file.txt" )
|
43
|
+
)
|
44
|
+
assert( !metadata['is_dir'] )
|
45
|
+
FileUtils.rm_r( "#{DummyDropbox.root_path}/file.txt" )
|
46
|
+
end
|
47
|
+
|
48
|
+
# TODO these methods I don't used yet. They are commented out because they
|
49
|
+
# have to be checked against the api if the signature match
|
50
|
+
|
51
|
+
# def test_download
|
52
|
+
# assert_equal( "File 1", @session.download( '/file1.txt' ) )
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# def test_list
|
56
|
+
# assert_equal(['/file1.txt', '/folder1'], @session.list('').map{ |e| e.path } )
|
57
|
+
# assert_equal(['folder1/file2.txt', 'folder1/file3.txt'], @session.list('folder1').map{ |e| e.path } )
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# def test_delete
|
61
|
+
# FileUtils.mkdir_p( "#{DummyDropbox.root_path}/tmp_folder" )
|
62
|
+
# 3.times { |i| FileUtils.touch( "#{DummyDropbox.root_path}/tmp_folder/#{i}.txt" ) }
|
63
|
+
#
|
64
|
+
# assert( File.exists?( "#{DummyDropbox.root_path}/tmp_folder" ) )
|
65
|
+
# assert( File.exists?( "#{DummyDropbox.root_path}/tmp_folder/0.txt" ) )
|
66
|
+
#
|
67
|
+
# metadata = @session.delete '/tmp_folder/0.txt'
|
68
|
+
# assert( !File.exists?( "#{DummyDropbox.root_path}/tmp_folder/0.txt" ) )
|
69
|
+
#
|
70
|
+
# metadata = @session.delete '/tmp_folder'
|
71
|
+
# assert( !File.exists?( "#{DummyDropbox.root_path}/tmp_folder" ) )
|
72
|
+
# end
|
73
|
+
|
74
|
+
end
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
File 1
|
@@ -0,0 +1 @@
|
|
1
|
+
File 2
|
@@ -0,0 +1 @@
|
|
1
|
+
File 3
|
@@ -0,0 +1 @@
|
|
1
|
+
file content
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dummy_dropbox_sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 11
|
10
|
+
version: 0.0.11
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Panter llc
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-11-23 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: bundler
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 15424057
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
- rc
|
35
|
+
- 6
|
36
|
+
version: 1.0.0.rc.6
|
37
|
+
type: :development
|
38
|
+
version_requirements: *id001
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: dropbox-sdk
|
41
|
+
prerelease: false
|
42
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
hash: 13
|
48
|
+
segments:
|
49
|
+
- 1
|
50
|
+
- 1
|
51
|
+
version: "1.1"
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
54
|
+
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."
|
55
|
+
email:
|
56
|
+
- info@panter.ch
|
57
|
+
executables: []
|
58
|
+
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files: []
|
62
|
+
|
63
|
+
files:
|
64
|
+
- .bundle/config
|
65
|
+
- .gitignore
|
66
|
+
- .rvmrc
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- README.rdoc
|
70
|
+
- Rakefile
|
71
|
+
- dummy_dropbox_sdk.gemspec
|
72
|
+
- lib/dummy_dropbox_sdk.rb
|
73
|
+
- lib/version.rb
|
74
|
+
- test/dummy_dropbox_sdk_test.rb
|
75
|
+
- test/fixtures/.DS_Store
|
76
|
+
- test/fixtures/dropbox/file1.txt
|
77
|
+
- test/fixtures/dropbox/folder1/file2.txt
|
78
|
+
- test/fixtures/dropbox/folder1/file3.txt
|
79
|
+
- test/fixtures/file.txt
|
80
|
+
has_rdoc: true
|
81
|
+
homepage: https://github.com/panter/DummyDropbox
|
82
|
+
licenses: []
|
83
|
+
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 3
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
requirements: []
|
108
|
+
|
109
|
+
rubyforge_project: DummyDropbox
|
110
|
+
rubygems_version: 1.3.7
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: "Dummy monkey patching for the dropbox-sdk ruby gem: 'dropbox-sdk'"
|
114
|
+
test_files:
|
115
|
+
- test/dummy_dropbox_sdk_test.rb
|
116
|
+
- test/fixtures/.DS_Store
|
117
|
+
- test/fixtures/dropbox/file1.txt
|
118
|
+
- test/fixtures/dropbox/folder1/file2.txt
|
119
|
+
- test/fixtures/dropbox/folder1/file3.txt
|
120
|
+
- test/fixtures/file.txt
|