rdropbox 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ 1.1.0 (2010-05-27)
2
+
3
+ * Added thumbnails API method.
4
+ * Changed name of gem from rdropbox to dropbox.
5
+ * Fixed potential dependency issues.
6
+ * Documentation updates.
7
+
8
+ 1.0.0 (2010-05-05)
9
+
10
+ * Initial release.
@@ -2,6 +2,10 @@
2
2
 
3
3
  An easy-to-use third-party interface to the RESTful Dropbox API.
4
4
 
5
+ == Installation
6
+
7
+ gem install dropbox
8
+
5
9
  == Tutorial by Example
6
10
 
7
11
  First things first: Be sure you've gotten a consumer key and secret from
@@ -12,7 +16,6 @@ http://developers.dropbox.com
12
16
  puts "Visit #{session.authorize_url} to log in to Dropbox. Hit enter when you have done this."
13
17
  gets
14
18
  session.authorize
15
- session.sandbox = true
16
19
 
17
20
  # STEP 2: Play!
18
21
  session.upload('testfile.txt')
@@ -48,7 +51,7 @@ account, and then upload a file to their Dropbox.
48
51
  return redirect_to(:action => 'authorize') unless dropbox_session.authorized?
49
52
 
50
53
  if request.method == :post then
51
- dropbox_session.upload params[:file], 'My Uploads', :sandbox => true
54
+ dropbox_session.upload params[:file], 'My Uploads'
52
55
  render :text => 'Uploaded OK'
53
56
  else
54
57
  # display a multipart file field form
@@ -67,6 +70,8 @@ account, and then upload a file to their Dropbox.
67
70
  * The Dropbox::Memoization module has some handy utility methods for memoizing
68
71
  server responses to reduce network calls. It's plug-in compatible with any
69
72
  caching strategy you might already have (memcache, etc.).
73
+ * If you're using pingbacks, check out Dropbox::Event and Dropbox::Revision.
74
+ Those classes parse pingbacks from Dropbox into Ruby objects.
70
75
 
71
76
  == Note on Patches/Pull Requests
72
77
 
data/Rakefile CHANGED
@@ -17,8 +17,6 @@ begin
17
17
  gem.add_runtime_dependency "oauth", ">= 0.3.6"
18
18
  gem.add_runtime_dependency "json", ">= 1.2.0"
19
19
  gem.add_runtime_dependency "multipart-post", ">= 1.0"
20
-
21
- gem.rubyforge_project = "dropbox"
22
20
  end
23
21
  Jeweler::GemcutterTasks.new
24
22
  Jeweler::RubyforgeTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -1,3 +1,7 @@
1
+ $stderr.puts "DEPRECATION NOTICE: The rdropbox gem has been renamed dropbox."
2
+ $stderr.puts "Please uninstall this gem and install dropbox instead."
3
+ $stderr.puts "Future updates will only be pushed to the dropbox gemspec."
4
+
1
5
  # Defines the Dropbox module.
2
6
 
3
7
  require 'cgi'
@@ -8,8 +12,19 @@ require 'set'
8
12
  require 'time'
9
13
  require 'tempfile'
10
14
 
11
- Dir.glob("#{File.expand_path File.dirname(__FILE__)}/extensions/*.rb") { |file| require file }
12
- Dir.glob("#{File.expand_path File.dirname(__FILE__)}/dropbox/*.rb") { |file| require file }
15
+ require 'extensions/array'
16
+ require 'extensions/hash'
17
+ require 'extensions/module'
18
+ require 'extensions/object'
19
+ require 'extensions/string'
20
+ require 'extensions/to_bool'
21
+
22
+ require 'dropbox/memoization'
23
+ require 'dropbox/api'
24
+ require 'dropbox/entry'
25
+ require 'dropbox/event'
26
+ require 'dropbox/revision'
27
+ require 'dropbox/session'
13
28
 
14
29
  # Container module for the all Dropbox API classes.
15
30
 
@@ -21,9 +36,17 @@ module Dropbox
21
36
  # The SSL host serving API requests.
