dropbox-sdk 1.3 → 1.5.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.
Files changed (4) hide show
  1. data/CHANGELOG +10 -0
  2. data/cli_example.rb +0 -0
  3. data/lib/dropbox_sdk.rb +112 -13
  4. metadata +10 -7
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ 1.5.1 (2012-8-20)
2
+ * Fixed packaging.
3
+
4
+ 1.5 (2012-8-15)
5
+ * Support for uploading large files via /chunked_upload
6
+
7
+ 1.3.1 (2012-5-16)
8
+ * Increase metadata() file list limit to 25,000 (used to be 10,000).
9
+ * Use CGI.escape() instead of the deprecated URI.escape().
10
+
1
11
  1.3 (2012-3-26)
2
12
  * Add support for the /delta API.
3
13
  * Add support for the "copy ref" API.
File without changes
@@ -9,9 +9,9 @@ module Dropbox # :nodoc:
9
9
  API_SERVER = "api.dropbox.com"
10
10
  API_CONTENT_SERVER = "api-content.dropbox.com"
11
11
  WEB_SERVER = "www.dropbox.com"
12
-
12
+
13
13
  API_VERSION = 1
14
- SDK_VERSION = "1.3"
14
+ SDK_VERSION = "1.5.1"
15
15
 
16
16
  TRUSTED_CERT_FILE = File.join(File.dirname(__FILE__), 'trusted-certs.crt')
17
17
  end
@@ -401,6 +401,107 @@ class DropboxClient
401
401
  parse_response(response)
402
402
  end
403
403
 
404
+ # Returns a ChunkedUploader object.
405
+ #
406
+ # Args:
407
+ # * file_obj: The file-like object to be uploaded. Must support .read()
408
+ # * total_size: The total size of file_obj
409
+ def get_chunked_uploader(file_obj, total_size)
410
+ ChunkedUploader.new(self, file_obj, total_size)
411
+ end
412
+
413
+ # ChunkedUploader is responsible for uploading a large file to Dropbox in smaller chunks.
414
+ # This allows large files to be uploaded and makes allows recovery during failure.
415
+ class ChunkedUploader
416
+ attr_accessor :file_obj, :total_size, :offset, :upload_id, :client
417
+
418
+ def initialize(client, file_obj, total_size)
419
+ @client = client
420
+ @file_obj = file_obj
421
+ @total_size = total_size
422
+ @upload_id = nil
423
+ @offset = 0
424
+ end
425
+
426
+ # Uploads data from this ChunkedUploader's file_obj in chunks, until
427
+ # an error occurs. Throws an exception when an error occurs, and can
428
+ # be called again to resume the upload.
429
+ #
430
+ # Args:
431
+ # * chunk_size: The chunk size for each individual upload. Defaults to 4MB.
432
+ def upload(chunk_size=4*1024*1024)
433
+ last_chunk = nil
434
+
435
+ while @offset < @total_size
436
+ if not last_chunk
437
+ last_chunk = @file_obj.read(chunk_size)
438
+ end
439
+
440
+ resp = {}
441
+ begin
442
+ resp = @client.parse_response(@client.partial_chunked_upload(last_chunk, @upload_id, @offset))
443
+ last_chunk = nil
444
+ rescue DropboxError => e
445
+ resp = JSON.parse(e.http_response.body)
446
+ raise unless resp.has_key? 'offset'
447
+ end
448
+
449
+ if resp.has_key? 'offset' and resp['offset'] > @offset
450
+ @offset += (resp['offset'] - @offset) if resp['offset']
451
+ last_chunk = nil
452
+ end
453
+ @upload_id = resp['upload_id'] if resp['upload_id']
454
+ end
455
+ end
456
+
457
+ # Completes a file upload
458
+ #
459
+ # Args:
460
+ # * to_path: The directory path to upload the file to. If the destination
461
+ # directory does not yet exist, it will be created.
462
+ # * overwrite: Whether to overwrite an existing file at the given path. [default is False]
463
+ # If overwrite is False and a file already exists there, Dropbox
464
+ # will rename the upload to make sure it doesn't overwrite anything.
465
+ # You must check the returned metadata to know what this new name is.
466
+ # This field should only be True if your intent is to potentially
467
+ # clobber changes to a file that you don't know about.
468
+ # * parent_rev: The rev field from the 'parent' of this upload.
469
+ # If your intent is to update the file at the given path, you should
470
+ # pass the parent_rev parameter set to the rev value from the most recent
471
+ # metadata you have of the existing file at that path. If the server
472
+ # has a more recent version of the file at the specified path, it will
473
+ # automatically rename your uploaded file, spinning off a conflict.
474
+ # Using this parameter effectively causes the overwrite parameter to be ignored.
475
+ # The file will always be overwritten if you send the most-recent parent_rev,
476
+ # and it will never be overwritten you send a less-recent one.
477
+ #
478
+ # Returns:
479
+ # * A Hash with the metadata of file just uploaded.
480
+ # For a detailed description of what this call returns, visit:
481
+ # https://www.dropbox.com/developers/reference/api#metadata
482
+ def finish(to_path, overwrite=false, parent_rev=nil)
483
+ response = @client.commit_chunked_upload(to_path, @upload_id, overwrite, parent_rev)
484
+ @client.parse_response(response)
485
+ end
486
+ end
487
+
488
+ def commit_chunked_upload(to_path, upload_id, overwrite=false, parent_rev=nil) #:nodoc
489
+ params = {'overwrite' => overwrite.to_s,
490
+ 'upload_id' => upload_id,
491
+ 'parent_rev' => parent_rev.to_s,
492
+ }
493
+ @session.do_post(build_url("/commit_chunked_upload/#{@root}#{format_path(to_path)}", params, content_server=true))
494
+ end
495
+
496
+ def partial_chunked_upload(data, upload_id=nil, offset=nil) #:nodoc
497
+ params = {}
498
+ params['upload_id'] = upload_id.to_s if upload_id
499
+ params['offset'] = offset.to_s if offset
500
+ @session.do_put(build_url('/chunked_upload', params, content_server=true),
501
+ {'Content-Type' => "application/octet-stream"},
502
+ data)
503
+ end
504
+
404
505
  # Download a file
