dropbox-api 0.3.1 → 0.3.2

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/README.markdown CHANGED
@@ -218,6 +218,24 @@ However, you can specify your own path:
218
218
  client.search 'pattern', :path => 'somedir' # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
219
219
  ```
220
220
 
221
+ ### Dropbox::API::Client#delta
222
+
223
+ Returns a cursor and a list of files that have changed since the cursor was generated.
224
+
225
+ ```ruby
226
+ delta = client.delta 'abc123'
227
+ delta.cursor # => 'def456'
228
+ delta.entries # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
229
+ ```
230
+
231
+ When called without a cursor, it returns all the files.
232
+
233
+ ```ruby
234
+ delta = client.delta 'abc123'
235
+ delta.cursor # => 'abc123'
236
+ delta.entries # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
237
+ ```
238
+
221
239
  Dropbox::API::File and Dropbox::API::Dir methods
222
240
  ----------------------------
223
241
 
data/lib/dropbox-api.rb CHANGED
@@ -17,5 +17,6 @@ require "dropbox-api/objects/object"
17
17
  require "dropbox-api/objects/fileops"
18
18
  require "dropbox-api/objects/file"
19
19
  require "dropbox-api/objects/dir"
20
+ require "dropbox-api/objects/delta"
20
21
  require "dropbox-api/connection"
21
22
  require "dropbox-api/client"
@@ -44,9 +44,22 @@ module Dropbox
44
44
  Dropbox::API::Object.convert(results, self)
45
45
  end
46
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)
47
+ def delta(cursor=nil)
48
+ entries = []
49
+ has_more = true
50
+ params = cursor ? {:cursor => cursor} : {}
51
+ while has_more
52
+ response = raw.delta(params)
53
+ params[:cursor] = response['cursor']
54
+ has_more = response['has_more']
55
+ entries.push *response['entries']
56
+ end
57
+
58
+ files = entries.map do |entry|
59
+ entry.last || {:is_deleted => true, :path => entry.first}
60
+ end
61
+
62
+ Delta.new(params[:cursor], Dropbox::API::Object.convert(files, self))
50
63
  end
51
64
 
52
65
  end
@@ -0,0 +1,11 @@
1
+ module Dropbox
2
+ module API
3
+ class Delta
4
+ attr_reader :cursor, :entries
5
+ def initialize(cursor, entries)
6
+ @cursor = cursor
7
+ @entries = entries
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Dropbox
2
2
  module API
3
- VERSION = "0.3.1"
3
+ VERSION = "0.3.2"
4
4
  end
5
5
  end
@@ -153,19 +153,6 @@ describe Dropbox::API::Client do
153
153
 
154
154
  end
155
155
 
156
- describe "#delta" do
157
-
158
- it "receives an object with a cursor and list of entries" do
159
- filename = "test/delta-test-#{Dropbox::Spec.namespace}.txt"
160
- @client.upload filename, "Some file"
161
- response = @client.delta
162
- response.cursor.should_not be_nil
163
- response.entries.should_not be_nil
164
- response.should be_an_instance_of(Dropbox::API::Object)
165
- end
166
-
167
- end
168
-
169
156
  describe "#download" do
170
157
 
171
158
  it "downloads a file from Dropbox" do
@@ -182,4 +169,33 @@ describe Dropbox::API::Client do
182
169
 
183
170
  end
184
171
 
172
+ describe "#delta" do
173
+ it "returns a cursor and list of files" do
174
+ filename = "#{Dropbox::Spec.test_dir}/delta-test-#{Dropbox::Spec.namespace}.txt"
175
+ @client.upload filename, 'Some file'
176
+ response = @client.delta
177
+ cursor, files = response.cursor, response.entries
178
+ cursor.should be_an_instance_of(String)
179
+ files.should be_an_instance_of(Array)
180
+ files.last.should be_an_instance_of(Dropbox::API::File)
181
+ end
182
+
183
+ it "returns the files that have changed since the cursor was made" do
184
+ filename = "#{Dropbox::Spec.test_dir}/delta-test-#{Dropbox::Spec.namespace}.txt"
185
+ delete_filename = "#{Dropbox::Spec.test_dir}/delta-test-delete-#{Dropbox::Spec.namespace}.txt"
186
+ @client.upload delete_filename, 'Some file'
187
+ response = @client.delta
188
+ cursor, files = response.cursor, response.entries
189
+ files.last.path.should == delete_filename
190
+ files.last.destroy
191
+ @client.upload filename, 'Another file'
192
+ response = @client.delta(cursor)
193
+ cursor, files = response.cursor, response.entries
194
+ files.length.should == 2
195
+ files.first.is_deleted.should == true
196
+ files.first.path.should == delete_filename
197
+ files.last.path.should == filename
198
+ end
199
+ end
200
+
185
201
  end
@@ -20,8 +20,8 @@ describe Dropbox::API::File do
20
20
  @io.rewind
21
21
 
22
22
  jpeg = JPEG.new(@io)
23
- jpeg.height.should == 72
24
- jpeg.width.should == 72
23
+ jpeg.height.should == 64
24
+ jpeg.width.should == 64
25
25
  end
26
26
 
27
27
  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.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-21 00:00:00.000000000 Z
12
+ date: 2012-08-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -79,6 +79,7 @@ files:
79
79
  - lib/dropbox-api/client/raw.rb
80
80
  - lib/dropbox-api/connection.rb
81
81
  - lib/dropbox-api/connection/requests.rb
82
+ - lib/dropbox-api/objects/delta.rb
82
83
  - lib/dropbox-api/objects/dir.rb
83
84
  - lib/dropbox-api/objects/file.rb
84
85
  - lib/dropbox-api/objects/fileops.rb