dropbox-api 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/dropbox-api.gemspec +1 -1
- data/lib/dropbox-api/client.rb +8 -1
- data/lib/dropbox-api/client/files.rb +4 -0
- data/lib/dropbox-api/client/raw.rb +3 -1
- data/lib/dropbox-api/objects/file.rb +6 -1
- data/lib/dropbox-api/tasks.rb +3 -3
- data/lib/dropbox-api/version.rb +1 -1
- data/spec/connection.sample.yml +2 -1
- data/spec/lib/dropbox-api/client_spec.rb +63 -11
- data/spec/lib/dropbox-api/dir_spec.rb +1 -1
- data/spec/lib/dropbox-api/file_spec.rb +14 -2
- data/spec/lib/dropbox-api/thumbnail_spec.rb +1 -1
- data/spec/spec_helper.rb +9 -0
- data/spec/support/config.rb +2 -0
- metadata +25 -10
data/dropbox-api.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Dropbox::API::VERSION
|
8
8
|
s.authors = ["Marcin Bunsch"]
|
9
9
|
s.email = ["marcin@futuresimple.com"]
|
10
|
-
s.homepage = ""
|
10
|
+
s.homepage = "http://github.com/futuresimple/dropbox-api"
|
11
11
|
s.summary = "A Ruby client for the DropBox REST API."
|
12
12
|
s.description = "To deliver a more Rubyesque experience when using the DropBox API."
|
13
13
|
|
data/lib/dropbox-api/client.rb
CHANGED
@@ -18,7 +18,9 @@ module Dropbox
|
|
18
18
|
include Dropbox::API::Client::Files
|
19
19
|
|
20
20
|
def find(filename)
|
21
|
-
|
21
|
+
data = self.raw.metadata(:path => filename)
|
22
|
+
data.delete('contents')
|
23
|
+
Dropbox::API::Object.convert(data, self)
|
22
24
|
end
|
23
25
|
|
24
26
|
def ls(path = '')
|
@@ -42,6 +44,11 @@ module Dropbox
|
|
42
44
|
Dropbox::API::Object.convert(results, self)
|
43
45
|
end
|
44
46
|
|
47
|
+
def delta(cursor = nil, options = {})
|
48
|
+
response = cursor ? raw.delta({ :cursor => cursor }.merge(options)) : raw.delta(options)
|
49
|
+
Dropbox::API::Object.init(response, self)
|
50
|
+
end
|
51
|
+
|
45
52
|
end
|
46
53
|
|
47
54
|
end
|
@@ -11,7 +11,7 @@ module Dropbox
|
|
11
11
|
|
12
12
|
def self.add_method(method, action, options = {})
|
13
13
|
# Add the default root bit, but allow it to be disabled by a config option
|
14
|
-
root = options[:root] == false ? '' : "options[:root] ||=
|
14
|
+
root = options[:root] == false ? '' : "options[:root] ||= Dropbox::API::Config.mode"
|
15
15
|
self.class_eval <<-STR
|
16
16
|
def #{options[:as] || action}(options = {})
|
17
17
|
#{root}
|
@@ -29,6 +29,7 @@ module Dropbox
|
|
29
29
|
add_method :get, "/account/info", :as => 'account', :root => false
|
30
30
|
|
31
31
|
add_method :get, "/metadata/:root/:path", :as => 'metadata'
|
32
|
+
add_method :post, "/delta", :as => 'delta', :root => false
|
32
33
|
add_method :get, "/revisions/:root/:path", :as => 'revisions'
|
33
34
|
add_method :post, "/restore/:root/:path", :as => 'restore'
|
34
35
|
add_method :get, "/search/:root/:path", :as => 'search'
|
@@ -38,6 +39,7 @@ module Dropbox
|
|
38
39
|
add_method :get_raw, "/thumbnails/:root/:path", :as => 'thumbnails', :endpoint => :content
|
39
40
|
|
40
41
|
add_method :post, "/fileops/copy", :as => "copy"
|
42
|
+
add_method :get, "/copy_ref/:root/:path", :as => 'copy_ref'
|
41
43
|
add_method :post, "/fileops/create_folder", :as => "create_folder"
|
42
44
|
add_method :post, "/fileops/delete", :as => "delete"
|
43
45
|
add_method :post, "/fileops/move", :as => "move"
|
@@ -28,7 +28,12 @@ module Dropbox
|
|
28
28
|
def thumbnail(options = {})
|
29
29
|
client.raw.thumbnails({ :path => self.path }.merge(options))
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
|
+
def copy_ref(options = {})
|
33
|
+
response = client.raw.copy_ref({ :path => self.path }.merge(options))
|
34
|
+
Dropbox::API::Object.init(response, client)
|
35
|
+
end
|
36
|
+
|
32
37
|
def download
|
33
38
|
client.download(self.path)
|
34
39
|
end
|
data/lib/dropbox-api/tasks.rb
CHANGED
@@ -33,9 +33,9 @@ module Dropbox
|
|
33
33
|
access_token = request_token.get_access_token(:oauth_verifier => token)
|
34
34
|
|
35
35
|
puts "\nAuthorization complete!:\n\n"
|
36
|
-
puts " Dropbox::
|
37
|
-
puts " Dropbox::
|
38
|
-
puts " client = Dropbox::
|
36
|
+
puts " Dropbox::API::Config.app_key = '#{consumer.key}'"
|
37
|
+
puts " Dropbox::API::Config.app_secret = '#{consumer.secret}'"
|
38
|
+
puts " client = Dropbox::API::Client.new(:token => '#{access_token.token}', :secret => '#{access_token.secret}')"
|
39
39
|
puts "\n"
|
40
40
|
end
|
41
41
|
end
|
data/lib/dropbox-api/version.rb
CHANGED
data/spec/connection.sample.yml
CHANGED
@@ -25,6 +25,30 @@ describe Dropbox::API::Client do
|
|
25
25
|
|
26
26
|
end
|
27
27
|
|
28
|
+
describe "#find" do
|
29
|
+
|
30
|
+
before do
|
31
|
+
@filename = "#{Dropbox::Spec.test_dir}/spec-find-file-test-#{Time.now.to_i}.txt"
|
32
|
+
@file = @client.upload @filename, "spec file"
|
33
|
+
|
34
|
+
@dirname = "#{Dropbox::Spec.test_dir}/spec-find-dir-test-#{Time.now.to_i}"
|
35
|
+
@dir = @client.mkdir @dirname
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns a single file" do
|
39
|
+
response = @client.find(@filename)
|
40
|
+
response.path.should == @file.path
|
41
|
+
response.should be_an_instance_of(Dropbox::API::File)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns a single directory" do
|
45
|
+
response = @client.find(@dirname)
|
46
|
+
response.path.should == @dir.path
|
47
|
+
response.should be_an_instance_of(Dropbox::API::Dir)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
28
52
|
describe "#ls" do
|
29
53
|
|
30
54
|
it "returns an array of files and dirs" do
|
@@ -33,7 +57,7 @@ describe Dropbox::API::Client do
|
|
33
57
|
end
|
34
58
|
|
35
59
|
it "returns a single item array of if we ls a file" do
|
36
|
-
result = @client.ls
|
60
|
+
result = @client.ls(Dropbox::Spec.test_dir)
|
37
61
|
first_file = result.detect { |f| f.class == Dropbox::API::File }
|
38
62
|
result = @client.ls first_file.path
|
39
63
|
result.should be_an_instance_of(Array)
|
@@ -44,21 +68,21 @@ describe Dropbox::API::Client do
|
|
44
68
|
describe "#mkdir" do
|
45
69
|
|
46
70
|
it "returns an array of files and dirs" do
|
47
|
-
dirname = "
|
71
|
+
dirname = "#{Dropbox::Spec.test_dir}/test-dir-#{Dropbox::Spec.namespace}"
|
48
72
|
response = @client.mkdir dirname
|
49
73
|
response.path.should == dirname
|
50
74
|
response.should be_an_instance_of(Dropbox::API::Dir)
|
51
75
|
end
|
52
76
|
|
53
77
|
it "creates dirs with tricky characters" do
|
54
|
-
dirname = "
|
78
|
+
dirname = "#{Dropbox::Spec.test_dir}/test-dir |!@\#$%^&*{b}[].;'.,<>?: #{Dropbox::Spec.namespace}"
|
55
79
|
response = @client.mkdir dirname
|
56
80
|
response.path.should == dirname.gsub(/[\\\:\?\*\<\>\"\|]+/, '')
|
57
81
|
response.should be_an_instance_of(Dropbox::API::Dir)
|
58
82
|
end
|
59
83
|
|
60
84
|
it "creates dirs with utf8 characters" do
|
61
|
-
dirname = "
|
85
|
+
dirname = "#{Dropbox::Spec.test_dir}/test-dir łółą #{Dropbox::Spec.namespace}"
|
62
86
|
response = @client.mkdir dirname
|
63
87
|
response.path.should == dirname
|
64
88
|
response.should be_an_instance_of(Dropbox::API::Dir)
|
@@ -69,21 +93,21 @@ describe Dropbox::API::Client do
|
|
69
93
|
describe "#upload" do
|
70
94
|
|
71
95
|
it "puts the file in dropbox" do
|
72
|
-
filename = "
|
96
|
+
filename = "#{Dropbox::Spec.test_dir}/test-#{Dropbox::Spec.namespace}.txt"
|
73
97
|
response = @client.upload filename, "Some file"
|
74
98
|
response.path.should == filename
|
75
99
|
response.bytes.should == 9
|
76
100
|
end
|
77
101
|
|
78
102
|
it "uploads the file with tricky characters" do
|
79
|
-
filename = "
|
103
|
+
filename = "#{Dropbox::Spec.test_dir}/test ,|!@\#$%^&*{b}[].;'.,<>?:-#{Dropbox::Spec.namespace}.txt"
|
80
104
|
response = @client.upload filename, "Some file"
|
81
105
|
response.path.should == filename
|
82
106
|
response.bytes.should == 9
|
83
107
|
end
|
84
108
|
|
85
109
|
it "uploads the file with utf8" do
|
86
|
-
filename = "
|
110
|
+
filename = "#{Dropbox::Spec.test_dir}/test łołąó-#{Dropbox::Spec.namespace}.txt"
|
87
111
|
response = @client.upload filename, "Some file"
|
88
112
|
response.path.should == filename
|
89
113
|
response.bytes.should == 9
|
@@ -93,26 +117,54 @@ describe Dropbox::API::Client do
|
|
93
117
|
describe "#search" do
|
94
118
|
|
95
119
|
it "finds a file" do
|
120
|
+
filename = "#{Dropbox::Spec.test_dir}/searchable-test-#{Dropbox::Spec.namespace}.txt"
|
121
|
+
@client.upload filename, "Some file"
|
122
|
+
response = @client.search "searchable-test-#{Dropbox::Spec.namespace}", :path => "#{Dropbox::Spec.test_dir}"
|
123
|
+
response.size.should == 1
|
124
|
+
response.first.class.should == Dropbox::API::File
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "#copy_from_copy_ref" do
|
130
|
+
|
131
|
+
it "copies a file from a copy_ref" do
|
96
132
|
filename = "test/searchable-test-#{Dropbox::Spec.namespace}.txt"
|
97
133
|
@client.upload filename, "Some file"
|
98
|
-
response = @client.search "searchable-test-#{Dropbox::Spec.namespace}", :path => 'test'
|
134
|
+
response = @client.search "searchable-test-#{Dropbox::Spec.namespace}", :path => 'test'
|
135
|
+
ref = response.first.copy_ref['copy_ref']
|
136
|
+
@client.copy_from_copy_ref ref, "#{filename}.copied"
|
137
|
+
response = @client.search "searchable-test-#{Dropbox::Spec.namespace}.txt.copied", :path => 'test'
|
99
138
|
response.size.should == 1
|
100
139
|
response.first.class.should == Dropbox::API::File
|
101
140
|
end
|
102
141
|
|
103
142
|
end
|
104
143
|
|
144
|
+
describe "#delta" do
|
145
|
+
|
146
|
+
it "receives an object with a cursor and list of entries" do
|
147
|
+
filename = "test/delta-test-#{Dropbox::Spec.namespace}.txt"
|
148
|
+
@client.upload filename, "Some file"
|
149
|
+
response = @client.delta
|
150
|
+
response.cursor.should_not be_nil
|
151
|
+
response.entries.should_not be_nil
|
152
|
+
response.should be_an_instance_of(Dropbox::API::Object)
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
105
157
|
describe "#download" do
|
106
158
|
|
107
159
|
it "downloads a file from Dropbox" do
|
108
|
-
@client.upload
|
109
|
-
file = @client.download
|
160
|
+
@client.upload "#{Dropbox::Spec.test_dir}/test.txt", "Some file"
|
161
|
+
file = @client.download "#{Dropbox::Spec.test_dir}/test.txt"
|
110
162
|
file.should == "Some file"
|
111
163
|
end
|
112
164
|
|
113
165
|
it "raises a 404 when a file is not found in Dropbox" do
|
114
166
|
lambda {
|
115
|
-
@client.download
|
167
|
+
@client.download "#{Dropbox::Spec.test_dir}/no.txt"
|
116
168
|
}.should raise_error(Dropbox::API::Error::NotFound)
|
117
169
|
end
|
118
170
|
|
@@ -4,7 +4,7 @@ describe Dropbox::API::File do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
@client = Dropbox::Spec.instance
|
7
|
-
@filename = "
|
7
|
+
@filename = "#{Dropbox::Spec.test_dir}/spec-test-#{Time.now.to_i}.txt"
|
8
8
|
@file = @client.upload @filename, "spec file"
|
9
9
|
end
|
10
10
|
|
@@ -21,7 +21,7 @@ describe Dropbox::API::File do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
describe "#move" do
|
26
26
|
|
27
27
|
it "moves the file properly" do
|
@@ -91,6 +91,18 @@ describe Dropbox::API::File do
|
|
91
91
|
|
92
92
|
end
|
93
93
|
|
94
|
+
describe "#copy_ref" do
|
95
|
+
|
96
|
+
it "returns a copy_ref object" do
|
97
|
+
|
98
|
+
result = @file.copy_ref
|
99
|
+
result.should be_an_instance_of(Dropbox::API::Object)
|
100
|
+
result.keys.sort.should == ['copy_ref', 'expires']
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
94
106
|
describe "#direct_url" do
|
95
107
|
|
96
108
|
it "returns an Url object" do
|
@@ -6,7 +6,7 @@ describe Dropbox::API::File do
|
|
6
6
|
before do
|
7
7
|
@io = StringIO.new
|
8
8
|
@client = Dropbox::Spec.instance
|
9
|
-
@filename = "
|
9
|
+
@filename = "#{Dropbox::Spec.test_dir}/spec-test-#{Time.now.to_i}.jpg"
|
10
10
|
jpeg = File.read("spec/fixtures/dropbox.jpg")
|
11
11
|
@file = @client.upload @filename, jpeg
|
12
12
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,3 +12,12 @@ module Dropbox
|
|
12
12
|
end
|
13
13
|
|
14
14
|
Dir.glob("#{File.dirname(__FILE__)}/support/*.rb").each { |f| require f }
|
15
|
+
|
16
|
+
# Clean up after specs, remove test-directory
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.after(:all) do
|
19
|
+
test_dir = Dropbox::Spec.instance.find(Dropbox::Spec.test_dir)
|
20
|
+
test_dir.destroy unless test_dir.is_deleted?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
data/spec/support/config.rb
CHANGED
@@ -4,6 +4,7 @@ config = YAML.load_file "spec/connection.yml"
|
|
4
4
|
|
5
5
|
Dropbox::API::Config.app_key = config['app_key']
|
6
6
|
Dropbox::API::Config.app_secret = config['app_secret']
|
7
|
+
Dropbox::API::Config.mode = config['mode']
|
7
8
|
|
8
9
|
Dropbox::Spec.token = config['token']
|
9
10
|
Dropbox::Spec.secret = config['secret']
|
@@ -11,3 +12,4 @@ Dropbox::Spec.secret = config['secret']
|
|
11
12
|
Dropbox::Spec.namespace = Time.now.to_i
|
12
13
|
Dropbox::Spec.instance = Dropbox::API::Client.new(:token => Dropbox::Spec.token,
|
13
14
|
:secret => Dropbox::Spec.secret)
|
15
|
+
Dropbox::Spec.test_dir = "test-#{Time.now.to_i}"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dropbox-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yajl-ruby
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: oauth
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: hashie
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,7 +53,12 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
description: To deliver a more Rubyesque experience when using the DropBox API.
|
48
63
|
email:
|
49
64
|
- marcin@futuresimple.com
|
@@ -85,7 +100,7 @@ files:
|
|
85
100
|
- spec/spec_helper.rb
|
86
101
|
- spec/support/config.rb
|
87
102
|
- spec/support/jpeg.rb
|
88
|
-
homepage:
|
103
|
+
homepage: http://github.com/futuresimple/dropbox-api
|
89
104
|
licenses: []
|
90
105
|
post_install_message:
|
91
106
|
rdoc_options: []
|
@@ -105,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
120
|
version: '0'
|
106
121
|
requirements: []
|
107
122
|
rubyforge_project: dropbox-api
|
108
|
-
rubygems_version: 1.8.
|
123
|
+
rubygems_version: 1.8.24
|
109
124
|
signing_key:
|
110
125
|
specification_version: 3
|
111
126
|
summary: A Ruby client for the DropBox REST API.
|