405
506
  #
406
507
  # Args:
@@ -557,7 +658,7 @@ class DropboxClient
557
658
  # * file_limit: The maximum number of file entries to return within
558
659
  # a folder. If the number of files in the directory exceeds this
559
660
  # limit, an exception is raised. The server will return at max
560
- # 10,000 files within a folder.
661
+ # 25,000 files within a folder.
561
662
  # * hash: Every directory listing has a hash parameter attached that
562
663
  # can then be passed back into this function later to save on
563
664
  # bandwidth. Rather than returning an unchanged folder's contents, if
@@ -571,7 +672,7 @@ class DropboxClient
571
672
  # * A Hash object with the metadata of the file or folder (and contained files if
572
673
  # appropriate). For a detailed description of what this call returns, visit:
573
674
  # https://www.dropbox.com/developers/reference/api#metadata
574
- def metadata(path, file_limit=10000, list=true, hash=nil, rev=nil, include_deleted=false)
675
+ def metadata(path, file_limit=25000, list=true, hash=nil, rev=nil, include_deleted=false)
575
676
  params = {
576
677
  "file_limit" => file_limit.to_s,
577
678
  "list" => list.to_s,
@@ -697,9 +798,9 @@ class DropboxClient
697
798
  # Arguments:
698
799
  # * from_path: The path to the file to be thumbnailed.
699
800
  # * size: A string describing the desired thumbnail size. At this time,
700
- # 'small', 'medium', and 'large' are officially supported sizes
701
- # (32x32, 64x64, and 128x128 respectively), though others may
702
- # be available. Check https://www.dropbox.com/developers/reference/api#thumbnails
801
+ # 'small' (32x32), 'medium' (64x64), 'large' (128x128), 's' (64x64),
802
+ # 'm' (128x128), 'l' (640x640), and 'xl' (1024x1024) are officially supported sizes.
803
+ # Check https://www.dropbox.com/developers/reference/api#thumbnails
703
804
  # for more details. [defaults to large]
704
805
  # Returns:
705
806
  # * The thumbnail data
@@ -708,7 +809,7 @@ class DropboxClient
708
809
  parse_response(response, raw=true)
709
810
  end
710
811
 
711
- # Download a thumbnail for an image alongwith the image's metadata.
812
+ # Download a thumbnail for an image along with the image's metadata.
712
813
  #
713
814
  # Arguments:
714
815
  # * from_path: The path to the file to be thumbnailed.
@@ -788,9 +889,7 @@ class DropboxClient
788
889
  # Returns:
789
890
  # * The HTTPResponse for the thumbnail request.
790
891
  def thumbnail_impl(from_path, size='large') # :nodoc:
791
- from_path = format_path(from_path, false)
792
-
793
- raise DropboxError.new("size must be small medium or large. (not '#{size})") unless ['small','medium','large'].include?(size)
892
+ from_path = format_path(from_path, true)
794
893
 
795
894
  params = {
796
895
  "size" => size
@@ -833,7 +932,7 @@ class DropboxClient
833
932
  path = "/fileops/copy"
834
933
 
835
934
  params = {'from_copy_ref' => copy_ref,
836
- 'to_path' => "#{format_path(to_path)}",
935
+ 'to_path' => "#{to_path}",
837
936
  'root' => @root}
838
937
 
839
938
  response = @session.do_post(build_url(path, params))
@@ -856,7 +955,7 @@ class DropboxClient
856
955
 
857
956
  if params
858
957
  target.query = params.collect {|k,v|
859
- URI.escape(k) + "=" + URI.escape(v)
958
+ CGI.escape(k) + "=" + CGI.escape(v)
860
959
  }.join("&")
861
960
  end
862
961
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropbox-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.3'
4
+ version: 1.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-27 00:00:00.000000000 -07:00
13
- default_executable:
12
+ date: 2012-09-06 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: json
17
- requirement: &2156604720 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,7 +21,12 @@ dependencies:
22
21
  version: '0'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2156604720
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
26
30
  description: ! " A library that provides a plain function-call interface to
27
31
  the\n Dropbox API web endpoints.\n"
28
32
  email:
@@ -39,7 +43,6 @@ files:
39
43
  - web_file_browser.rb
40
44
  - lib/dropbox_sdk.rb
41
45
  - lib/trusted-certs.crt
42
- has_rdoc: true
43
46
  homepage: http://www.dropbox.com/developers/
44
47
  licenses:
45
48
  - MIT
@@ -61,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
64
  version: '0'
62
65
  requirements: []
63
66
  rubyforge_project:
64
- rubygems_version: 1.6.2
67
+ rubygems_version: 1.8.24
65
68
  signing_key:
66
69
  specification_version: 3
67
70
  summary: Dropbox REST API Client.