22
37
  SSL_HOST = "https://api.dropbox.com"
23
38
  # Alternate hosts for other API requests.
24
- ALTERNATE_HOSTS = { 'event_content' => 'http://api-content.dropbox.com', 'files' => "http://api-content.dropbox.com" }
39
+ ALTERNATE_HOSTS = {
40
+ 'event_content' => 'http://api-content.dropbox.com',
41
+ 'files' => 'http://api-content.dropbox.com',
42
+ 'thumbnails' => 'http://api-content.dropbox.com'
43
+ }
25
44
  # Alternate SSL hosts for other API requests.
26
- ALTERNATE_SSL_HOSTS = { 'event_content' => 'https://api-content.dropbox.com', 'files' => "https://api-content.dropbox.com" }
45
+ ALTERNATE_SSL_HOSTS = {
46
+ 'event_content' => 'https://api-content.dropbox.com',
47
+ 'files' => 'https://api-content.dropbox.com',
48
+ 'thumbnails' => 'https://api-content.dropbox.com'
49
+ }
27
50
 
28
51
  def self.api_url(*paths_and_options) # :nodoc:
29
52
  params = paths_and_options.extract_options!
@@ -1,6 +1,5 @@
1
1
  # Defines the Dropbox::API module.
2
2
 
3
- require "#{File.expand_path File.dirname(__FILE__)}/memoization"
4
3
  require 'json'
5
4
  require 'net/http/post/multipart'
6
5
 
@@ -29,9 +28,9 @@ module Dropbox
29
28
  # are inaccessible.
30
29
  # * In Dropbox mode, the root is the user's Dropbox folder, and all files are
31
30
  # accessible. This mode is typically only available to certain API users.
32
- # * In metadata-only mode, the root is the Dropbox folder, but read-only
33
- # access is not available. Operations that modify the user's files will
34
- # fail.
31
+ # * In metadata-only mode, the root is the Dropbox folder, but write access
32
+ # is not available. Operations that modify the user's files will
33
+ # fail.
35
34
  #
36
35
  # You should configure the Dropbox::Session instance to use whichever mode
37
36
  # you chose when you set up your application:
@@ -63,8 +62,8 @@ module Dropbox
63
62
  alias :dir :entry
64
63
 
65
64
  # Returns a +Struct+ with information about the user's account. See
66
- # http://developers.dropbox.com/python/base.html#account-info for more
67
- # information on the data returned.
65
+ # https://www.dropbox.com/developers/docs#account-info for more information
66
+ # on the data returned.
68
67
 
69
68
  def account
70
69
  get('account', 'info', :ssl => @ssl).to_struct_recursively
@@ -89,6 +88,53 @@ module Dropbox
89
88
  api_body :get, 'files', root(options), *rest
90
89
  #TODO streaming, range queries
91
90
  end
91
+
92
+ # Downloads a minimized thumbnail for a file. Pass the path to the file,
93
+ # optionally the size of the thumbnail you want, and any additional options.
94
+ # See https://www.dropbox.com/developers/docs#thumbnails for a list of valid
95
+ # size specifiers.
96
+ #
97
+ # Returns the content of the thumbnail image as a +String+. The thumbnail
98
+ # data is in JPEG format. Returns +nil+ if the file does not have a
99
+ # thumbnail. You can check if a file has a thumbnail using the metadata
100
+ # method.
101
+ #
102
+ # Because of the way this API method works, if you pass in the name of a
103
+ # file that does not exist, you will not receive a 404, but instead just get
104
+ # +nil+.
105
+ #
106
+ # Options:
107
+ #
108
+ # +mode+:: Temporarily changes the API mode. See the MODES array.
109
+ #
110
+ # Examples:
111
+ #
112
+ # Get the thumbnail for an image (default thunmbnail size):
113
+ #
114
+ # session.thumbnail('my/image.jpg')
115
+ #
116
+ # Get the thumbnail for an image in the +medium+ size:
117
+ #
118
+ # session.thumbnail('my/image.jpg', 'medium')
119
+
120
+ def thumbnail(*args)
121
+ options = args.extract_options!
122
+ path = args.shift
123
+ size = args.shift
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
+
126
+ path.sub! /^\//, ''
127
+ rest = Dropbox.check_path(path).split('/')
128
+ rest << { :ssl => @ssl }
129
+ rest.last[:size] = size if size
130
+
131
+ begin
132
+ api_body :get, 'thumbnails', root(options), *rest
133
+ rescue Dropbox::UnsuccessfulResponseError => e
134
+ raise unless e.response.code.to_i == 404
135
+ return nil
136
+ end
137
+ end
92
138
 
