dummy_dropbox_sdk 0.0.13 → 0.0.14

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/.rvmrc CHANGED
@@ -1 +1,3 @@
1
- rvm use 1.8.7@dummy_dropbox
1
+ rvm use 1.8.7@dummy_dropbox --create
2
+ echo rvm_auto_reload_flag=1 >> ~/.rvmrc
3
+ echo rvm_auto_reload_flag=2 >> ~/.rvmrc
@@ -1,15 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dummy_dropbox_sdk (0.0.11)
4
+ dummy_dropbox_sdk (0.0.13)
5
5
  dropbox-sdk (>= 1.1)
6
+ mime-types
6
7
 
7
8
  GEM
8
9
  remote: http://rubygems.org/
9
10
  specs:
10
- dropbox-sdk (1.1)
11
+ dropbox-sdk (1.3)
11
12
  json
12
- json (1.6.1)
13
+ json (1.7.3)
14
+ mime-types (1.19)
13
15
 
14
16
  PLATFORMS
15
17
  ruby
@@ -18,3 +20,4 @@ DEPENDENCIES
18
20
  bundler (>= 1.0.0.rc.6)
19
21
  dropbox-sdk (>= 1.1)
20
22
  dummy_dropbox_sdk!
23
+ mime-types
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.add_development_dependency "bundler", ">= 1.0.0.rc.6"
17
17
 
18
18
  s.add_dependency "dropbox-sdk", ">= 1.1"
19
+ s.add_dependency "mime-types"
19
20
 
20
21
  s.files = `git ls-files`.split("\n")
21
22
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -5,14 +5,30 @@ rescue LoadError
5
5
  require 'dropbox_sdk'
6
6
  end
7
7
  require 'ostruct'
8
+ require 'mime/types'
9
+
10
+ GIGA_SIZE = 1073741824.0
11
+ MEGA_SIZE = 1048576.0
12
+ KILO_SIZE = 1024.0
13
+
14
+ # Return the file size with a readable style.
15
+ def readable_file_size(size, precision)
16
+ case
17
+ when size == 1 : "1 Byte"
18
+ when size < KILO_SIZE : "%d Bytes" % size
19
+ when size < MEGA_SIZE : "%.#{precision}f KB" % (size / KILO_SIZE)
20
+ when size < GIGA_SIZE : "%.#{precision}f MB" % (size / MEGA_SIZE)
21
+ else "%.#{precision}f GB" % (size / GIGA_SIZE)
22
+ end
23
+ end
8
24
 
9
25
  module DummyDropbox
10
26
  @@root_path = File.expand_path( "./test/fixtures/dropbox" )
11
-
27
+
12
28
  def self.root_path=(path)
13
29
  @@root_path = path
14
30
  end
15
-
31
+
16
32
  def self.root_path
17
33
  @@root_path
18
34
  end
@@ -28,7 +44,7 @@ class DropboxSession
28
44
  def self.deserialize(data)
29
45
  return DropboxSession.new( 'dummy_key', 'dummy_secret' )
30
46
  end
31
-
47
+
32
48
  def get_authorize_url(*args)
33
49
  return 'https://www.dropbox.com/0/oauth/authorize'
34
50
  end
@@ -36,7 +52,7 @@ class DropboxSession
36
52
  def serialize
37
53
  return 'dummy serial'.to_yaml
38
54
  end
39
-
55
+
40
56
  def authorized?
41
57
  return true
42
58
  end
@@ -44,7 +60,7 @@ class DropboxSession
44
60
  def dummy?
45
61
  return true
46
62
  end
47
-
63
+
48
64
  end
49
65
 
50
66
  class DropboxClient
@@ -54,35 +70,61 @@ class DropboxClient
54
70
  end
55
71
 
56
72
  def file_create_folder(path, options={})
57
- FileUtils.mkdir( "#{DummyDropbox::root_path}/#{path}" )
73
+ file_path = File.join(DummyDropbox::root_path, path)
74
+ raise DropboxError.new("Folder exists!") if File.exists?(file_path)
75
+ FileUtils.mkdir(file_path)
58
76
  # intercepted result:
59
77
  # {"modified"=>"Wed, 23 Nov 2011 10:24:37 +0000", "bytes"=>0, "size"=>"0
60
78
  # bytes", "is_dir"=>true, "rev"=>"2f04dc6147", "icon"=>"folder",
61
79
  # "root"=>"app_folder", "path"=>"/test_from_console", "thumb_exists"=>false,
62
80
  # "revision"=>47}
63
- return self.metadata( path )
81
+ return self.metadata(path)
64
82
  end
65
83
 
66
84
  def metadata(path, options={})
