dropbox 1.2.3 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +11 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +25 -18
- data/README.rdoc +12 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/dropbox.gemspec +9 -20
- data/keys.json.example +0 -2
- data/lib/dropbox.rb +1 -1
- data/lib/dropbox/session.rb +22 -47
- data/spec/dropbox/session_spec.rb +56 -37
- data/spec/dropbox_spec.rb +5 -0
- data/spec/spec_helper.rb +4 -0
- metadata +68 -108
data/ChangeLog
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
1.3.0 (2011-07-19)
|
2
|
+
|
3
|
+
* NOTE: Removed the ability to automate the OAuth form.
|
4
|
+
* Added a method allowing users to manually set the access token and secret (in
|
5
|
+
case you are doing your own OAuth elsewhere).
|
6
|
+
* The mode (Dropbox or Sandbox) is now serialized.
|
7
|
+
* Fixed a bug that would cause files uploaded into deep paths to fail due to
|
8
|
+
name length limitations.
|
9
|
+
* Fixed a bug that would cause abnormal OAuth requests when deserializing an
|
10
|
+
authorized session.
|
11
|
+
|
1
12
|
1.2.3 (2011-01-14)
|
2
13
|
|
3
14
|
* Now supports caching metadata calls
|
data/Gemfile
CHANGED
@@ -2,10 +2,10 @@ source :rubygems
|
|
2
2
|
|
3
3
|
gem 'oauth', '>= 0.3.6'
|
4
4
|
gem 'json', '>= 1.2.0'
|
5
|
-
gem 'multipart-post', '>= 1.0'
|
6
|
-
gem 'mechanize', '>= 1.0.0'
|
5
|
+
gem 'multipart-post', '>= 1.1.0'
|
7
6
|
|
8
7
|
group :development do
|
9
8
|
gem 'jeweler'
|
10
9
|
gem 'rspec', '>= 2.0'
|
10
|
+
gem 'mechanize'
|
11
11
|
end
|
data/Gemfile.lock
CHANGED
@@ -3,25 +3,32 @@ GEM
|
|
3
3
|
specs:
|
4
4
|
diff-lcs (1.1.2)
|
5
5
|
git (1.2.5)
|
6
|
-
jeweler (1.
|
7
|
-
bundler (~> 1.0
|
6
|
+
jeweler (1.6.4)
|
7
|
+
bundler (~> 1.0)
|
8
8
|
git (>= 1.2.5)
|
9
9
|
rake
|
10
|
-
json (1.
|
11
|
-
mechanize (
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
rspec
|
10
|
+
json (1.5.3)
|
11
|
+
mechanize (2.0.1)
|
12
|
+
net-http-digest_auth (>= 1.1.1, ~> 1.1)
|
13
|
+
net-http-persistent (~> 1.8)
|
14
|
+
nokogiri (~> 1.4)
|
15
|
+
webrobots (>= 0.0.9, ~> 0.0)
|
16
|
+
multipart-post (1.1.2)
|
17
|
+
net-http-digest_auth (1.1.1)
|
18
|
+
net-http-persistent (1.8)
|
19
|
+
nokogiri (1.5.0)
|
20
|
+
oauth (0.4.5)
|
21
|
+
rake (0.9.2)
|
22
|
+
rspec (2.6.0)
|
23
|
+
rspec-core (~> 2.6.0)
|
24
|
+
rspec-expectations (~> 2.6.0)
|
25
|
+
rspec-mocks (~> 2.6.0)
|
26
|
+
rspec-core (2.6.4)
|
27
|
+
rspec-expectations (2.6.0)
|
23
28
|
diff-lcs (~> 1.1.2)
|
24
|
-
rspec-mocks (2.
|
29
|
+
rspec-mocks (2.6.0)
|
30
|
+
webrobots (0.0.10)
|
31
|
+
nokogiri (>= 1.4.4)
|
25
32
|
|
26
33
|
PLATFORMS
|
27
34
|
ruby
|
@@ -29,7 +36,7 @@ PLATFORMS
|
|
29
36
|
DEPENDENCIES
|
30
37
|
jeweler
|
31
38
|
json (>= 1.2.0)
|
32
|
-
mechanize
|
33
|
-
multipart-post (>= 1.0)
|
39
|
+
mechanize
|
40
|
+
multipart-post (>= 1.1.0)
|
34
41
|
oauth (>= 0.3.6)
|
35
42
|
rspec (>= 2.0)
|
data/README.rdoc
CHANGED
@@ -19,13 +19,23 @@ http://developers.dropbox.com
|
|
19
19
|
session.authorize
|
20
20
|
|
21
21
|
# STEP 2: Play!
|
22
|
-
session.upload('testfile.txt')
|
23
|
-
uploaded_file = session.file('testfile.txt'
|
22
|
+
session.upload('testfile.txt', '/')
|
23
|
+
uploaded_file = session.file('testfile.txt')
|
24
24
|
puts uploaded_file.metadata.size
|
25
25
|
|
26
26
|
uploaded_file.move 'new_name.txt'
|
27
27
|
uploaded_file.delete
|
28
28
|
|
29
|
+
# STEP 3: Save session for later
|
30
|
+
File.open('serialized_session.txt', 'w') do |f|
|
31
|
+
f.puts session.serialize
|
32
|
+
end
|
33
|
+
|
34
|
+
# STEP 4: Play with saved session!
|
35
|
+
new_session = Dropbox::Session.deserialize(File.read('serialized_session.txt'))
|
36
|
+
account = new_session.account
|
37
|
+
puts account.display_name
|
38
|
+
|
29
39
|
== Tutorial by Example, Rails Edition
|
30
40
|
|
31
41
|
A simple Rails controller that allows a user to first authorize their Dropbox
|
data/Rakefile
CHANGED
@@ -23,7 +23,7 @@ Jeweler::RubygemsDotOrgTasks.new
|
|
23
23
|
require 'rspec/core/rake_task'
|
24
24
|
RSpec::Core::RakeTask.new
|
25
25
|
|
26
|
-
require '
|
26
|
+
require 'rdoc/task'
|
27
27
|
Rake::RDocTask.new(:doc) do |rdoc|
|
28
28
|
version = File.exist?('VERSION') ? File.read('VERSION').chomp.strip : ""
|
29
29
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
data/dropbox.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dropbox}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tim Morgan"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-07-19}
|
13
13
|
s.description = %q{An easy-to-use client library for the official Dropbox API.}
|
14
14
|
s.email = %q{dropbox@timothymorgan.info}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -53,45 +53,34 @@ Gem::Specification.new do |s|
|
|
53
53
|
]
|
54
54
|
s.homepage = %q{http://github.com/RISCfuture/dropbox}
|
55
55
|
s.require_paths = ["lib"]
|
56
|
-
s.rubygems_version = %q{1.
|
56
|
+
s.rubygems_version = %q{1.6.2}
|
57
57
|
s.summary = %q{Ruby client library for the official Dropbox API}
|
58
|
-
s.test_files = [
|
59
|
-
"examples/upload_and_delete.rb",
|
60
|
-
"spec/dropbox/api_spec.rb",
|
61
|
-
"spec/dropbox/entry_spec.rb",
|
62
|
-
"spec/dropbox/event_spec.rb",
|
63
|
-
"spec/dropbox/revision_spec.rb",
|
64
|
-
"spec/dropbox/session_spec.rb",
|
65
|
-
"spec/dropbox_spec.rb",
|
66
|
-
"spec/spec_helper.rb"
|
67
|
-
]
|
68
58
|
|
69
59
|
if s.respond_to? :specification_version then
|
70
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
71
60
|
s.specification_version = 3
|
72
61
|
|
73
62
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
74
63
|
s.add_runtime_dependency(%q<oauth>, [">= 0.3.6"])
|
75
64
|
s.add_runtime_dependency(%q<json>, [">= 1.2.0"])
|
76
|
-
s.add_runtime_dependency(%q<multipart-post>, [">= 1.0"])
|
77
|
-
s.add_runtime_dependency(%q<mechanize>, [">= 1.0.0"])
|
65
|
+
s.add_runtime_dependency(%q<multipart-post>, [">= 1.1.0"])
|
78
66
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
79
67
|
s.add_development_dependency(%q<rspec>, [">= 2.0"])
|
68
|
+
s.add_development_dependency(%q<mechanize>, [">= 0"])
|
80
69
|
else
|
81
70
|
s.add_dependency(%q<oauth>, [">= 0.3.6"])
|
82
71
|
s.add_dependency(%q<json>, [">= 1.2.0"])
|
83
|
-
s.add_dependency(%q<multipart-post>, [">= 1.0"])
|
84
|
-
s.add_dependency(%q<mechanize>, [">= 1.0.0"])
|
72
|
+
s.add_dependency(%q<multipart-post>, [">= 1.1.0"])
|
85
73
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
86
74
|
s.add_dependency(%q<rspec>, [">= 2.0"])
|
75
|
+
s.add_dependency(%q<mechanize>, [">= 0"])
|
87
76
|
end
|
88
77
|
else
|
89
78
|
s.add_dependency(%q<oauth>, [">= 0.3.6"])
|
90
79
|
s.add_dependency(%q<json>, [">= 1.2.0"])
|
91
|
-
s.add_dependency(%q<multipart-post>, [">= 1.0"])
|
92
|
-
s.add_dependency(%q<mechanize>, [">= 1.0.0"])
|
80
|
+
s.add_dependency(%q<multipart-post>, [">= 1.1.0"])
|
93
81
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
94
82
|
s.add_dependency(%q<rspec>, [">= 2.0"])
|
83
|
+
s.add_dependency(%q<mechanize>, [">= 0"])
|
95
84
|
end
|
96
85
|
end
|
97
86
|
|
data/keys.json.example
CHANGED
data/lib/dropbox.rb
CHANGED
@@ -60,7 +60,7 @@ module Dropbox
|
|
60
60
|
|
61
61
|
def self.check_path(path) # :nodoc:
|
62
62
|
raise ArgumentError, "Backslashes are not allowed in Dropbox paths" if path.include?('\\')
|
63
|
-
raise ArgumentError, "
|
63
|
+
raise ArgumentError, "File names are limited to 255 characters" if path.split('/').last.size > 255 unless path.empty?
|
64
64
|
return path
|
65
65
|
end
|
66
66
|
end
|
data/lib/dropbox/session.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# Defines the Dropbox::Session class.
|
2
2
|
|
3
3
|
require 'oauth'
|
4
|
-
require 'mechanize'
|
5
4
|
|
6
5
|
module Dropbox
|
7
6
|
|
@@ -48,11 +47,6 @@ module Dropbox
|
|
48
47
|
|
49
48
|
class Session
|
50
49
|
include API
|
51
|
-
|
52
|
-
# The email of a Dropbox account to automatically authorize.
|
53
|
-
attr_accessor :authorizing_user
|
54
|
-
# The password of a Dropbox account to automatically authorize.
|
55
|
-
attr_accessor :authorizing_password
|
56
50
|
|
57
51
|
# Begins the authorization process. Provide the OAuth key and secret of your
|
58
52
|
# API account, assigned by Dropbox. This is the first step in the
|
@@ -61,18 +55,10 @@ module Dropbox
|
|
61
55
|
# Options:
|
62
56
|
#
|
63
57
|
# +ssl+:: If true, uses SSL to connect to the Dropbox API server.
|
64
|
-
# +authorizing_user+:: The email of a Dropbox account to automatically
|
65
|
-
# authorize.
|
66
|
-
# +authorizing_password+:: The password of a Dropbox account to
|
67
|
-
# automatically authorize.
|
68
58
|
|
69
59
|
def initialize(oauth_key, oauth_secret, options={})
|
70
60
|
@ssl = options[:ssl].to_bool
|
71
61
|
|
72
|
-
# necessary for the automatic authorization in #authorize!
|
73
|
-
@authorizing_user = options[:authorizing_user] if options[:authorizing_user]
|
74
|
-
@authorizing_password = options[:authorizing_password] if options[:authorizing_password]
|
75
|
-
|
76
62
|
@proxy = options[:proxy] || ENV["HTTP_PROXY"] || ENV["http_proxy"]
|
77
63
|
@proxy = nil if options[:noproxy].to_bool
|
78
64
|
@consumer = OAuth::Consumer.new(oauth_key, oauth_secret,
|
@@ -81,7 +67,7 @@ module Dropbox
|
|
81
67
|
:request_token_path => "/#{Dropbox::VERSION}/oauth/request_token",
|
82
68
|
:authorize_path => "/#{Dropbox::VERSION}/oauth/authorize",
|
83
69
|
:access_token_path => "/#{Dropbox::VERSION}/oauth/access_token")
|
84
|
-
@request_token = @consumer.get_request_token
|
70
|
+
@request_token = @consumer.get_request_token unless options[:already_authorized]
|
85
71
|
end
|
86
72
|
|
87
73
|
# Returns a URL that is used to complete the authorization process. Visiting
|
@@ -118,32 +104,6 @@ module Dropbox
|
|
118
104
|
def authorized?
|
119
105
|
@access_token.to_bool
|
120
106
|
end
|
121
|
-
|
122
|
-
# Automatically complete the authorization step of the OAuth process. You
|
123
|
-
# must have provided the +authorizing_user+ and +authorizing_password+
|
124
|
-
# options. Raises a Dropbox::UnauthorizedError on failure.
|
125
|
-
|
126
|
-
def authorize!
|
127
|
-
begin
|
128
|
-
a = Mechanize.new
|
129
|
-
a.get(authorize_url) do |page|
|
130
|
-
login_form = page.form_with(:action => '/login')
|
131
|
-
|
132
|
-
login_form.login_email = @authorizing_user
|
133
|
-
login_form.login_password = @authorizing_password
|
134
|
-
auth_page = login_form.submit
|
135
|
-
|
136
|
-
auth_form = auth_page.form_with(:action => 'authorize')
|
137
|
-
if auth_form
|
138
|
-
auth_button = auth_form.button_with(:value => "Allow")
|
139
|
-
auth_form.click_button
|
140
|
-
end
|
141
|
-
end
|
142
|
-
rescue OAuth::Unauthorized => e
|
143
|
-
raise Dropbox::UnauthorizedError
|
144
|
-
end
|
145
|
-
authorize
|
146
|
-
end
|
147
107
|
|
148
108
|
# Returns the OAuth access_token which allows access to token and secret.
|
149
109
|
|
@@ -156,9 +116,9 @@ module Dropbox
|
|
156
116
|
|
157
117
|
def serialize
|
158
118
|
if authorized? then
|
159
|
-
[ @consumer.key, @consumer.secret, authorized?, @access_token.token, @access_token.secret, @ssl ].to_yaml
|
119
|
+
[ @consumer.key, @consumer.secret, authorized?, @access_token.token, @access_token.secret, @ssl, mode ].to_yaml
|
160
120
|
else
|
161
|
-
[ @consumer.key, @consumer.secret, authorized?, @request_token.token, @request_token.secret, @ssl ].to_yaml
|
121
|
+
[ @consumer.key, @consumer.secret, authorized?, @request_token.token, @request_token.secret, @ssl, mode ].to_yaml
|
162
122
|
end
|
163
123
|
end
|
164
124
|
|
@@ -166,19 +126,34 @@ module Dropbox
|
|
166
126
|
# Returns the recreated instance.
|
167
127
|
|
168
128
|
def self.deserialize(data)
|
169
|
-
consumer_key, consumer_secret, authorized, token, token_secret, ssl = YAML.load(StringIO.new(data))
|
129
|
+
consumer_key, consumer_secret, authorized, token, token_secret, ssl, mode = YAML.load(StringIO.new(data))
|
170
130
|
raise ArgumentError, "Must provide a properly serialized #{self.to_s} instance" unless [ consumer_key, consumer_secret, token, token_secret ].all? and authorized == true or authorized == false
|
171
131
|
|
172
|
-
session = self.new(consumer_key, consumer_secret, :ssl => ssl)
|
132
|
+
session = self.new(consumer_key, consumer_secret, :ssl => ssl, :already_authorized => authorized)
|
173
133
|
if authorized then
|
174
|
-
session.
|
134
|
+
session.set_access_token token, token_secret
|
175
135
|
else
|
176
|
-
session.
|
136
|
+
session.set_request_token token, token_secret
|
177
137
|
end
|
138
|
+
session.mode = mode if mode
|
178
139
|
|
179
140
|
return session
|
180
141
|
end
|
181
142
|
|
143
|
+
# Manually sets the OAuth request token. Use this method if you are doing
|
144
|
+
# your own OAuth elsewhere.
|
145
|
+
|
146
|
+
def set_request_token(token, token_secret)
|
147
|
+
@request_token = OAuth::RequestToken.new(@consumer, token, token_secret)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Manually sets the OAuth access token. Use this method if you are doing
|
151
|
+
# your own OAuth elsewhere.
|
152
|
+
|
153
|
+
def set_access_token(token, token_secret)
|
154
|
+
@access_token = OAuth::AccessToken.new(@consumer, token, token_secret)
|
155
|
+
end
|
156
|
+
|
182
157
|
def inspect # :nodoc:
|
183
158
|
"#<#{self.class.to_s} #{@consumer.key} (#{'un' unless authorized?}authorized)>"
|
184
159
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'mechanize'
|
2
3
|
|
3
4
|
describe Dropbox::Session do
|
4
5
|
describe ".new" do
|
@@ -132,7 +133,7 @@ describe Dropbox::Session do
|
|
132
133
|
@token_mock.stub!(:token).and_return("request token")
|
133
134
|
@token_mock.stub!(:secret).and_return("request token secret")
|
134
135
|
|
135
|
-
@session.serialize.should eql([ "consumer key", "consumer secret", false, "request token", "request token secret", false ].to_yaml)
|
136
|
+
@session.serialize.should eql([ "consumer key", "consumer secret", false, "request token", "request token secret", false, :sandbox ].to_yaml)
|
136
137
|
end
|
137
138
|
|
138
139
|
it "should serialize the SSL setting" do
|
@@ -142,7 +143,18 @@ describe Dropbox::Session do
|
|
142
143
|
@token_mock.stub!(:token).and_return("request token")
|
143
144
|
@token_mock.stub!(:secret).and_return("request token secret")
|
144
145
|
|
145
|
-
@session.serialize.should eql([ "consumer key", "consumer secret", false, "request token", "request token secret", true ].to_yaml)
|
146
|
+
@session.serialize.should eql([ "consumer key", "consumer secret", false, "request token", "request token secret", true, :sandbox ].to_yaml)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should serialize the mode" do
|
150
|
+
@session = Dropbox::Session.new('foo', 'bar')
|
151
|
+
@consumer_mock.stub!(:key).and_return("consumer key")
|
152
|
+
@consumer_mock.stub!(:secret).and_return("consumer secret")
|
153
|
+
@token_mock.stub!(:token).and_return("request token")
|
154
|
+
@token_mock.stub!(:secret).and_return("request token secret")
|
155
|
+
@session.mode = :dropbox
|
156
|
+
|
157
|
+
@session.serialize.should eql([ "consumer key", "consumer secret", false, "request token", "request token secret", false, :dropbox ].to_yaml)
|
146
158
|
end
|
147
159
|
end
|
148
160
|
|
@@ -152,30 +164,61 @@ describe Dropbox::Session do
|
|
152
164
|
end
|
153
165
|
|
154
166
|
it "should raise an error if an improper YAML is provided" do
|
155
|
-
lambda { Dropbox::Session.deserialize([ 1, 2, 3].to_yaml) }.should raise_error(ArgumentError)
|
167
|
+
lambda { Dropbox::Session.deserialize([ 1, 2, 3 ].to_yaml) }.should raise_error(ArgumentError)
|
156
168
|
end
|
157
169
|
|
158
170
|
it "should return a properly initialized unauthorized instance" do
|
159
|
-
Dropbox::Session.should_receive(:new).once.with('key', 'secret', :ssl => true).and_return(@mock_session)
|
171
|
+
Dropbox::Session.should_receive(:new).once.with('key', 'secret', :ssl => true, :already_authorized => false).and_return(@mock_session)
|
172
|
+
@mock_session.should_receive(:mode=).once.with(:dropbox)
|
173
|
+
@mock_session.should_receive(:set_request_token).once.with('a', 'b')
|
160
174
|
|
161
|
-
Dropbox::Session.deserialize([ 'key', 'secret', false, 'a', 'b', true ].to_yaml).should eql(@mock_session)
|
162
|
-
|
175
|
+
Dropbox::Session.deserialize([ 'key', 'secret', false, 'a', 'b', true, :dropbox ].to_yaml).should eql(@mock_session)
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should return a properly initialized authorized instance" do
|
179
|
+
Dropbox::Session.should_receive(:new).once.with('key', 'secret', :ssl => true, :already_authorized => true).and_return(@mock_session)
|
180
|
+
@mock_session.should_receive(:mode=).once.with(:dropbox)
|
181
|
+
@mock_session.should_receive(:set_access_token).once.with('a', 'b')
|
182
|
+
|
183
|
+
Dropbox::Session.deserialize([ 'key', 'secret', true, 'a', 'b', true, :dropbox ].to_yaml).should eql(@mock_session)
|
163
184
|
end
|
164
185
|
|
165
186
|
it "should allow the SSL option to be left out" do
|
166
|
-
Dropbox::Session.should_receive(:new).once.with('key', 'secret', :ssl => nil).and_return(@mock_session)
|
187
|
+
Dropbox::Session.should_receive(:new).once.with('key', 'secret', :ssl => nil, :already_authorized=>false).and_return(@mock_session)
|
188
|
+
@mock_session.stub!(:mode=)
|
189
|
+
@mock_session.stub!(:set_request_token)
|
167
190
|
|
168
191
|
Dropbox::Session.deserialize([ 'key', 'secret', false, 'a', 'b' ].to_yaml).should eql(@mock_session)
|
169
192
|
end
|
193
|
+
|
194
|
+
it "should allow the mode to be left out" do
|
195
|
+
@mock_session.stub!(:set_request_token)
|
196
|
+
|
197
|
+
Dropbox::Session.should_receive(:new).once.with('key', 'secret', :ssl => nil, :already_authorized=>false).and_return(@mock_session)
|
198
|
+
Dropbox::Session.deserialize([ 'key', 'secret', false, 'a', 'b' ].to_yaml).should eql(@mock_session)
|
199
|
+
end
|
170
200
|
end
|
171
201
|
|
172
|
-
describe "with
|
202
|
+
describe "with actual HTTP calls" do
|
173
203
|
before(:all) do
|
174
204
|
@keys = read_keys_file
|
175
205
|
end
|
176
206
|
|
177
207
|
def new_session
|
178
|
-
Dropbox::Session.new(@keys['key'], @keys['secret']
|
208
|
+
Dropbox::Session.new(@keys['key'], @keys['secret'])
|
209
|
+
end
|
210
|
+
|
211
|
+
def authorize!(session)
|
212
|
+
if @keys['access_token'] and @keys['access_token_secret'] then
|
213
|
+
session.set_access_token @keys['access_token'], @keys['access_token_secret']
|
214
|
+
else
|
215
|
+
puts "Please authorize and then hit enter: #{session.authorize_url}"
|
216
|
+
$stdin.gets
|
217
|
+
session.authorize
|
218
|
+
@keys['access_token'] = session.access_token.token
|
219
|
+
@keys['access_token_secret'] = session.access_token.secret
|
220
|
+
write_keys_file @keys
|
221
|
+
end
|
179
222
|
end
|
180
223
|
|
181
224
|
describe "#authorized?" do
|
@@ -188,39 +231,15 @@ describe Dropbox::Session do
|
|
188
231
|
end
|
189
232
|
|
190
233
|
it "should be true for sessions that have been authorized" do
|
191
|
-
@session
|
234
|
+
authorize! @session
|
192
235
|
@session.should be_authorized
|
193
236
|
end
|
194
237
|
end
|
195
238
|
|
196
|
-
describe "#authorize!" do
|
197
|
-
describe "with credentials" do
|
198
|
-
before(:each) do
|
199
|
-
@session = new_session
|
200
|
-
end
|
201
|
-
|
202
|
-
it "should not fail" do
|
203
|
-
lambda { @session.authorize! }.should_not raise_error
|
204
|
-
end
|
205
|
-
|
206
|
-
it "should return the result of #authorize" do
|
207
|
-
@session.should_receive(:authorize).and_return("winner!")
|
208
|
-
@session.authorize!.should == "winner!"
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
describe "with no credentials" do
|
213
|
-
it "should fail" do
|
214
|
-
@session = Dropbox::Session.new(@keys['key'], @keys['password'])
|
215
|
-
lambda { @session.authorize! }.should raise_error
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
239
|
describe ".deserialize" do
|
221
240
|
it "should return a properly initialized authorized instance" do
|
222
241
|
@session = new_session
|
223
|
-
@session
|
242
|
+
authorize! @session
|
224
243
|
@session_clone = Dropbox::Session.deserialize(@session.serialize)
|
225
244
|
|
226
245
|
@session.serialize.should == @session_clone.serialize
|
@@ -230,8 +249,8 @@ describe Dropbox::Session do
|
|
230
249
|
describe "#serialize" do
|
231
250
|
it "should return the consumer key and secret and the access token and secret in YAML form if authorized" do
|
232
251
|
@session = new_session
|
233
|
-
@session
|
234
|
-
@session.serialize.should eql([ @keys['key'], @keys['secret'], true, @
|
252
|
+
authorize! @session
|
253
|
+
@session.serialize.should eql([ @keys['key'], @keys['secret'], true, @keys['access_token'], @keys['access_token_secret'], false, :sandbox ].to_yaml)
|
235
254
|
end
|
236
255
|
end
|
237
256
|
end
|
data/spec/dropbox_spec.rb
CHANGED
@@ -53,5 +53,10 @@ describe Dropbox do
|
|
53
53
|
path = "valid path/here"
|
54
54
|
lambda { Dropbox.check_path(path).should eql(path) }.should_not raise_error
|
55
55
|
end
|
56
|
+
|
57
|
+
it "should allow a path that is empty" do
|
58
|
+
path = {}
|
59
|
+
lambda { Dropbox.check_path(path).should eql(path) }.should_not raise_error
|
60
|
+
end
|
56
61
|
end
|
57
62
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,119 +1,92 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: dropbox
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 2
|
8
|
-
- 3
|
9
|
-
version: 1.2.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Tim Morgan
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2011-01-14 00:00:00 -08:00
|
12
|
+
date: 2011-07-19 00:00:00.000000000 -07:00
|
18
13
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
21
16
|
name: oauth
|
22
|
-
requirement: &
|
17
|
+
requirement: &2168044400 !ruby/object:Gem::Requirement
|
23
18
|
none: false
|
24
|
-
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
- 3
|
30
|
-
- 6
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
31
22
|
version: 0.3.6
|
32
23
|
type: :runtime
|
33
24
|
prerelease: false
|
34
|
-
version_requirements: *
|
35
|
-
- !ruby/object:Gem::Dependency
|
25
|
+
version_requirements: *2168044400
|
26
|
+
- !ruby/object:Gem::Dependency
|
36
27
|
name: json
|
37
|
-
requirement: &
|
28
|
+
requirement: &2168043920 !ruby/object:Gem::Requirement
|
38
29
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
segments:
|
43
|
-
- 1
|
44
|
-
- 2
|
45
|
-
- 0
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
46
33
|
version: 1.2.0
|
47
34
|
type: :runtime
|
48
35
|
prerelease: false
|
49
|
-
version_requirements: *
|
50
|
-
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: *2168043920
|
37
|
+
- !ruby/object:Gem::Dependency
|
51
38
|
name: multipart-post
|
52
|
-
requirement: &
|
53
|
-
none: false
|
54
|
-
requirements:
|
55
|
-
- - ">="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
segments:
|
58
|
-
- 1
|
59
|
-
- 0
|
60
|
-
version: "1.0"
|
61
|
-
type: :runtime
|
62
|
-
prerelease: false
|
63
|
-
version_requirements: *id003
|
64
|
-
- !ruby/object:Gem::Dependency
|
65
|
-
name: mechanize
|
66
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
39
|
+
requirement: &2168043360 !ruby/object:Gem::Requirement
|
67
40
|
none: false
|
68
|
-
requirements:
|
69
|
-
- -
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
72
|
-
- 1
|
73
|
-
- 0
|
74
|
-
- 0
|
75
|
-
version: 1.0.0
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.1.0
|
76
45
|
type: :runtime
|
77
46
|
prerelease: false
|
78
|
-
version_requirements: *
|
79
|
-
- !ruby/object:Gem::Dependency
|
47
|
+
version_requirements: *2168043360
|
48
|
+
- !ruby/object:Gem::Dependency
|
80
49
|
name: jeweler
|
81
|
-
requirement: &
|
50
|
+
requirement: &2168042860 !ruby/object:Gem::Requirement
|
82
51
|
none: false
|
83
|
-
requirements:
|
84
|
-
- -
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
|
87
|
-
- 0
|
88
|
-
version: "0"
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
89
56
|
type: :development
|
90
57
|
prerelease: false
|
91
|
-
version_requirements: *
|
92
|
-
- !ruby/object:Gem::Dependency
|
58
|
+
version_requirements: *2168042860
|
59
|
+
- !ruby/object:Gem::Dependency
|
93
60
|
name: rspec
|
94
|
-
requirement: &
|
61
|
+
requirement: &2168042320 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '2.0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *2168042320
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: mechanize
|
72
|
+
requirement: &2168041840 !ruby/object:Gem::Requirement
|
95
73
|
none: false
|
96
|
-
requirements:
|
97
|
-
- -
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
|
100
|
-
- 2
|
101
|
-
- 0
|
102
|
-
version: "2.0"
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
103
78
|
type: :development
|
104
79
|
prerelease: false
|
105
|
-
version_requirements: *
|
80
|
+
version_requirements: *2168041840
|
106
81
|
description: An easy-to-use client library for the official Dropbox API.
|
107
82
|
email: dropbox@timothymorgan.info
|
108
83
|
executables: []
|
109
|
-
|
110
84
|
extensions: []
|
111
|
-
|
112
|
-
extra_rdoc_files:
|
85
|
+
extra_rdoc_files:
|
113
86
|
- ChangeLog
|
114
87
|
- LICENSE
|
115
88
|
- README.rdoc
|
116
|
-
files:
|
89
|
+
files:
|
117
90
|
- .document
|
118
91
|
- .rspec
|
119
92
|
- ChangeLog
|
@@ -149,42 +122,29 @@ files:
|
|
149
122
|
has_rdoc: true
|
150
123
|
homepage: http://github.com/RISCfuture/dropbox
|
151
124
|
licenses: []
|
152
|
-
|
153
125
|
post_install_message:
|
154
126
|
rdoc_options: []
|
155
|
-
|
156
|
-
require_paths:
|
127
|
+
require_paths:
|
157
128
|
- lib
|
158
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
130
|
none: false
|
160
|
-
requirements:
|
161
|
-
- -
|
162
|
-
- !ruby/object:Gem::Version
|
163
|
-
|
164
|
-
segments:
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
segments:
|
165
136
|
- 0
|
166
|
-
|
167
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
hash: 2154918313936808061
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
139
|
none: false
|
169
|
-
requirements:
|
170
|
-
- -
|
171
|
-
- !ruby/object:Gem::Version
|
172
|
-
|
173
|
-
- 0
|
174
|
-
version: "0"
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
175
144
|
requirements: []
|
176
|
-
|
177
145
|
rubyforge_project:
|
178
|
-
rubygems_version: 1.
|
146
|
+
rubygems_version: 1.6.2
|
179
147
|
signing_key:
|
180
148
|
specification_version: 3
|
181
149
|
summary: Ruby client library for the official Dropbox API
|
182
|
-
test_files:
|
183
|
-
- examples/upload_and_delete.rb
|
184
|
-
- spec/dropbox/api_spec.rb
|
185
|
-
- spec/dropbox/entry_spec.rb
|
186
|
-
- spec/dropbox/event_spec.rb
|
187
|
-
- spec/dropbox/revision_spec.rb
|
188
|
-
- spec/dropbox/session_spec.rb
|
189
|
-
- spec/dropbox_spec.rb
|
190
|
-
- spec/spec_helper.rb
|
150
|
+
test_files: []
|