93
139
  # Uploads a file to a path relative to the configured mode's root. The
94
140
  # +remote_path+ parameter is taken to be the path portion _only_; the name
@@ -314,7 +360,7 @@ module Dropbox
314
360
  # true).
315
361
  #
316
362
  # For information on the schema of the return struct, see the Dropbox API
317
- # at http://developers.dropbox.com/python/base.html#metadata
363
+ # at https://www.dropbox.com/developers/docs#metadata
318
364
  #
319
365
  # The +modified+ key will be converted into a +Time+ instance. The +is_dir+
320
366
  # key will also be available as <tt>directory?</tt>.
@@ -82,6 +82,12 @@ module Dropbox
82
82
  @session.download path, options
83
83
  end
84
84
  alias :body :download
85
+
86
+ # Delegates to Dropbox::API#thumbnail.
87
+
88
+ def thumbnail(*args)
89
+ @session.thumbnail path, *args
90
+ end
85
91
 
86
92
  # Delegates to Dropbox::API#link.
87
93
 
@@ -93,4 +99,4 @@ module Dropbox
93
99
  "#<#{self.class.to_s} #{path}>"
94
100
  end
95
101
  end
96
- end
102
+ end
@@ -96,7 +96,6 @@ module Dropbox
96
96
  end
97
97
 
98
98
  def process_metadata(metadata)
99
- p metadata
100
99
  metadata.each do |user_id, namespaces|
101
100
  namespaces.each do |namespace_id, journals|
102
101
  journals.each do |journal_id, attributes|
@@ -4,26 +4,27 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{dropbox}
8
- s.version = "1.0.0"
7
+ s.name = %q{rdropbox}
8
+ s.version = "1.1.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{2010-05-05}
13
- s.description = %q{An easy-to-use interface to the RESTful Dropbox API.}
12
+ s.date = %q{2010-05-27}
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 = [
16
- "LICENSE",
16
+ "ChangeLog",
17
+ "LICENSE",
17
18
  "README.rdoc"
18
19
  ]
