dropbox 0.0.10 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,148 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Dropbox::Session do
4
+ describe ".new" do
5
+ it "should create a new OAuth::Consumer" do
6
+ key = 'test_key'
7
+ secret = 'test_secret'
8
+ options_hash = [ 'request_token', 'authorize', 'access_token' ].inject({}) { |hsh, cur| hsh["#{cur}_path".to_sym] = "/#{Dropbox::VERSION}/oauth/#{cur}" ; hsh }
9
+ options_hash[:site] = Dropbox::HOST
10
+
11
+ consumer_mock = mock('OAuth::Consumer')
12
+ consumer_mock.stub!(:get_request_token)
13
+ OAuth::Consumer.should_receive(:new).once.with(key, secret, options_hash).and_return(consumer_mock)
14
+
15
+ Dropbox::Session.new(key, secret)
16
+ end
17
+
18
+ it "should use the SSL host if :ssl => true is given" do
19
+ key = 'test_key'
20
+ secret = 'test_secret'
21
+ options_hash = [ 'request_token', 'authorize', 'access_token' ].inject({}) { |hsh, cur| hsh["#{cur}_path".to_sym] = "/#{Dropbox::VERSION}/oauth/#{cur}" ; hsh }
22
+ options_hash[:site] = Dropbox::SSL_HOST
23
+
24
+ consumer_mock = mock('OAuth::Consumer')
25
+ consumer_mock.stub!(:get_request_token)
26
+ OAuth::Consumer.should_receive(:new).once.with(key, secret, options_hash).and_return(consumer_mock)
27
+
28
+ Dropbox::Session.new(key, secret, :ssl => true)
29
+ end
30
+
31
+ it "should get the request token" do
32
+ consumer_mock = mock('OAuth::Consumer')
33
+ consumer_mock.should_receive(:get_request_token).once
34
+ OAuth::Consumer.stub!(:new).and_return(consumer_mock)
35
+
36
+ Dropbox::Session.new('foo', 'bar')
37
+ end
38
+ end
39
+
40
+ describe "#authorize_url" do
41
+ before :each do
42
+ consumer_mock = mock("OAuth::Consumer")
43
+ @token_mock = mock("OAuth::RequestToken")
44
+ consumer_mock.stub!(:get_request_token).and_return(@token_mock)
45
+ OAuth::Consumer.stub!(:new).and_return(consumer_mock)
46
+ @session = Dropbox::Session.new('foo', 'bar')
47
+ end
48
+
49
+ it "should raise an error if the session is already authorized" do
50
+ @session.stub!(:authorized?).and_return(true)
51
+
52
+ lambda { @session.authorize_url }.should raise_error(Dropbox::AlreadyAuthorizedError)
53
+ end
54
+
55
+ it "should call authorize_url on the request token" do
56
+ @token_mock.should_receive(:authorize_url).once
57
+ @session.authorize_url
58
+ end
59
+
60
+ it "should pass all parameters to the request token" do
61
+ @token_mock.should_receive(:authorize_url).once.with(:a, 'b', :c => 123)
62
+ @session.authorize_url(:a, 'b', :c => 123)
63
+ end
64
+ end
65
+
66
+ describe "#authorize" do
67
+ before :each do
68
+ consumer_mock = mock("OAuth::Consumer")
69
+ @token_mock = mock("OAuth::RequestToken")
70
+ consumer_mock.stub!(:get_request_token).and_return(@token_mock)
71
+ OAuth::Consumer.stub!(:new).and_return(consumer_mock)
72
+ @session = Dropbox::Session.new('foo', 'bar')
73
+ end
74
+
75
+ it "should call get_access_token on the request_token and pass the given options" do
76
+ options = { :foo => 'bar' }
77
+ @token_mock.should_receive(:get_access_token).once.with(options)
78
+ @session.authorize(options)
79
+ end
80
+
81
+ it "should make authorized? return true if an access token is returned" do
82
+ @token_mock.stub!(:get_access_token).and_return(Object.new)
83
+ @session.authorize({ 'foo' => 'bar' })
84
+ @session.should be_authorized
85
+ end
86
+
87
+ it "should make authorized? return false if no access token is returned" do
88
+ @token_mock.stub!(:get_access_token).and_return(nil)
89
+ @session.authorize({ 'foo' => 'bar' })
90
+ @session.should_not be_authorized
91
+ end
92
+
93
+ it "should return true if authorized" do
94
+ @token_mock.stub!(:get_access_token).and_return(Object.new)
95
+ @session.authorize({ 'foo' => 'bar' }).should be_true
96
+ end
97
+
98
+ it "should return false if unauthorized" do
99
+ @token_mock.stub!(:get_access_token).and_return(nil)
100
+ @session.authorize({ 'foo' => 'bar' }).should be_false
101
+ end
102
+ end
103
+
104
+ describe "#authorized?" do
105
+ #TODO this method remains opaque for purposes of testing
106
+ end
107
+
108
+ describe "#serialize" do
109
+ before :each do
110
+ @consumer_mock = mock("OAuth::Consumer")
111
+ @token_mock = mock("OAuth::RequestToken")
112
+ @consumer_mock.stub!(:get_request_token).and_return(@token_mock)
113
+ OAuth::Consumer.stub!(:new).and_return(@consumer_mock)
114
+ @session = Dropbox::Session.new('foo', 'bar')
115
+ end
116
+
117
+ it "should return the consumer key and secret and the request token and secret in YAML form if unauthorized" do
118
+ @consumer_mock.stub!(:key).and_return("consumer key")
119
+ @consumer_mock.stub!(:secret).and_return("consumer secret")
120
+ @token_mock.stub!(:token).and_return("request token")
121
+ @token_mock.stub!(:secret).and_return("request token secret")
122
+
123
+ @session.serialize.should eql([ "consumer key", "consumer secret", false, "request token", "request token secret" ].to_yaml)
124
+ end
125
+
126
+ it "should return the consumer key and secret and the access token and secret in YAML form if authorized" do
127
+ pending "access token is opaque"
128
+ end
129
+ end
130
+
131
+ describe ".deserialize" do
132
+ it "should raise an error if an improper YAML is provided" do
133
+ lambda { Dropbox::Session.deserialize([ 1, 2, 3].to_yaml) }.should raise_error(ArgumentError)
134
+ end
135
+
136
+ it "should return a properly initialized unauthorized instance" do
137
+ mock_session = mock('Dropbox::Session')
138
+ Dropbox::Session.should_receive(:new).once.with('key', 'secret').and_return(mock_session)
139
+
140
+ Dropbox::Session.deserialize([ 'key', 'secret', false, 'a', 'b' ].to_yaml).should eql(mock_session)
141
+ #TODO request token remains opaque for purposes of testing
142
+ end
143
+
144
+ it "should return a properly initialized authorized instance" do
145
+ pending "access token remains opaque for purposes of testing"
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,57 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Dropbox do
4
+ describe ".api_url" do
5
+ before :each do
6
+ @prefix = "#{Dropbox::HOST}/#{Dropbox::VERSION}/"
7
+ end
8
+
9
+ it "should use the HOST and VERSION" do
10
+ Dropbox.api_url.should eql(@prefix)
11
+ end
12
+
13
+ it "should use the SSL_HOST if :ssl => true is given" do
14
+ Dropbox.api_url(:ssl => true).should eql("#{Dropbox::SSL_HOST}/#{Dropbox::VERSION}/")
15
+ end
16
+
17
+ it "should concatenate path elements with slashes" do
18
+ Dropbox.api_url("foo", :bar, 123).should eql(@prefix + "foo/bar/123")
19
+ end
20
+
21
+ it "should use the trailing hash as query params" do
22
+ [ @prefix + "foo/bar?string=val&hash=123", @prefix + "foo/bar?hash=123&string=val" ].should include(Dropbox.api_url("foo", :bar, 'string' => 'val', :hash => 123))
23
+ end
24
+
25
+ it "should strip the :ssl option from query params" do
26
+ prefix = "#{Dropbox::SSL_HOST}/#{Dropbox::VERSION}/"
27
+ [ prefix + "foo/bar?string=val&hash=123", prefix + "foo/bar?hash=123&string=val" ].should include(Dropbox.api_url("foo", :bar, 'string' => 'val', :hash => 123, :ssl => true))
28
+ end
29
+
30
+ it "should CGI-escape path elements and query parameters" do
31
+ Dropbox.api_url("foo space", "amp&ersand" => 'eq=uals').should eql(@prefix + "foo%20space?amp%26ersand=eq%3Duals")
32
+ end
33
+
34
+ it "should use the alternate host if supplied" do
35
+ Dropbox.api_url('files').should eql("#{Dropbox::ALTERNATE_HOSTS['files']}/#{Dropbox::VERSION}/files")
36
+ end
37
+
38
+ it "should use the alternate SSL host if :ssl => true is given" do
39
+ Dropbox.api_url('files', :ssl => true).should eql("#{Dropbox::ALTERNATE_SSL_HOSTS['files']}/#{Dropbox::VERSION}/files")
40
+ end
41
+ end
42
+
43
+ describe ".check_path" do
44
+ it "should raise an exception if the path contains a backslash" do
45
+ lambda { Dropbox.check_path "hello\\there" }.should raise_error(ArgumentError)
46
+ end
47
+
48
+ it "should raise an exception if the path is longer than 256 characters" do
49
+ lambda { Dropbox.check_path "a"*257 }.should raise_error(ArgumentError)
50
+ end
51
+
52
+ it "should otherwise return the path unchanged" do
53
+ path = "valid path/here"
54
+ lambda { Dropbox.check_path(path).should eql(path) }.should_not raise_error
55
+ end
56
+ end
57
+ end
@@ -0,0 +1 @@
1
+ --color -fs
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'dropbox.rb'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ end
metadata CHANGED
@@ -3,51 +3,50 @@ name: dropbox
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
+ - 1
6
7
  - 0