67
- response = <<-RESPONSE
85
+ dummy_path = File.join(DummyDropbox::root_path, path)
86
+ raise DropboxError.new("File not found") unless File.exists?(dummy_path)
87
+
88
+ list_hash_files = []
89
+ if File.directory?(dummy_path)
90
+ Dir.entries(dummy_path).each do |file_name|
91
+ file_path = File.join(dummy_path, file_name)
92
+ unless File.directory?(file_path)
93
+ list_hash_files << {"size" => readable_file_size(File.size(file_path), 2),
94
+ "bytes" => File.size(file_path),
95
+ "is_dir" => false,
96
+ "modified" => File.mtime(file_path),
97
+ "mime_type" => MIME::Types.type_for(file_path)[0].content_type,
98
+ "path" => File.join(path, file_name)}
99
+ end
100
+ end
101
+
102
+ end
103
+
104
+ response =
68
105
  {
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"
106
+ "thumb_exists" => false,
107
+ "bytes" => File.size(dummy_path),
108
+ "modified" => "Tue, 04 Nov 2008 02:52:28 +0000",
109
+ "path" => path,
110
+ "is_dir" => File.directory?( "#{DummyDropbox::root_path}/#{path}" ),
111
+ "size" => readable_file_size(File.size(dummy_path), 2),
112
+ "root" => "dropbox",
113
+ "icon" => "page_white_acrobat",
114
+ "hash" => "theHash",
115
+ "contents" => list_hash_files
78
116
  }
79
- RESPONSE
80
- return JSON.parse(response)
117
+
118
+ return response
81
119
  end
82
120
 
83
121
  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))
122
+ file_path = File.join(DummyDropbox::root_path, to_path)
123
+ # FileUtils.copy_file(file_obj.path, File.join(DummyDropbox::root_path, to_path))
124
+ File.open(file_path, "w") do |f|
125
+ f.write(file_obj)
126
+ end
127
+
86
128
  return self.metadata(to_path)
87
129
  end
88
130
 
@@ -92,7 +134,24 @@ class DropboxClient
92
134
  'email' => 'dummy_dropbox@example.com'
93
135
  }
94
136
  end
95
-
137
+
138
+ def get_file(path)
139
+ dummy_file_path = File.join(DummyDropbox::root_path, path)
140
+ raise DropboxError.new("File not found") unless File.exists?(dummy_file_path)
141
+
142
+ File.read(dummy_file_path)
143
+ end
144
+
145
+ def file_delete(path)
146
+ dummy_file_path = File.join(DummyDropbox::root_path, path)
147
+ raise DropboxError.new("File not found") unless File.exists?(dummy_file_path)
148
+
149
+ metadata = self.metadata(path)
150
+ FileUtils.rm_rf(dummy_file_path)
151
+
152
+ return metadata
153
+ end
154
+
96
155
  # TODO these methods I don't used yet. They are commented out because they
97
156
  # have to be checked against the api if the signature match
98
157
 
@@ -102,21 +161,21 @@ class DropboxClient
102
161
  #
103
162
  # def delete(path, options={})
104
163
  # FileUtils.rm_rf( "#{Dropbox.files_root_path}/#{path}" )
105
- #
164
+ #
106
165
  # return true
107
166
  # end
108
- #
167
+ #
109
168
  # def upload(local_file_path, remote_folder_path, options={})
110
169
  # end
111
- #
112
- #
170
+ #
171
+ #
113
172
  # def list(path, options={})
114
173
  # result = []
115
- #
174
+ #
116
175
  # Dir["#{Dropbox.files_root_path}/#{path}/**"].each do |element_path|
117
176
  # element_path.gsub!( "#{Dropbox.files_root_path}/", '' )
118
- #
119
- # element =
177
+ #
178
+ # element =
120
179
  # OpenStruct.new(
121
180
  # :icon => 'folder',
122
181
  # :'directory?' => File.directory?( "#{Dropbox.files_root_path}/#{element_path}" ),
@@ -128,13 +187,13 @@ class DropboxClient
128
187
  # :is_dir => File.directory?( "#{Dropbox.files_root_path}/#{element_path}" ),
129
188
  # :size => '0 bytes'
130
189
  # )
131
- #
190
+ #
132
191
  # result << element
133
192
  # end
134
- #
193
+ #
135
194
  # return result
136
195
  # end
137
- #
196
+ #
138
197
  # def account
139
198
  # response = <<-RESPONSE
140
199
  # {
@@ -149,9 +208,8 @@ class DropboxClient
149
208
  # "uid": "174"
150
209
  # }
151
210
  # RESPONSE
152
- #
211
+ #
153
212
  # return JSON.parse(response).symbolize_keys_recursively.to_struct_recursively
154
213
  # end
155
-
156
- end
157
214
 
215
+ end
@@ -1,3 +1,3 @@
1
1
  module DummyDropbox
2
- VERSION = '0.0.13'
2
+ VERSION = '0.0.14'
3
3
  end