19
20
  s.files = [
20
21
  ".document",
21
22
  ".gitignore",
23
+ "ChangeLog",
22
24
  "LICENSE",
23
25
  "README.rdoc",
24
26
  "Rakefile",
25
27
  "VERSION",
26
- "dropbox.gemspec",
27
28
  "lib/dropbox.rb",
28
29
  "lib/dropbox/api.rb",
29
30
  "lib/dropbox/entry.rb",
@@ -37,6 +38,7 @@ Gem::Specification.new do |s|
37
38
  "lib/extensions/object.rb",
38
39
  "lib/extensions/string.rb",
39
40
  "lib/extensions/to_bool.rb",
41
+ "rdropbox.gemspec",
40
42
  "spec/dropbox/api_spec.rb",
41
43
  "spec/dropbox/entry_spec.rb",
42
44
  "spec/dropbox/event_spec.rb",
@@ -49,9 +51,8 @@ Gem::Specification.new do |s|
49
51
  s.homepage = %q{http://github.com/RISCfuture/dropbox}
50
52
  s.rdoc_options = ["--charset=UTF-8"]
51
53
  s.require_paths = ["lib"]
52
- s.rubyforge_project = %q{dropbox}
53
- s.rubygems_version = %q{1.3.6}
54
- s.summary = %q{Ruby Dropbox interface}
54
+ s.rubygems_version = %q{1.3.7}
55
+ s.summary = %q{Ruby client library for the official Dropbox API}
55
56
  s.test_files = [
56
57
  "spec/dropbox/api_spec.rb",
57
58
  "spec/dropbox/entry_spec.rb",
@@ -66,7 +67,7 @@ Gem::Specification.new do |s|
66
67
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
67
68
  s.specification_version = 3
68
69
 
69
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
70
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
70
71
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
71
72
  s.add_runtime_dependency(%q<oauth>, [">= 0.3.6"])
72
73
  s.add_runtime_dependency(%q<json>, [">= 1.2.0"])
@@ -96,6 +96,63 @@ describe Dropbox::API do
96
96
  @session.download(path)
97
97
  end
98
98
  end
99
+
100
+ describe "#thumbnail" do
101
+ it "should call the thumbnails API method" do
102
+ should_receive_api_method_with_arguments @token_mock, :get, 'thumbnails', {}, @response, 'path/to/file', 'sandbox'
103
+ @session.thumbnail "path/to/file"
104
+ end
105
+
106
+ it "should strip a leading slash" do
107
+ should_receive_api_method_with_arguments @token_mock, :get, 'thumbnails', {}, @response, 'path/to/file', 'sandbox'
108
+ @session.thumbnail "/path/to/file"
109
+ end
110
+
111
+ it "should return the body of the response" do
112
+ @token_mock.stub!(:get).and_return(@response)
113
+ @session.thumbnail("path/to/file").should eql("response body")
114
+ end
115
+
116
+ it "should check the path" do
117
+ path = "test/path"
118
+ Dropbox.should_receive(:check_path).once.with(path).and_return(path)
119
+ @token_mock.stub!(:get).and_return(@response)
120
+
121
+ @session.thumbnail(path)
122
+ end
123
+
124
+ it "should pass along a size" do
125
+ should_receive_api_method_with_arguments @token_mock, :get, 'thumbnails', { :size => 'medium' }, @response, 'path/to/file', 'sandbox'
126
+ @session.thumbnail "path/to/file", 'medium'
127
+ end
128
+
129
+ it "should raise an error if too many arguments are given" do
130
+ lambda { @session.thumbnail "path/to/file", 'large', 'oops', :foo => 'bar' }.should raise_error(ArgumentError)
131
+ end
132
+
133
+ it "should raise an error if invalid arguments are given" do
134
+ lambda { @session.thumbnail "path/to/file", 'large', :not_string }.should raise_error(ArgumentError)
135
+ lambda { @session.thumbnail "path/to/file", 'large', 'oops', 'not_hash' }.should raise_error(ArgumentError)
136
+ end
137
+
138
+ it "should return nil if a 404 is received" do
139
+ request_mock = mock('Request')
140
+ response_mock = mock('Response', :code => '404')
141
+ error = Dropbox::UnsuccessfulResponseError.new(request_mock, response_mock)
142
+ @token_mock.stub!(:get).and_raise(error)
143
+
144
+ @session.thumbnail('foo').should be_nil
145
+ end
146
+
147
+ it "should raise any other response codes" do
148
+ request_mock = mock('Request')
149
+ response_mock = mock('Response', :code => '500')
150
+ error = Dropbox::UnsuccessfulResponseError.new(request_mock, response_mock)
151
+ @token_mock.stub!(:get).and_raise(error)
152
+
153
+ lambda { @session.thumbnail('foo') }.should raise_error(Dropbox::UnsuccessfulResponseError)
154
+ end
155
+ end
99
156
 
100
157
  describe "#copy" do
101
158
  before :each do
@@ -125,6 +125,36 @@ describe Dropbox::Entry do
125
125
  @entry.download(:sandbox => true)
126
126
  end
127
127
  end
128
+
129
+ describe "#thumbnail" do
130
+ it "should delegate to the session and return the result" do
131
+ result = mock('result')
132
+ @session.should_receive(:thumbnail).once.with(@path).and_return(result)
133
+
134
+ @entry.thumbnail.should eql(result)
135
+ end
136
+
137
+ it "should pass along a size" do
138
+ result = mock('result')
139
+ @session.should_receive(:thumbnail).once.with(@path, 'medium').and_return(result)
140
+
141
+ @entry.thumbnail('medium').should eql(result)
142
+ end
143
+
144
+ it "should pass along options" do
145
+ result = mock('result')
146
+ @session.should_receive(:thumbnail).once.with(@path, { :sandbox => true }).and_return(result)
147
+
148
+ @entry.thumbnail(:sandbox => true).should eql(result)
149
+ end
150
+
151
+ it "should pass along a size and options" do
152
+ result = mock('result')
153
+ @session.should_receive(:thumbnail).once.with(@path, 'medium', { :sandbox => true }).and_return(result)
154
+
155
+ @entry.thumbnail('medium', :sandbox => true).should eql(result)
156
+ end
157
+ end
128
158
 
129
159
  describe "#link" do
130
160
  it "should delegate to the session and return the result" do
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdropbox
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
8
+ - 1
7
9
  - 0
8
- - 0
9
- version: 1.0.0
10
+ version: 1.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Tim Morgan
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-05 00:00:00 -07:00
18
+ date: 2010-05-27 00:00:00 -07:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rspec
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 13
27
30
  segments:
28
31
  - 1
29
32
  - 2
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: oauth
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 31
41
46
  segments:
42
47
  - 0
43
48
  - 3
@@ -49,9 +54,11 @@ dependencies:
49
54
  name: json
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
61
+ hash: 31
55
62
  segments:
56
63
  - 1
57
64
  - 2
@@ -63,9 +70,11 @@ dependencies:
63
70
  name: multipart-post
64
71
  prerelease: false
65
72
  requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
66
74
  requirements:
67
75
  - - ">="
68
76
  - !ruby/object:Gem::Version
77
+ hash: 15
69
78
  segments:
70
79
  - 1
71
80
  - 0
@@ -79,16 +88,17 @@ executables: []
79
88
  extensions: []
80
89
 
81
90
  extra_rdoc_files:
91
+ - ChangeLog
82
92
  - LICENSE
83
93
  - README.rdoc
84
94
  files:
85
95
  - .document
86
96
  - .gitignore
97
+ - ChangeLog
87
98
  - LICENSE
88
99
  - README.rdoc
89
100
  - Rakefile
90
101
  - VERSION
91
- - dropbox.gemspec
92
102
  - lib/dropbox.rb
93
103
  - lib/dropbox/api.rb
94
104
  - lib/dropbox/entry.rb
@@ -102,6 +112,7 @@ files:
102
112
  - lib/extensions/object.rb
103
113
  - lib/extensions/string.rb
104
114
  - lib/extensions/to_bool.rb
115
+ - rdropbox.gemspec
105
116
  - spec/dropbox/api_spec.rb
106
117
  - spec/dropbox/entry_spec.rb
107
118
  - spec/dropbox/event_spec.rb
@@ -120,23 +131,27 @@ rdoc_options:
120
131
  require_paths:
121
132
  - lib
122
133
  required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
123
135
  requirements:
124
136
  - - ">="
125
137
  - !ruby/object:Gem::Version
138
+ hash: 3
126
139
  segments:
127
140
  - 0
128
141
  version: "0"
129
142
  required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
130
144
  requirements:
131
145
  - - ">="
132
146
  - !ruby/object:Gem::Version
147
+ hash: 3
133
148
  segments:
134
149
  - 0
135
150
  version: "0"
136
151
  requirements: []
137
152
 
138
- rubyforge_project: dropbox
139
- rubygems_version: 1.3.6
153
+ rubyforge_project:
154
+ rubygems_version: 1.3.7
140
155
  signing_key:
141
156
  specification_version: 3
142
157
  summary: Ruby client library for the official Dropbox API