dropbox-api 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a497d50d7c10eb7ace7e89beffe53806096d7e7
4
- data.tar.gz: 638bebfaa0400f030068dcc07d8549fbea9d284e
3
+ metadata.gz: 479b56344f30f924e5356feb539d00639397d4bd
4
+ data.tar.gz: cc4e16ab4d6507626469ab4172cf1860d7d9888b
5
5
  SHA512:
6
- metadata.gz: 9d62dc7f4c700a210e9853ee2919db1bbab97224ca2ae7a512b095199e1a93e08a1057cb3c6c46e48b57044bb251567bdb95e446d2a26222ec7c8cb020f81822
7
- data.tar.gz: 0b91edbe79fb4e0bab7d4af3d849b5f785b49758196ff9b89dad14c19eb995b452202daeb32827e45c85669a68391315cce833b3a71ba281a21efe3a80177356
6
+ metadata.gz: 4dc5213599843a81ad89b47842a1298063150d9e658e543df9bc5641bd1678319bcdb796ff51caeba33fb849b264a45ee5372b7a4fb4990634a1f7afc07bb1cb
7
+ data.tar.gz: 059424661b5c12a9263a6f828c192dffaa8fe35cc13b41a438a8d9da8e04aa7dc0296c74f874da61f271d66cb34e6a3d60c4ae2afb0604dd8a2674b4d839a79a
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ 0.4.5
2
+ + Add Dropbox::API::Client#chunked_upload
1
3
  0.4.4
2
4
  + Add Dropbox::API::Dir#hash which returns the dropbox hash
3
5
  0.4.3
@@ -18,8 +18,7 @@ module Dropbox
18
18
  include Dropbox::API::Client::Files
19
19
 
20
20
  def find(filename)
21
- data = self.raw.metadata(:path => filename)
22
- data.delete('contents')
21
+ data = self.raw.metadata(:path => filename, :list => false)
23
22
  Dropbox::API::Object.convert(data, self)
24
23
  end
25
24
 
@@ -24,10 +24,47 @@ module Dropbox
24
24
  Dropbox::API::File.init(response, self)
25
25
  end
26
26
 
27
+ def chunked_upload(path, file, options = {})
28
+ root = options.delete(:root) || Dropbox::API::Config.mode
29
+ path = Dropbox::API::Util.escape(path)
30
+ upload_url = '/chunked_upload'
31
+ commit_url = ['', "commit_chunked_upload", root, path].compact.join('/')
32
+
33
+ total_file_size = ::File.size(file)
34
+ chunk_size = options[:chunk_size] || 4*1024*1024 # default 4 MB chunk size
35
+ offset = options[:offset] || 0
36
+ upload_id = options[:upload_id]
37
+
38
+ while offset < total_file_size
39
+ data = file.read(chunk_size)
40
+
41
+ query = Dropbox::API::Util.query(options.merge(:offset => offset))
42
+ response = connection.put(:content, "#{upload_url}?#{query}", data, {
43
+ 'Content-Type' => "application/octet-stream",
44
+ "Content-Length" => data.length.to_s
45
+ })
46
+
47
+ upload = Dropbox::API::Object.init(response, self)
48
+ options[:upload_id] ||= upload[:upload_id]
49
+ offset += upload[:offset].to_i - offset if upload[:offset] && upload[:offset].to_i > offset
50
+ yield offset, upload if block_given?
51
+ end
52
+
53
+
54
+ query = Dropbox::API::Util.query({:upload_id => options[:upload_id]})
55
+
56
+ response = connection.post(:content, "#{commit_url}?#{query}", "", {
57
+ 'Content-Type' => "application/octet-stream",
58
+ "Content-Length" => "0"
59
+ })
60
+
61
+ Dropbox::API::File.init(response, self)
62
+ end
63
+
27
64
  def copy_from_copy_ref(copy_ref, to, options = {})
28
- raw.copy({
29
- :from_copy_ref => copy_ref,
30
- :to_path => to
65
+ raw.copy({
66
+ :from_copy_ref => copy_ref,
67
+ :to_path => to
31
68
  }.merge(options))
32
69
  end
33
70
 
@@ -1,5 +1,5 @@
1
1
  module Dropbox
2
2
  module API
3
- VERSION = "0.4.4"
3
+ VERSION = "0.4.5"
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require "spec_helper"
3
+ require "tempfile"
3
4
 
4
5
  describe Dropbox::API::Client do
5
6
 
@@ -114,6 +115,26 @@ describe Dropbox::API::Client do
114
115
  end
115
116
  end
116
117
 
118
+ describe "#chunked_upload" do
119
+
120
+ before do
121
+ @size = 5*1024*1024 # 5MB, to test the 4MB chunk size
122
+ @file = File.open("/tmp/dropbox-api-test", "w") {|f| f.write "a"*@size}
123
+ end
124
+
125
+ it "puts a 5MB file in dropbox" do
126
+ filename = "#{Dropbox::Spec.test_dir}/test-#{Dropbox::Spec.namespace}.txt"
127
+ response = @client.chunked_upload filename, File.open("/tmp/dropbox-api-test")
128
+ response.path.should == filename
129
+ response.bytes.should == @size
130
+ end
131
+
132
+ after do
133
+ FileUtils.rm "/tmp/dropbox-api-test"
134
+ end
135
+
136
+ end
137
+
117
138
  describe "#search" do
118
139
 
119
140
  let(:term) { "searchable-test-#{Dropbox::Spec.namespace}" }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropbox-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Bunsch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-30 00:00:00.000000000 Z
11
+ date: 2014-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json