@@ -6,7 +6,7 @@ class DummyDropboxSdkTest < Test::Unit::TestCase
6
6
  @session = DropboxSession.new('key', 'secret')
7
7
  @client = DropboxClient.new(@session)
8
8
  end
9
-
9
+
10
10
  def test_serialize
11
11
  assert_equal("--- dummy serial\n", @session.serialize )
12
12
  end
@@ -29,29 +29,32 @@ class DummyDropboxSdkTest < Test::Unit::TestCase
29
29
  metadata = @client.file_create_folder '/tmp_folder'
30
30
  assert( File.directory?( "#{DummyDropbox.root_path}/tmp_folder" ) )
31
31
  assert_equal(true, metadata["is_dir"])
32
-
32
+
33
33
  FileUtils.rm_r( "#{DummyDropbox.root_path}/tmp_folder" )
34
34
  end
35
35
 
36
36
  def test_upload
37
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")
38
+ File.open("test/file.txt", "w"){|f| f.write("file content")}
39
+ DummyDropbox.root_path = "test/"
40
+
41
+ file_fixture = File.new("#{File.dirname(__FILE__)}/file.txt")
39
42
  metadata = @client.put_file('file.txt', file_fixture)
40
- assert_equal(
41
- file_fixture.read,
43
+ assert_equal(
44
+ File.read("#{File.dirname(__FILE__)}/file.txt"),
42
45
  File.read( "#{DummyDropbox.root_path}/file.txt" )
43
46
  )
44
- assert( !metadata['is_dir'] )
47
+ assert(!metadata["is_dir"])
45
48
  FileUtils.rm_r( "#{DummyDropbox.root_path}/file.txt" )
46
49
  end
47
-
50
+
48
51
  # TODO these methods I don't used yet. They are commented out because they
49
52
  # have to be checked against the api if the signature match
50
-
53
+
51
54
  # def test_download
52
55
  # assert_equal( "File 1", @session.download( '/file1.txt' ) )
53
56
  # end
54
- #
57
+ #
55
58
  # def test_list
56
59
  # assert_equal(['/file1.txt', '/folder1'], @session.list('').map{ |e| e.path } )
57
60
  # assert_equal(['folder1/file2.txt', 'folder1/file3.txt'], @session.list('folder1').map{ |e| e.path } )
@@ -61,14 +64,15 @@ class DummyDropboxSdkTest < Test::Unit::TestCase
61
64
  # FileUtils.mkdir_p( "#{DummyDropbox.root_path}/tmp_folder" )
62
65
  # 3.times { |i| FileUtils.touch( "#{DummyDropbox.root_path}/tmp_folder/#{i}.txt" ) }
63
66
  #
64
- # assert( File.exists?( "#{DummyDropbox.root_path}/tmp_folder" ) )
67
+ # assert( File.exists?( "#{DummyDropbox.root_path}/tmp_folder" ) )
65
68
  # assert( File.exists?( "#{DummyDropbox.root_path}/tmp_folder/0.txt" ) )
66
- #
69
+ #
67
70
  # metadata = @session.delete '/tmp_folder/0.txt'
68
71
  # assert( !File.exists?( "#{DummyDropbox.root_path}/tmp_folder/0.txt" ) )
69
- #
72
+ #
70
73
  # metadata = @session.delete '/tmp_folder'
71
74
  # assert( !File.exists?( "#{DummyDropbox.root_path}/tmp_folder" ) )
72
75
  # end
73
-
76
+
74
77
  end
78
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dummy_dropbox_sdk
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 13
10
- version: 0.0.13
9
+ - 14
10
+ version: 0.0.14
11
11
  platform: ruby
12
12
  authors:
13
13
  - Panter llc
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-13 00:00:00 +01:00
18
+ date: 2012-06-24 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -51,6 +51,20 @@ dependencies:
51
51
  version: "1.1"
52
52
  type: :runtime
53
53
  version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: mime-types
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ type: :runtime
67
+ version_requirements: *id003
54
68
  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
69
  email:
56
70
  - gems@panter.ch
@@ -76,7 +90,6 @@ files:
76
90
  - test/fixtures/dropbox/file1.txt
77
91
  - test/fixtures/dropbox/folder1/file2.txt
78
92
  - test/fixtures/dropbox/folder1/file3.txt
79
- - test/fixtures/file.txt
80
93
  has_rdoc: true
81
94
  homepage: https://github.com/panter/dummy_dropbox_sdk
82
95
  licenses: []
@@ -117,4 +130,3 @@ test_files:
117
130
  - test/fixtures/dropbox/file1.txt
118
131
  - test/fixtures/dropbox/folder1/file2.txt
119
132
  - test/fixtures/dropbox/folder1/file3.txt
120
- - test/fixtures/file.txt
@@ -1 +0,0 @@
1
- file content