dropbox-api 0.2.0 → 0.2.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/lib/dropbox-api/client.rb +2 -0
- data/lib/dropbox-api/client/files.rb +2 -0
- data/lib/dropbox-api/client/raw.rb +1 -1
- data/lib/dropbox-api/connection/requests.rb +6 -4
- data/lib/dropbox-api/util/util.rb +6 -0
- data/lib/dropbox-api/version.rb +1 -1
- data/spec/lib/dropbox-api/client_spec.rb +29 -0
- metadata +9 -8
data/lib/dropbox-api/client.rb
CHANGED
@@ -7,6 +7,7 @@ module Dropbox
|
|
7
7
|
|
8
8
|
def download(path, options = {})
|
9
9
|
root = options.delete(:root) || Dropbox::API::Config.mode
|
10
|
+
path = Dropbox::API::Util.escape(path)
|
10
11
|
url = ['', "files", root, path].compact.join('/')
|
11
12
|
connection.get_raw(:content, url)
|
12
13
|
end
|
@@ -14,6 +15,7 @@ module Dropbox
|
|
14
15
|
def upload(path, data, options = {})
|
15
16
|
root = options.delete(:root) || Dropbox::API::Config.mode
|
16
17
|
query = Dropbox::API::Util.query(options)
|
18
|
+
path = Dropbox::API::Util.escape(path)
|
17
19
|
url = ['', "files_put", root, path].compact.join('/')
|
18
20
|
response = connection.put(:content, "#{url}?#{query}", data, {
|
19
21
|
'Content-Type' => "application/octet-stream",
|
@@ -22,7 +22,7 @@ module Dropbox
|
|
22
22
|
|
23
23
|
def request(endpoint, method, action, data = {})
|
24
24
|
action.sub! ':root', data.delete(:root) if action.match ':root'
|
25
|
-
action.sub! ':path', data.delete(:path) if action.match ':path'
|
25
|
+
action.sub! ':path', Dropbox::API::Util.escape(data.delete(:path)) if action.match ':path'
|
26
26
|
connection.send(method, endpoint, action, data)
|
27
27
|
end
|
28
28
|
|
@@ -29,29 +29,31 @@ module Dropbox
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
|
33
|
+
|
32
34
|
def get_raw(endpoint, path, data = {}, headers = {})
|
33
35
|
query = Dropbox::API::Util.query(data)
|
34
36
|
request(:raw => true) do
|
35
|
-
token(endpoint).get "#{Dropbox::API::Config.prefix}#{
|
37
|
+
token(endpoint).get "#{Dropbox::API::Config.prefix}#{path}?#{URI.parse(URI.encode(query))}", headers
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
41
|
def get(endpoint, path, data = {}, headers = {})
|
40
42
|
query = Dropbox::API::Util.query(data)
|
41
43
|
request do
|
42
|
-
token(endpoint).get "#{Dropbox::API::Config.prefix}#{
|
44
|
+
token(endpoint).get "#{Dropbox::API::Config.prefix}#{path}?#{URI.parse(URI.encode(query))}", headers
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
46
48
|
def post(endpoint, path, data = {}, headers = {})
|
47
49
|
request do
|
48
|
-
token(endpoint).post "#{Dropbox::API::Config.prefix}#{
|
50
|
+
token(endpoint).post "#{Dropbox::API::Config.prefix}#{path}", data, headers
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
52
54
|
def put(endpoint, path, data = {}, headers = {})
|
53
55
|
request do
|
54
|
-
token(endpoint).put "#{Dropbox::API::Config.prefix}#{
|
56
|
+
token(endpoint).put "#{Dropbox::API::Config.prefix}#{path}", data, headers
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
@@ -5,6 +5,12 @@ module Dropbox
|
|
5
5
|
|
6
6
|
class << self
|
7
7
|
|
8
|
+
def escape(string)
|
9
|
+
string.gsub(/([^ a-zA-Z0-9\.\\\-\/\_]+)/) do
|
10
|
+
'%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
|
11
|
+
end.gsub(' ', '%20')
|
12
|
+
end
|
13
|
+
|
8
14
|
def query(data)
|
9
15
|
data.inject([]) { |memo, entry| memo.push(entry.join('=')); memo }.join('&')
|
10
16
|
end
|
data/lib/dropbox-api/version.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require "spec_helper"
|
2
3
|
|
3
4
|
describe Dropbox::API::Client do
|
@@ -49,6 +50,20 @@ describe Dropbox::API::Client do
|
|
49
50
|
response.should be_an_instance_of(Dropbox::API::Dir)
|
50
51
|
end
|
51
52
|
|
53
|
+
it "creates dirs with tricky characters" do
|
54
|
+
dirname = "test/test-dir |!@\#$%^&*{b}[].;'.,<>?: #{Dropbox::Spec.namespace}"
|
55
|
+
response = @client.mkdir dirname
|
56
|
+
response.path.should == dirname.gsub(/[\\\:\?\*\<\>\"\|]+/, '')
|
57
|
+
response.should be_an_instance_of(Dropbox::API::Dir)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "creates dirs with utf8 characters" do
|
61
|
+
dirname = "test/test-dir łółą #{Dropbox::Spec.namespace}"
|
62
|
+
response = @client.mkdir dirname
|
63
|
+
response.path.should == dirname
|
64
|
+
response.should be_an_instance_of(Dropbox::API::Dir)
|
65
|
+
end
|
66
|
+
|
52
67
|
end
|
53
68
|
|
54
69
|
describe "#upload" do
|
@@ -60,6 +75,19 @@ describe Dropbox::API::Client do
|
|
60
75
|
response.bytes.should == 9
|
61
76
|
end
|
62
77
|
|
78
|
+
it "uploads the file with tricky characters" do
|
79
|
+
filename = "test/test ,|!@\#$%^&*{b}[].;'.,<>?:-#{Dropbox::Spec.namespace}.txt"
|
80
|
+
response = @client.upload filename, "Some file"
|
81
|
+
response.path.should == filename
|
82
|
+
response.bytes.should == 9
|
83
|
+
end
|
84
|
+
|
85
|
+
it "uploads the file with utf8" do
|
86
|
+
filename = "test/test łołąó-#{Dropbox::Spec.namespace}.txt"
|
87
|
+
response = @client.upload filename, "Some file"
|
88
|
+
response.path.should == filename
|
89
|
+
response.bytes.should == 9
|
90
|
+
end
|
63
91
|
end
|
64
92
|
|
65
93
|
describe "#search" do
|
@@ -77,6 +105,7 @@ describe Dropbox::API::Client do
|
|
77
105
|
describe "#download" do
|
78
106
|
|
79
107
|
it "downloads a file from Dropbox" do
|
108
|
+
@client.upload 'test/test.txt', "Some file"
|
80
109
|
file = @client.download 'test/test.txt'
|
81
110
|
file.should == "Some file"
|
82
111
|
end
|
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.1
|
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-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yajl-ruby
|
16
|
-
requirement: &
|
16
|
+
requirement: &70337833527400 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70337833527400
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: oauth
|
27
|
-
requirement: &
|
27
|
+
requirement: &70337833526700 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70337833526700
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: hashie
|
38
|
-
requirement: &
|
38
|
+
requirement: &70337833526140 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70337833526140
|
47
47
|
description: To deliver a more Rubyesque experience when using the DropBox API.
|
48
48
|
email:
|
49
49
|
- marcin@futuresimple.com
|
@@ -121,3 +121,4 @@ test_files:
|
|
121
121
|
- spec/spec_helper.rb
|
122
122
|
- spec/support/config.rb
|
123
123
|
- spec/support/jpeg.rb
|
124
|
+
has_rdoc:
|