7
8
  - 0
8
- - 10
9
- version: 0.0.10
9
+ version: 1.0.0
10
10
  platform: ruby
11
11
  authors:
12
- - Tys von Gaza
13
- - JP Hastings-Spital
14
- - Chris Searle
15
- - Nicholas A. Evans
12
+ - Tim Morgan
16
13
  autorequire:
17
14
  bindir: bin
18
15
  cert_chain: []
19
16
 
20
- date: 2010-04-16 00:00:00 -06:00
17
+ date: 2010-05-05 00:00:00 -07:00
21
18
  default_executable:
22
19
  dependencies:
23
20
  - !ruby/object:Gem::Dependency
24
- name: Shoulda
21
+ name: rspec
25
22
  prerelease: false
26
23
  requirement: &id001 !ruby/object:Gem::Requirement
27
24
  requirements:
28
25
  - - ">="
29
26
  - !ruby/object:Gem::Version
30
27
  segments:
31
- - 0
32
- version: "0"
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
33
32
  type: :development
34
33
  version_requirements: *id001
35
34
  - !ruby/object:Gem::Dependency
36
- name: mechanize
35
+ name: oauth
37
36
  prerelease: false
38
37
  requirement: &id002 !ruby/object:Gem::Requirement
39
38
  requirements:
40
39
  - - ">="
41
40
  - !ruby/object:Gem::Version
42
41
  segments:
43
- - 1
44
42
  - 0
45
- - 0
46
- version: 1.0.0
43
+ - 3
44
+ - 6
45
+ version: 0.3.6
47
46
  type: :runtime
48
47
  version_requirements: *id002
49
48
  - !ruby/object:Gem::Dependency
50
- name: nokogiri
49
+ name: json
51
50
  prerelease: false
52
51
  requirement: &id003 !ruby/object:Gem::Requirement
53
52
  requirements:
@@ -56,30 +55,62 @@ dependencies:
56
55
  segments:
57
56
  - 1
58
57
  - 2
59
- - 1
60
- version: 1.2.1
58
+ - 0
59
+ version: 1.2.0
61
60
  type: :runtime
62
61
  version_requirements: *id003
63
- description: A Simple DropBox API in Ruby
64
- email: tys@tvg.ca
62
+ - !ruby/object:Gem::Dependency
63
+ name: multipart-post
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 1
71
+ - 0
72
+ version: "1.0"
73
+ type: :runtime
74
+ version_requirements: *id004
75
+ description: An easy-to-use client library for the official Dropbox API.
76
+ email: dropbox@timothymorgan.info
65
77
  executables: []
66
78
 
67
79
  extensions: []
68
80
 
69
81
  extra_rdoc_files:
70
- - ChangeLog.rdoc
82
+ - LICENSE
71
83
  - README.rdoc
72
84
  files:
85
+ - .document
73
86
  - .gitignore
74
- - ChangeLog.rdoc
87
+ - LICENSE
75
88
  - README.rdoc
76
89
  - Rakefile
77
90
  - VERSION
78
- - examples/dropbox_spec.rb
79
91
  - lib/dropbox.rb
80
- - lib/dropbox/dropbox.rb
92
+ - lib/dropbox/api.rb
93
+ - lib/dropbox/entry.rb
94
+ - lib/dropbox/event.rb
95
+ - lib/dropbox/memoization.rb
96
+ - lib/dropbox/revision.rb
97
+ - lib/dropbox/session.rb
98
+ - lib/extensions/array.rb
99
+ - lib/extensions/hash.rb
100
+ - lib/extensions/module.rb
101
+ - lib/extensions/object.rb
102
+ - lib/extensions/string.rb
103
+ - lib/extensions/to_bool.rb
104
+ - spec/dropbox/api_spec.rb
105
+ - spec/dropbox/entry_spec.rb
106
+ - spec/dropbox/event_spec.rb
107
+ - spec/dropbox/revision_spec.rb
108
+ - spec/dropbox/session_spec.rb
109
+ - spec/dropbox_spec.rb
110
+ - spec/spec.opts
111
+ - spec/spec_helper.rb
81
112
  has_rdoc: true
82
- homepage: http://github.com/tvongaza/DropBox
113
+ homepage: http://github.com/RISCfuture/dropbox
83
114
  licenses: []
84
115
 
85
116
  post_install_message:
@@ -103,10 +134,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
134
  version: "0"
104
135
  requirements: []
105
136
 
