dropbox 1.0.0 → 1.1.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,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.
@@ -4,7 +4,7 @@ An easy-to-use third-party interface to the RESTful Dropbox API.
4
4
 
5
5
  == Installation
6
6
 
7
- sudo gem install rdropbox
7
+ gem install dropbox
8
8
 
9
9
  == Tutorial by Example
10
10
 
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
@@ -0,0 +1,88 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dropbox}
8
+ s.version = "1.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Tim Morgan"]
12
+ s.date = %q{2010-05-27}
13
+ s.description = %q{An easy-to-use client library for the official Dropbox API.}
14
+ s.email = %q{dropbox@timothymorgan.info}
15
+ s.extra_rdoc_files = [
16
+ "ChangeLog",
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "ChangeLog",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "dropbox.gemspec",
29
+ "lib/dropbox.rb",
30
+ "lib/dropbox/api.rb",
31
+ "lib/dropbox/entry.rb",
32
+ "lib/dropbox/event.rb",
33
+ "lib/dropbox/memoization.rb",
34
+ "lib/dropbox/revision.rb",
35
+ "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
+ "spec/dropbox/api_spec.rb",
43
+ "spec/dropbox/entry_spec.rb",
44
+ "spec/dropbox/event_spec.rb",
45
+ "spec/dropbox/revision_spec.rb",
46
+ "spec/dropbox/session_spec.rb",
47
+ "spec/dropbox_spec.rb",
48
+ "spec/spec.opts",
49
+ "spec/spec_helper.rb"
50
+ ]
51
+ s.homepage = %q{http://github.com/RISCfuture/dropbox}
52
+ s.rdoc_options = ["--charset=UTF-8"]
53
+ s.require_paths = ["lib"]
54
+ s.rubygems_version = %q{1.3.7}
55
+ s.summary = %q{Ruby client library for the official Dropbox API}
56
+ s.test_files = [
57
+ "spec/dropbox/api_spec.rb",
58
+ "spec/dropbox/entry_spec.rb",
59
+ "spec/dropbox/event_spec.rb",
60
+ "spec/dropbox/revision_spec.rb",
61
+ "spec/dropbox/session_spec.rb",
62
+ "spec/dropbox_spec.rb",
63
+ "spec/spec_helper.rb"
64
+ ]
65
+
66
+ if s.respond_to? :specification_version then
67
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
68
+ s.specification_version = 3
69
+
70
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
71
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
72
+ s.add_runtime_dependency(%q<oauth>, [">= 0.3.6"])
73
+ s.add_runtime_dependency(%q<json>, [">= 1.2.0"])
74
+ s.add_runtime_dependency(%q<multipart-post>, [">= 1.0"])
75
+ else
76
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
77
+ s.add_dependency(%q<oauth>, [">= 0.3.6"])
78
+ s.add_dependency(%q<json>, [">= 1.2.0"])
79
+ s.add_dependency(%q<multipart-post>, [">= 1.0"])
80
+ end
81
+ else
82
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
83
+ s.add_dependency(%q<oauth>, [">= 0.3.6"])
84
+ s.add_dependency(%q<json>, [">= 1.2.0"])
85
+ s.add_dependency(%q<multipart-post>, [">= 1.0"])
86
+ end
87
+ end
88
+
@@ -8,8 +8,19 @@ require 'set'
8
8
  require 'time'
9
9
  require 'tempfile'
10
10
 
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 }
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'
17
+
18
+ require 'dropbox/memoization'
19
+ require 'dropbox/api'
20
+ require 'dropbox/entry'
21
+ require 'dropbox/event'
22
+ require 'dropbox/revision'
23
+ require 'dropbox/session'
13
24
 
14
25
  # Container module for the all Dropbox API classes.
15
26
 
@@ -21,9 +32,17 @@ module Dropbox
21
32
  # The SSL host serving API requests.
22
33
  SSL_HOST = "https://api.dropbox.com"
23
34
  # Alternate hosts for other API requests.
24
- ALTERNATE_HOSTS = { 'event_content' => 'http://api-content.dropbox.com', 'files' => "http://api-content.dropbox.com" }
35
+ ALTERNATE_HOSTS = {
36
+ 'event_content' => 'http://api-content.dropbox.com',
37
+ 'files' => 'http://api-content.dropbox.com',
38
+ 'thumbnails' => 'http://api-content.dropbox.com'
39
+ }
25
40
  # Alternate SSL hosts for other API requests.
26
- ALTERNATE_SSL_HOSTS = { 'event_content' => 'https://api-content.dropbox.com', 'files' => "https://api-content.dropbox.com" }
41
+ ALTERNATE_SSL_HOSTS = {
42
+ 'event_content' => 'https://api-content.dropbox.com',
43
+ 'files' => 'https://api-content.dropbox.com',
44
+ 'thumbnails' => 'https://api-content.dropbox.com'
45
+ }
27
46
 
28
47
  def self.api_url(*paths_and_options) # :nodoc:
29
48
  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
 
@@ -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|
@@ -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: dropbox
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,15 +88,18 @@ 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
102
+ - dropbox.gemspec
91
103
  - lib/dropbox.rb
92
104
  - lib/dropbox/api.rb
93
105
  - lib/dropbox/entry.rb
@@ -119,23 +131,27 @@ rdoc_options:
119
131
  require_paths:
120
132
  - lib
121
133
  required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
122
135
  requirements:
123
136
  - - ">="
124
137
  - !ruby/object:Gem::Version
138
+ hash: 3
125
139
  segments:
126
140
  - 0
127
141
  version: "0"
128
142
  required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
129
144
  requirements:
130
145
  - - ">="
131
146
  - !ruby/object:Gem::Version
147
+ hash: 3
132
148
  segments:
133
149
  - 0
134
150
  version: "0"
135
151
  requirements: []
136
152
 
137
- rubyforge_project: dropbox
138
- rubygems_version: 1.3.6
153
+ rubyforge_project:
154
+ rubygems_version: 1.3.7
139
155
  signing_key:
140
156
  specification_version: 3
141
157
  summary: Ruby client library for the official Dropbox API