dummy_dropbox 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ Manifest
2
+ README.md
3
+ Rakefile
4
+ lib/dummy_dropbox.rb
5
+ test/dummy_dropbox_test.rb
6
+ test/fixtures/dropbox/file1.txt
7
+ test/fixtures/dropbox/folder1/file2.txt
8
+ test/fixtures/dropbox/folder1/file3.txt
@@ -0,0 +1,41 @@
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
+ So you can test your application without making real calls to Dropbox API.
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
+ DropboxDummy.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
+
37
+ == Credits
38
+
39
+ Author:: Fernando Guillen: http://fernandoguillen.info
40
+ Copyright:: Copyright (c) 2010 Fernando Guillen
41
+ License:: Released under the MIT license.
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('dummy_dropbox', '0.0.1') do |p|
6
+ p.description = "Dummy monkey patching for the dropbox ruby gem: http://rubygems.org/gems/dropbox"
7
+ p.url = "http://github.com/fguillen/DummyDropbox"
8
+ p.author = "Fernando Guillen"
9
+ p.email = "fguillen.mail@gmail.com"
10
+ p.ignore_pattern = []
11
+ p.development_dependencies = []
12
+ p.runtime_dependencies = ['dropbox']
13
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{dummy_dropbox}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Fernando Guillen"]
9
+ s.date = %q{2010-08-25}
10
+ s.description = %q{Dummy monkey patching for the dropbox ruby gem: http://rubygems.org/gems/dropbox}
11
+ s.email = %q{fguillen.mail@gmail.com}
12
+ s.extra_rdoc_files = ["README.md", "lib/dummy_dropbox.rb"]
13
+ s.files = ["Manifest", "README.md", "Rakefile", "lib/dummy_dropbox.rb", "test/dummy_dropbox_test.rb", "test/fixtures/dropbox/file1.txt", "test/fixtures/dropbox/folder1/file2.txt", "test/fixtures/dropbox/folder1/file3.txt", "dummy_dropbox.gemspec"]
14
+ s.homepage = %q{http://github.com/fguillen/DummyDropbox}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Dummy_dropbox", "--main", "README.md"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{dummy_dropbox}
18
+ s.rubygems_version = %q{1.3.7}
19
+ s.summary = %q{Dummy monkey patching for the dropbox ruby gem: http://rubygems.org/gems/dropbox}
20
+ s.test_files = ["test/dummy_dropbox_test.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<dropbox>, [">= 0"])
28
+ else
29
+ s.add_dependency(%q<dropbox>, [">= 0"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<dropbox>, [">= 0"])
33
+ end
34
+ end
@@ -0,0 +1,111 @@
1
+ class DummyDropbox
2
+ @@root_path = File.expand_path( "#{File.dirname(__FILE__)}/../test/fixtures/dropbox" )
3
+
4
+ def self.root_path=(path)
5
+ @@root_path = path
6
+ end
7
+
8
+ def self.root_path
9
+ @@root_path
10
+ end
11
+ end
12
+
13
+ module Dropbox
14
+ class Session
15
+ def initialize(oauth_key, oauth_secret, options={})
16
+ @ssl = false
17
+ @consumer = OpenStruct.new( :key => "dummy key consumer" )
18
+ @request_token = "dummy request token"
19
+ end
20
+
21
+ def authorize_url(*args)
22
+ return 'dummy url'
23
+ end
24
+
25
+ def authorize(options={})
26
+ return true
27
+ end
28
+
29
+ def authorized?
30
+ return true
31
+ end
32
+
33
+ def serialize
34
+ return 'dummy serial'
35
+ end
36
+
37
+ def self.deserialize(data)
38
+ return Dropbox::Session.new( 'dummy_key', 'dummy_secret' )
39
+ end
40
+
41
+ #################
42
+ # API methods
43
+ #################
44
+
45
+ def download(path, options={})
46
+ File.read( "#{Dropbox.files_root_path}/#{path}" )
47
+ end
48
+
49
+ def metadata(path, options={})
50
+ response = <<-RESPONSE
51
+ {
52
+ "thumb_exists": false,
53
+ "bytes": "#{File.size( "#{Dropbox.files_root_path}/#{path}" )}",
54
+ "modified": "Tue, 04 Nov 2008 02:52:28 +0000",
55
+ "path": "#{path}",
56
+ "is_dir": #{File.directory?( "#{Dropbox.files_root_path}/#{path}" )},
57
+ "size": "566.0KB",
58
+ "root": "dropbox",
59
+ "icon": "page_white_acrobat"
60
+ }
61
+ RESPONSE
62
+ return parse_metadata(JSON.parse(response).symbolize_keys_recursively).to_struct_recursively
63
+ end
64
+
65
+ def list(path, options={})
66
+ result = []
67
+
68
+ Dir["#{Dropbox.files_root_path}/#{path}/**"].each do |element_path|
69
+ element_path.gsub!( "#{Dropbox.files_root_path}/", '' )
70
+
71
+ element =
72
+ OpenStruct.new(
73
+ :icon => 'folder',
74
+ :'directory?' => File.directory?( "#{Dropbox.files_root_path}/#{element_path}" ),
75
+ :path => element_path,
76
+ :thumb_exists => false,
77
+ :modified => Time.parse( '2010-01-01 10:10:10' ),
78
+ :revision => 1,
79
+ :bytes => 0,
80
+ :is_dir => File.directory?( "#{Dropbox.files_root_path}/#{element_path}" ),
81
+ :size => '0 bytes'
82
+ )
83
+
84
+ result << element
85
+ end
86
+
87
+ return result
88
+ end
89
+
90
+ def account
91
+ response = <<-RESPONSE
92
+ {
93
+ "country": "",
94
+ "display_name": "John Q. User",
95
+ "quota_info": {
96
+ "shared": 37378890,
97
+ "quota": 62277025792,
98
+ "normal": 263758550
99
+ },
100
+ "uid": "174"
101
+ }
102
+ RESPONSE
103
+
104
+ return JSON.parse(response).symbolize_keys_recursively.to_struct_recursively
105
+ end
106
+ end
107
+
108
+ def self.files_root_path
109
+ return DummyDropbox::root_path
110
+ end
111
+ end
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'ostruct'
4
+ require 'dropbox'
5
+ require "#{File.dirname(__FILE__)}/../lib/dummy_dropbox.rb"
6
+
7
+ class DummyDropboxTest < Test::Unit::TestCase
8
+ def setup
9
+ @session = Dropbox::Session.new('key', 'secret')
10
+ end
11
+
12
+ def test_session
13
+ assert_equal( "#<Dropbox::Session dummy key consumer (authorized)>", @session.inspect )
14
+ end
15
+
16
+ def test_download
17
+ assert_equal( "File 1", @session.download( '/file1.txt' ) )
18
+ end
19
+
20
+ def test_metadata
21
+ assert( !@session.metadata( '/file1.txt' ).directory? )
22
+ assert( @session.metadata( '/folder1' ).directory? )
23
+ end
24
+
25
+ def test_list
26
+ assert_equal(['/file1.txt', '/folder1'], @session.list('').map{ |e| e.path } )
27
+ assert_equal(['folder1/file2.txt', 'folder1/file3.txt'], @session.list('folder1').map{ |e| e.path } )
28
+ end
29
+ end
@@ -0,0 +1 @@
1
+ File 1
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dummy_dropbox
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Fernando Guillen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-25 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: dropbox
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: "Dummy monkey patching for the dropbox ruby gem: http://rubygems.org/gems/dropbox"
36
+ email: fguillen.mail@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.md
43
+ - lib/dummy_dropbox.rb
44
+ files:
45
+ - Manifest
46
+ - README.md
47
+ - Rakefile
48
+ - lib/dummy_dropbox.rb
49
+ - test/dummy_dropbox_test.rb
50
+ - test/fixtures/dropbox/file1.txt
51
+ - test/fixtures/dropbox/folder1/file2.txt
52
+ - test/fixtures/dropbox/folder1/file3.txt
53
+ - dummy_dropbox.gemspec
54
+ has_rdoc: true
55
+ homepage: http://github.com/fguillen/DummyDropbox
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --line-numbers
61
+ - --inline-source
62
+ - --title
63
+ - Dummy_dropbox
64
+ - --main
65
+ - README.md
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 11
83
+ segments:
84
+ - 1
85
+ - 2
86
+ version: "1.2"
87
+ requirements: []
88
+
89
+ rubyforge_project: dummy_dropbox
90
+ rubygems_version: 1.3.7
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: "Dummy monkey patching for the dropbox ruby gem: http://rubygems.org/gems/dropbox"
94
+ test_files:
95
+ - test/dummy_dropbox_test.rb