dropbox 1.1.0 → 1.1.1

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/.gitignore CHANGED
@@ -20,5 +20,6 @@ tmtags
20
20
  coverage
21
21
  rdoc
22
22
  pkg
23
+ .rvmrc
23
24
 
24
25
  ## PROJECT::SPECIFIC
@@ -73,6 +73,11 @@ account, and then upload a file to their Dropbox.
73
73
  * If you're using pingbacks, check out Dropbox::Event and Dropbox::Revision.
74
74
  Those classes parse pingbacks from Dropbox into Ruby objects.
75
75
 
76
+ == Testing Your Code
77
+
78
+ fguillen has implemented a mock of the Dropbox API server:
79
+ http://github.com/fguillen/DummyDropbox
80
+
76
81
  == Note on Patches/Pull Requests
77
82
 
78
83
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dropbox}
8
- s.version = "1.1.0"
8
+ s.version = "1.1.1"
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{2010-05-27}
12
+ s.date = %q{2010-09-22}
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 = [
@@ -30,15 +30,15 @@ Gem::Specification.new do |s|
30
30
  "lib/dropbox/api.rb",
31
31
  "lib/dropbox/entry.rb",
32
32
  "lib/dropbox/event.rb",
33
+ "lib/dropbox/extensions/array.rb",
34
+ "lib/dropbox/extensions/hash.rb",
35
+ "lib/dropbox/extensions/module.rb",
36
+ "lib/dropbox/extensions/object.rb",
37
+ "lib/dropbox/extensions/string.rb",
38
+ "lib/dropbox/extensions/to_bool.rb",
33
39
  "lib/dropbox/memoization.rb",
34
40
  "lib/dropbox/revision.rb",
35
41
  "lib/dropbox/session.rb",
36
- "lib/extensions/array.rb",
37
- "lib/extensions/hash.rb",
38
- "lib/extensions/module.rb",
39
- "lib/extensions/object.rb",
40
- "lib/extensions/string.rb",
41
- "lib/extensions/to_bool.rb",
42
42
  "spec/dropbox/api_spec.rb",
43
43
  "spec/dropbox/entry_spec.rb",
44
44
  "spec/dropbox/event_spec.rb",
@@ -8,12 +8,12 @@ require 'set'
8
8
  require 'time'
9
9
  require 'tempfile'
10
10
 
11
- require 'extensions/array'
12
- require 'extensions/hash'
13
- require 'extensions/module'
14
- require 'extensions/object'
15
- require 'extensions/string'
16
- require 'extensions/to_bool'
11
+ require 'dropbox/extensions/array'
12
+ require 'dropbox/extensions/hash'
13
+ require 'dropbox/extensions/module'
14
+ require 'dropbox/extensions/object'
15
+ require 'dropbox/extensions/string'
16
+ require 'dropbox/extensions/to_bool'
17
17
 
18
18
  require 'dropbox/memoization'
19
19
  require 'dropbox/api'
@@ -82,7 +82,7 @@ module Dropbox
82
82
  # +mode+:: Temporarily changes the API mode. See the MODES array.
83
83
 
84
84
  def download(path, options={})
85
- path.sub! /^\//, ''
85
+ path = path.sub(/^\//, '')
86
86
  rest = Dropbox.check_path(path).split('/')
87
87
  rest << { :ssl => @ssl }
88
88
  api_body :get, 'files', root(options), *rest
@@ -123,7 +123,7 @@ module Dropbox
123
123
  size = args.shift
124
124
  raise ArgumentError, "thumbnail takes a path, an optional size, and optional options" unless path.kind_of?(String) and (size.kind_of?(String) or size.nil?) and args.empty?
125
125
 
126
- path.sub! /^\//, ''
126
+ path = path.sub(/^\//, '')
127
127
  rest = Dropbox.check_path(path).split('/')
128
128
  rest << { :ssl => @ssl }
129
129
  rest.last[:size] = size if size
@@ -167,7 +167,7 @@ module Dropbox
167
167
  raise ArgumentError, "local_file must be a File or file path"
168
168
  end
169
169
 
170
- remote_path.sub! /^\//, ''
170
+ remote_path = remote_path.sub(/^\//, '')
171
171
  remote_path = Dropbox.check_path(remote_path).split('/')
172
172
 
173
173
  remote_path << { :ssl => @ssl }
@@ -217,8 +217,8 @@ module Dropbox
217
217
  # TODO The API documentation says this method returns 404/403 if the source or target is invalid, but it actually returns 5xx.
218
218
 
219
219
  def copy(source, target, options={})
220
- source.sub! /^\//, ''
221
- target.sub! /^\//, ''
220
+ source = source.sub(/^\//, '')
221
+ target = target.sub(/^\//, '')
222
222
  target << File.basename(source) if target.ends_with?('/')
223
223
  begin
224
224
  parse_metadata(post('fileops', 'copy', :from_path => Dropbox.check_path(source), :to_path => Dropbox.check_path(target), :root => root(options), :ssl => @ssl)).to_struct_recursively
@@ -243,7 +243,7 @@ module Dropbox
243
243
  # TODO The API documentation says this method returns 403 if the path already exists, but it actually appends " (1)" to the end of the name and returns 200.
244
244
 
245
245
  def create_folder(path, options={})
246
- path.sub! /^\//, ''
246
+ path = path.sub(/^\//, '')
247
247
  path.sub! /\/$/, ''
248
248
  begin
249
249
  parse_metadata(post('fileops', 'create_folder', :path => Dropbox.check_path(path), :root => root(options), :ssl => @ssl)).to_struct_recursively
@@ -266,7 +266,7 @@ module Dropbox
266
266
  # TODO The API documentation says this method returns 404 if the path does not exist, but it actually returns 5xx.
267
267
 
268
268
  def delete(path, options={})
269
- path.sub! /^\//, ''
269
+ path = path.sub(/^\//, '')
270
270
  path.sub! /\/$/, ''
271
271
  begin
272
272
  api_response(:post, 'fileops', 'delete', :path => Dropbox.check_path(path), :root => root(options), :ssl => @ssl)
@@ -296,8 +296,8 @@ module Dropbox
296
296
  # TODO The API documentation says this method returns 404/403 if the source or target is invalid, but it actually returns 5xx.
297
297
 
298
298
  def move(source, target, options={})
299
- source.sub! /^\//, ''
300
- target.sub! /^\//, ''
299
+ source = source.sub(/^\//, '')
300
+ target = target.sub(/^\//, '')
301
301
  target << File.basename(source) if target.ends_with?('/')
302
302
  begin
303
303
  parse_metadata(post('fileops', 'move', :from_path => Dropbox.check_path(source), :to_path => Dropbox.check_path(target), :root => root(options), :ssl => @ssl)).to_struct_recursively
@@ -322,7 +322,7 @@ module Dropbox
322
322
 
323
323
  def rename(path, new_name, options={})
324
324
  raise ArgumentError, "Names cannot have slashes in them" if new_name.include?('/')
325
- path.sub! /\/$/, ''
325
+ path = path.sub(/\/$/, '')
326
326
  destination = path.split('/')
327
327
  destination[destination.size - 1] = new_name
328
328
  destination = destination.join('/')
@@ -339,7 +339,7 @@ module Dropbox
339
339
  # +mode+:: Temporarily changes the API mode. See the MODES array.
340
340
 
341
341
  def link(path, options={})
342
- path.sub! /^\//, ''
342
+ path = path.sub(/^\//, '')
343
343
  begin
344
344
  rest = Dropbox.check_path(path).split('/')
345
345
  rest << { :ssl => @ssl }
@@ -377,7 +377,7 @@ module Dropbox
377
377
  # TODO hash option seems to return HTTPBadRequest for now
378
378
 
379
379
  def metadata(path, options={})
380
- path.sub! /^\//, ''
380
+ path = path.sub(/^\//, '')
381
381
  args = [
382
382
  'metadata',
383
383
  root(options)
@@ -22,7 +22,7 @@ class Hash # :nodoc:
22
22
  hsh.each { |k, v| hsh[k] = v.symbolize_keys_recursively if v.kind_of?(Hash) }
23
23
  hsh.each { |k, v| hsh[k] = v.map { |i| i.kind_of?(Hash) ? i.symbolize_keys_recursively : i } if v.kind_of?(Array) }
24
24
  return hsh
25
- end
25
+ end unless method_defined?(:symbolize_keys_recursively)
26
26
 
27
27
  def stringify_keys # :nodoc:
28
28
  inject({}) do |options, (key, value)|
@@ -40,7 +40,7 @@ class Hash # :nodoc:
40
40
  hsh.each { |k, v| hsh[k] = v.stringify_keys_recursively if v.kind_of?(Hash) }
41
41
  hsh.each { |k, v| hsh[k] = v.map { |i| i.kind_of?(Hash) ? i.stringify_keys_recursively : i } if v.kind_of?(Array) }
42
42
  return hsh
43
- end
43
+ end unless method_defined?(:stringify_keys_recursively)
44
44
 
45
45
  def to_struct # :nodoc:
46
46
  struct = Struct.new(*keys).new(*values)
@@ -50,12 +50,12 @@ class Hash # :nodoc:
50
50
  struct.eigenclass.send(:define_method, key.to_sym) { return val }
51
51
  end
52
52
  return struct
53
- end
53
+ end unless method_defined?(:to_struct)
54
54
 
55
55
  def to_struct_recursively # :nodoc:
56
56
  hsh = dup
57
57
  hsh.each { |k, v| hsh[k] = v.to_struct_recursively if v.kind_of?(Hash) }
58
58
  hsh.each { |k, v| hsh[k] = v.map { |i| i.kind_of?(Hash) ? i.to_struct_recursively : i } if v.kind_of?(Array) }
59
59
  return hsh.to_struct
60
- end
60
+ end unless method_defined?(:to_struct_recursively)
61
61
  end
@@ -1,5 +1,5 @@
1
1
  class Object # :nodoc:
2
2
  def eigenclass # :nodoc:
3
3
  (class << self; self; end)
4
- end
4
+ end unless method_defined?(:eigenclass)
5
5
  end
@@ -1,17 +1,17 @@
1
- class Object # :nodoc:
2
- def to_bool # :nodoc:
3
- true
4
- end
5
- end
6
-
7
1
  class FalseClass # :nodoc:
8
2
  def to_bool # :nodoc:
9
3
  false
10
- end
4
+ end unless method_defined?(:to_bool)
11
5
  end
12
6
 
13
7
  class NilClass # :nodoc:
14
8
  def to_bool # :nodoc:
15
9
  false
16
- end
10
+ end unless method_defined?(:to_bool)
17
11
  end
12
+
13
+ class Object # :nodoc:
14
+ def to_bool # :nodoc:
15
+ true
16
+ end unless method_defined?(:to_bool)
17
+ end
@@ -58,8 +58,11 @@ module Dropbox
58
58
 
59
59
  def initialize(oauth_key, oauth_secret, options={})
60
60
  @ssl = options[:ssl].to_bool
61
+ @proxy = options[:proxy] || ENV["HTTP_PROXY"] || ENV["http_proxy"]
62
+ @proxy = nil if options[:noproxy].to_bool
61
63
  @consumer = OAuth::Consumer.new(oauth_key, oauth_secret,
62
64
  :site => (@ssl ? Dropbox::SSL_HOST : Dropbox::HOST),
65
+ :proxy => @proxy,
63
66
  :request_token_path => "/#{Dropbox::VERSION}/oauth/request_token",
64
67
  :authorize_path => "/#{Dropbox::VERSION}/oauth/authorize",
65
68
  :access_token_path => "/#{Dropbox::VERSION}/oauth/access_token")
@@ -106,9 +109,9 @@ module Dropbox
106
109
 
107
110
  def serialize
108
111
  if authorized? then
109
- [ @consumer.key, @consumer.secret, authorized?, @access_token.token, @access_token.secret ].to_yaml
112
+ [ @consumer.key, @consumer.secret, authorized?, @access_token.token, @access_token.secret, @ssl ].to_yaml
110
113
  else
111
- [ @consumer.key, @consumer.secret, authorized?, @request_token.token, @request_token.secret ].to_yaml
114
+ [ @consumer.key, @consumer.secret, authorized?, @request_token.token, @request_token.secret, @ssl ].to_yaml
112
115
  end
113
116
  end
114
117
 
@@ -116,10 +119,10 @@ module Dropbox
116
119
  # Returns the recreated instance.
117
120
 
118
121
  def self.deserialize(data)
119
- consumer_key, consumer_secret, authorized, token, token_secret = YAML.load(StringIO.new(data))
122
+ consumer_key, consumer_secret, authorized, token, token_secret, ssl = YAML.load(StringIO.new(data))
120
123
  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
121
124
 
122
- session = self.new(consumer_key, consumer_secret)
125
+ session = self.new(consumer_key, consumer_secret, :ssl => ssl)
123
126
  if authorized then
124
127
  session.instance_variable_set :@access_token, OAuth::AccessToken.new(session.instance_variable_get(:@consumer), token, token_secret)
125
128
  else
@@ -7,6 +7,7 @@ describe Dropbox::Session do
7
7
  secret = 'test_secret'
8
8
  options_hash = [ 'request_token', 'authorize', 'access_token' ].inject({}) { |hsh, cur| hsh["#{cur}_path".to_sym] = "/#{Dropbox::VERSION}/oauth/#{cur}" ; hsh }
9
9
  options_hash[:site] = Dropbox::HOST
10
+ options_hash[:proxy] = nil
10
11
 
11
12
  consumer_mock = mock('OAuth::Consumer')
12
13
  consumer_mock.stub!(:get_request_token)
@@ -20,6 +21,7 @@ describe Dropbox::Session do
20
21
  secret = 'test_secret'
21
22
  options_hash = [ 'request_token', 'authorize', 'access_token' ].inject({}) { |hsh, cur| hsh["#{cur}_path".to_sym] = "/#{Dropbox::VERSION}/oauth/#{cur}" ; hsh }
22
23
  options_hash[:site] = Dropbox::SSL_HOST
24
+ options_hash[:proxy] = nil
23
25
 
24
26
  consumer_mock = mock('OAuth::Consumer')
25
27
  consumer_mock.stub!(:get_request_token)
@@ -27,6 +29,20 @@ describe Dropbox::Session do
27
29
 
28
30
  Dropbox::Session.new(key, secret, :ssl => true)
29
31
  end
32
+
33
+ it "should create a new OAuth::Consumer" do
34
+ key = 'test_key'
35
+ secret = 'test_secret'
36
+ options_hash = [ 'request_token', 'authorize', 'access_token' ].inject({}) { |hsh, cur| hsh["#{cur}_path".to_sym] = "/#{Dropbox::VERSION}/oauth/#{cur}" ; hsh }
37
+ options_hash[:site] = Dropbox::HOST
38
+ options_hash[:proxy] = proxy = mock('proxy')
39
+
40
+ consumer_mock = mock('OAuth::Consumer')
41
+ consumer_mock.stub!(:get_request_token)
42
+ OAuth::Consumer.should_receive(:new).once.with(key, secret, options_hash).and_return(consumer_mock)
43
+
44
+ Dropbox::Session.new(key, secret, :proxy => proxy)
45
+ end
30
46
 
31
47
  it "should get the request token" do
32
48
  consumer_mock = mock('OAuth::Consumer')
@@ -120,7 +136,17 @@ describe Dropbox::Session do
120
136
  @token_mock.stub!(:token).and_return("request token")
121
137
  @token_mock.stub!(:secret).and_return("request token secret")
122
138
 
123
- @session.serialize.should eql([ "consumer key", "consumer secret", false, "request token", "request token secret" ].to_yaml)
139
+ @session.serialize.should eql([ "consumer key", "consumer secret", false, "request token", "request token secret", false ].to_yaml)
140
+ end
141
+
142
+ it "should serialize the SSL setting" do
143
+ @session = Dropbox::Session.new('foo', 'bar', :ssl => true)
144
+ @consumer_mock.stub!(:key).and_return("consumer key")
145
+ @consumer_mock.stub!(:secret).and_return("consumer secret")
146
+ @token_mock.stub!(:token).and_return("request token")
147
+ @token_mock.stub!(:secret).and_return("request token secret")
148
+
149
+ @session.serialize.should eql([ "consumer key", "consumer secret", false, "request token", "request token secret", true ].to_yaml)
124
150
  end
125
151
 
126
152
  it "should return the consumer key and secret and the access token and secret in YAML form if authorized" do
@@ -135,11 +161,18 @@ describe Dropbox::Session do
135
161
 
136
162
  it "should return a properly initialized unauthorized instance" do
137
163
  mock_session = mock('Dropbox::Session')
138
- Dropbox::Session.should_receive(:new).once.with('key', 'secret').and_return(mock_session)
164
+ Dropbox::Session.should_receive(:new).once.with('key', 'secret', :ssl => true).and_return(mock_session)
139
165
 
140
- Dropbox::Session.deserialize([ 'key', 'secret', false, 'a', 'b' ].to_yaml).should eql(mock_session)
166
+ Dropbox::Session.deserialize([ 'key', 'secret', false, 'a', 'b', true ].to_yaml).should eql(mock_session)
141
167
  #TODO request token remains opaque for purposes of testing
142
168
  end
169
+
170
+ it "should allow the SSL option to be left out" do
171
+ mock_session = mock('Dropbox::Session')
172
+ Dropbox::Session.should_receive(:new).once.with('key', 'secret', :ssl => nil).and_return(mock_session)
173
+
174
+ Dropbox::Session.deserialize([ 'key', 'secret', false, 'a', 'b' ].to_yaml).should eql(mock_session)
175
+ end
143
176
 
144
177
  it "should return a properly initialized authorized instance" do
145
178
  pending "access token remains opaque for purposes of testing"
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropbox
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
8
7
  - 1
9
- - 0
10
- version: 1.1.0
8
+ - 1
9
+ version: 1.1.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Tim Morgan
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-05-27 00:00:00 -07:00
17
+ date: 2010-09-22 00:00:00 -07:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 13
30
28
  segments:
31
29
  - 1
32
30
  - 2
@@ -42,7 +40,6 @@ dependencies:
42
40
  requirements:
43
41
  - - ">="
44
42
  - !ruby/object:Gem::Version
45
- hash: 31
46
43
  segments:
47
44
  - 0
48
45
  - 3
@@ -58,7 +55,6 @@ dependencies:
58
55
  requirements:
59
56
  - - ">="
60
57
  - !ruby/object:Gem::Version
61
- hash: 31
62
58
  segments:
63
59
  - 1
64
60
  - 2
@@ -74,7 +70,6 @@ dependencies:
74
70
  requirements:
75
71
  - - ">="
76
72
  - !ruby/object:Gem::Version
77
- hash: 15
78
73
  segments:
79
74
  - 1
80
75
  - 0
@@ -104,15 +99,15 @@ files:
104
99
  - lib/dropbox/api.rb
105
100
  - lib/dropbox/entry.rb
106
101
  - lib/dropbox/event.rb
102
+ - lib/dropbox/extensions/array.rb
103
+ - lib/dropbox/extensions/hash.rb
104
+ - lib/dropbox/extensions/module.rb
105
+ - lib/dropbox/extensions/object.rb
106
+ - lib/dropbox/extensions/string.rb
107
+ - lib/dropbox/extensions/to_bool.rb
107
108
  - lib/dropbox/memoization.rb
108
109
  - lib/dropbox/revision.rb
109
110
  - lib/dropbox/session.rb
110
- - lib/extensions/array.rb
111
- - lib/extensions/hash.rb
112
- - lib/extensions/module.rb
113
- - lib/extensions/object.rb
114
- - lib/extensions/string.rb
115
- - lib/extensions/to_bool.rb
116
111
  - spec/dropbox/api_spec.rb
117
112
  - spec/dropbox/entry_spec.rb
118
113
  - spec/dropbox/event_spec.rb
@@ -135,7 +130,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
130
  requirements:
136
131
  - - ">="
137
132
  - !ruby/object:Gem::Version
138
- hash: 3
139
133
  segments:
140
134
  - 0
141
135
  version: "0"
@@ -144,7 +138,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
138
  requirements:
145
139
  - - ">="
146
140
  - !ruby/object:Gem::Version
147
- hash: 3
148
141
  segments:
149
142
  - 0
150
143
  version: "0"