106
- rubyforge_project:
137
+ rubyforge_project: dropbox
107
138
  rubygems_version: 1.3.6
108
139
  signing_key:
109
140
  specification_version: 3
110
- summary: A Simple DropBox API in Ruby
141
+ summary: Ruby client library for the official Dropbox API
111
142
  test_files:
112
- - examples/dropbox_spec.rb
143
+ - spec/dropbox/api_spec.rb
144
+ - spec/dropbox/entry_spec.rb
145
+ - spec/dropbox/event_spec.rb
146
+ - spec/dropbox/revision_spec.rb
147
+ - spec/dropbox/session_spec.rb
148
+ - spec/dropbox_spec.rb
149
+ - spec/spec_helper.rb
@@ -1,17 +0,0 @@
1
- == 0.0.10 (April 16, 2010):
2
- * Fixed a bug downloading files (tvongaza)
3
-
4
- == 0.0.9 (April 16, 2010):
5
- * Really fixed bug with empty stats (chrissearle)
6
- * Fixed a bug uploading files (Luka87)
7
-
8
- == 0.0.8 (March 12, 2010):
9
- * Fixed bug with empty stats (chrissearle)
10
-
11
- == 0.0.7 (March 11, 2010):
12
- * Fixed stats (chrissearle)
13
- * Added some additional documentation (tvongaza)
14
- * Running into issue creating files, anyone else?
15
-
16
- == 0.0.6 (March 4, 2010);
17
- * Explicit minimum dependency versions
@@ -1,99 +0,0 @@
1
- require 'rubygems'
2
- require 'spec'
3
- require 'dropbox'
4
-
5
- %w[DROPBOX_EMAIL DROPBOX_PASSWORD].each do |var|
6
- raise "Need to set #{var} to run the specs." unless ENV[var]
7
- end
8
- ENV["DROPBOX_FOLDER_NAMESPACE"] ||= "dropboxrb/specroot"
9
-
10
- describe DropBox do
11
- before :all do
12
- # TODO: check for existance of DROPBOX_FOLDER_NAMESPACE
13
- # TODO: ensure the folder starts out empty
14
- @connection = connection
15
- end
16
-
17
- def connection
18
- DropBox.new(ENV["DROPBOX_EMAIL"],
19
- ENV["DROPBOX_PASSWORD"],
20
- ENV["DROPBOX_FOLDER_NAMESPACE"])
21
- end
22
-
23
- def dirent_for(name)
24
- @connection.list.find {|f| f["name"] == name }
25
- end
26
-
27
- context "uploading a file" do
28
- before :all do
29
- @file = Tempfile.new("dbrb")
30
- @contents = <<-EOF
31
- This is a temp file used by the dropbox.rb specs.
32
- foo
33
- bar
34
- baz
35
- EOF
36
- @file.print @contents
37
- @file.flush
38
- @basename = File.basename(@file.path)
39
- @connection.create(@file.path)
40
- end
41
- after :all do
42
- # TODO: fix the bugs that force us to reset the connection.before deleting the file
43
- @connection.login
44
- @connection.destroy @basename
45
- @file.close!
46
- end
47
-
48
- it "should be listed at the toplevel" do
49
- @connection.list.map {|f| f["name"] }.should include(@basename)
50
- end
51
-
52
- it "should be listed as not a directory" do
53
- dirent_for(@basename)["directory"].should be_false
54
- end
55
-
56
- it "should have a path relative to the folder namespace (containing query params)" do
57
- dirent_for(@basename)["path"].should match(%r{^/#{@basename}\?w=.*$})
58
- end
59
-
60
- it "should be retrievable" do
61
- path = dirent_for(@basename)["path"]
62
- @connection.get(path).should == @contents
63
- end
64
-
65
- end
66
-
67
- context "creating a directory at the toplevel" do
68
- before { @connection.create_directory("spec_create_dir") }
69
- after { @connection.destroy("spec_create_dir") }
70
-
71
- it "should be listed at the toplevel" do
72
- @connection.list.map {|f| f["name"] }.should include("spec_create_dir")
73
- end
74
-
75
- it "should be listed as a directory" do
76
- dirent_for("spec_create_dir")["directory"].should be_true
77
- end
78
-
79
- it "should have a path relative to the folder namespace" do
80
- dirent_for("spec_create_dir")["path"].should == "/spec_create_dir"
81
- end
82
-
83
- it "should contain only a link to the parent directory" do
84
- list = @connection.list("spec_create_dir")
85
- list.should have(1).item
86
- dir = list.first
87
- dir["name"].should == "Parent folder"
88
- dir["directory"].should be_true
89
- dir["path"].should == ""
90
- end
91
-
92
- end
93
-
94
- #context "renaming a file"
95
- #context "deleting a file"
96
-
97
- end
98
-
99
- #describe DropBox, "folder namespace"