rdropbox 1.0.0

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.
@@ -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
data/spec/spec.opts ADDED
@@ -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 ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdropbox
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Tim Morgan
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-05 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: oauth
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 3
44
+ - 6
45
+ version: 0.3.6
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: json
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 2
58
+ - 0
59
+ version: 1.2.0
60
+ type: :runtime
61
+ version_requirements: *id003
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
77
+ executables: []
78
+
79
+ extensions: []
80
+
81
+ extra_rdoc_files:
82
+ - LICENSE
83
+ - README.rdoc
84
+ files:
85
+ - .document
86
+ - .gitignore
87
+ - LICENSE
88
+ - README.rdoc
89
+ - Rakefile
90
+ - VERSION
91
+ - dropbox.gemspec
92
+ - lib/dropbox.rb
93
+ - lib/dropbox/api.rb
94
+ - lib/dropbox/entry.rb
95
+ - lib/dropbox/event.rb
96
+ - lib/dropbox/memoization.rb
97
+ - lib/dropbox/revision.rb
98
+ - lib/dropbox/session.rb
99
+ - lib/extensions/array.rb
100
+ - lib/extensions/hash.rb
101
+ - lib/extensions/module.rb
102
+ - lib/extensions/object.rb
103
+ - lib/extensions/string.rb
104
+ - lib/extensions/to_bool.rb
105
+ - spec/dropbox/api_spec.rb
106
+ - spec/dropbox/entry_spec.rb
107
+ - spec/dropbox/event_spec.rb
108
+ - spec/dropbox/revision_spec.rb
109
+ - spec/dropbox/session_spec.rb
110
+ - spec/dropbox_spec.rb
111
+ - spec/spec.opts
112
+ - spec/spec_helper.rb
113
+ has_rdoc: true
114
+ homepage: http://github.com/RISCfuture/dropbox
115
+ licenses: []
116
+
117
+ post_install_message:
118
+ rdoc_options:
119
+ - --charset=UTF-8
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ requirements: []
137
+
138
+ rubyforge_project: dropbox
139
+ rubygems_version: 1.3.6
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: Ruby client library for the official Dropbox API
143
+ test_files:
144
+ - spec/dropbox/api_spec.rb
145
+ - spec/dropbox/entry_spec.rb
146
+ - spec/dropbox/event_spec.rb
147
+ - spec/dropbox/revision_spec.rb
148
+ - spec/dropbox/session_spec.rb
149
+ - spec/dropbox_spec.rb
150
+ - spec/spec_helper.rb