dropbox-sdk 1.2 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/lib/dropbox_sdk.rb +117 -17
- metadata +4 -4
data/CHANGELOG
CHANGED
data/lib/dropbox_sdk.rb
CHANGED
@@ -5,13 +5,13 @@ require 'cgi'
|
|
5
5
|
require 'json'
|
6
6
|
require 'yaml'
|
7
7
|
|
8
|
-
module Dropbox
|
8
|
+
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.
|
14
|
+
SDK_VERSION = "1.3"
|
15
15
|
|
16
16
|
TRUSTED_CERT_FILE = File.join(File.dirname(__FILE__), 'trusted-certs.crt')
|
17
17
|
end
|
@@ -125,6 +125,7 @@ class DropboxSession
|
|
125
125
|
raise DropboxAuthError.new("#{error_message_prefix} Server returned #{response.code}: #{response.message}.", response)
|
126
126
|
end
|
127
127
|
parts = CGI.parse(response.body)
|
128
|
+
|
128
129
|
if !parts.has_key? "oauth_token" and parts["oauth_token"].length != 1
|
129
130
|
raise DropboxAuthError.new("Invalid response from #{url_end}: missing \"oauth_token\" parameter: #{response.body}", response)
|
130
131
|
end
|
@@ -244,7 +245,7 @@ end
|
|
244
245
|
|
245
246
|
|
246
247
|
# A class that represents either an OAuth request token or an OAuth access token.
|
247
|
-
class OAuthToken
|
248
|
+
class OAuthToken # :nodoc:
|
248
249
|
def initialize(key, secret)
|
249
250
|
@key = key
|
250
251
|
@secret = secret
|
@@ -339,14 +340,14 @@ class DropboxClient
|
|
339
340
|
begin
|
340
341
|
return JSON.parse(response.body)
|
341
342
|
rescue JSON::ParserError
|
342
|
-
raise DropboxError.new("Unable to parse JSON response", response)
|
343
|
+
raise DropboxError.new("Unable to parse JSON response: #{response.body}", response)
|
343
344
|
end
|
344
345
|
end
|
345
346
|
|
346
347
|
# Returns account info in a Hash object
|
347
348
|
#
|
348
349
|
# For a detailed description of what this call returns, visit:
|
349
|
-
# https://www.dropbox.com/developers/
|
350
|
+
# https://www.dropbox.com/developers/reference/api#account-info
|
350
351
|
def account_info()
|
351
352
|
response = @session.do_get build_url("/account/info")
|
352
353
|
parse_response(response)
|
@@ -478,7 +479,7 @@ class DropboxClient
|
|
478
479
|
# Returns:
|
479
480
|
# * A hash with the metadata of the new copy of the file or folder.
|
480
481
|
# For a detailed description of what this call returns, visit:
|
481
|
-
# https://www.dropbox.com/developers/
|
482
|
+
# https://www.dropbox.com/developers/reference/api#fileops-copy
|
482
483
|
def file_copy(from_path, to_path)
|
483
484
|
params = {
|
484
485
|
"root" => @root,
|
@@ -497,7 +498,7 @@ class DropboxClient
|
|
497
498
|
# Returns:
|
498
499
|
# * A hash with the metadata of the newly created folder.
|
499
500
|
# For a detailed description of what this call returns, visit:
|
500
|
-
# https://www.dropbox.com/developers/
|
501
|
+
# https://www.dropbox.com/developers/reference/api#fileops-create-folder
|
501
502
|
def file_create_folder(path)
|
502
503
|
params = {
|
503
504
|
"root" => @root,
|
@@ -516,7 +517,7 @@ class DropboxClient
|
|
516
517
|
# Returns:
|
517
518
|
# * A Hash with the metadata of file just deleted.
|
518
519
|
# For a detailed description of what this call returns, visit:
|
519
|
-
# https://www.dropbox.com/developers/
|
520
|
+
# https://www.dropbox.com/developers/reference/api#fileops-delete
|
520
521
|
def file_delete(path)
|
521
522
|
params = {
|
522
523
|
"root" => @root,
|
@@ -536,7 +537,7 @@ class DropboxClient
|
|
536
537
|
# Returns:
|
537
538
|
# * A Hash with the metadata of file or folder just moved.
|
538
539
|
# For a detailed description of what this call returns, visit:
|
539
|
-
# https://www.dropbox.com/developers/
|
540
|
+
# https://www.dropbox.com/developers/reference/api#fileops-delete
|
540
541
|
def file_move(from_path, to_path)
|
541
542
|
params = {
|
542
543
|
"root" => @root,
|
@@ -561,18 +562,24 @@ class DropboxClient
|
|
561
562
|
# can then be passed back into this function later to save on
|
562
563
|
# bandwidth. Rather than returning an unchanged folder's contents, if
|
563
564
|
# the hash matches a DropboxNotModified exception is raised.
|
565
|
+
# * rev: Optional. The revision of the file to retrieve the metadata for.
|
566
|
+
# This parameter only applies for files. If omitted, you'll receive
|
567
|
+
# the most recent revision metadata.
|
568
|
+
# * include_deleted: Specifies whether to include deleted files in metadata results.
|
564
569
|
#
|
565
570
|
# Returns:
|
566
571
|
# * A Hash object with the metadata of the file or folder (and contained files if
|
567
572
|
# appropriate). For a detailed description of what this call returns, visit:
|
568
|
-
# https://www.dropbox.com/developers/
|
569
|
-
def metadata(path, file_limit=10000, list=true, hash=nil)
|
573
|
+
# https://www.dropbox.com/developers/reference/api#metadata
|
574
|
+
def metadata(path, file_limit=10000, list=true, hash=nil, rev=nil, include_deleted=false)
|
570
575
|
params = {
|
571
576
|
"file_limit" => file_limit.to_s,
|
572
|
-
"list" => list.to_s
|
577
|
+
"list" => list.to_s,
|
578
|
+
"include_deleted" => include_deleted.to_s
|
573
579
|
}
|
574
580
|
|
575
581
|
params["hash"] = hash if hash
|
582
|
+
params["rev"] = rev if rev
|
576
583
|
|
577
584
|
response = @session.do_get build_url("/metadata/#{@root}#{format_path(path)}", params=params)
|
578
585
|
if response.kind_of? Net::HTTPRedirection
|
@@ -594,7 +601,7 @@ class DropboxClient
|
|
594
601
|
# Returns:
|
595
602
|
# * A Hash object with a list the metadata of the file or folders matching query
|
596
603
|
# inside path. For a detailed description of what this call returns, visit:
|
597
|
-
# https://www.dropbox.com/developers/
|
604
|
+
# https://www.dropbox.com/developers/reference/api#search
|
598
605
|
def search(path, query, file_limit=1000, include_deleted=false)
|
599
606
|
params = {
|
600
607
|
'query' => query,
|
@@ -618,7 +625,7 @@ class DropboxClient
|
|
618
625
|
# * A Hash object with a list of the metadata of the all the revisions of
|
619
626
|
# all matches files (up to rev_limit entries)
|
620
627
|
# For a detailed description of what this call returns, visit:
|
621
|
-
# https://www.dropbox.com/developers/
|
628
|
+
# https://www.dropbox.com/developers/reference/api#revisions
|
622
629
|
def revisions(path, rev_limit=1000)
|
623
630
|
|
624
631
|
params = {
|
@@ -639,7 +646,7 @@ class DropboxClient
|
|
639
646
|
# Returns:
|
640
647
|
# * A Hash object with a list the metadata of the file or folders restored
|
641
648
|
# For a detailed description of what this call returns, visit:
|
642
|
-
# https://www.dropbox.com/developers/
|
649
|
+
# https://www.dropbox.com/developers/reference/api#search
|
643
650
|
def restore(path, rev)
|
644
651
|
params = {
|
645
652
|
'rev' => rev.to_s
|
@@ -679,7 +686,7 @@ class DropboxClient
|
|
679
686
|
# * A Hash object that looks like the following example:
|
680
687
|
# {'url': 'http://www.dropbox.com/s/m/a2mbDa2', 'expires': 'Thu, 16 Sep 2011 01:01:25 +0000'}
|
681
688
|
# For a detailed description of what this call returns, visit:
|
682
|
-
# https://www.dropbox.com/developers/
|
689
|
+
# https://www.dropbox.com/developers/reference/api#shares
|
683
690
|
def shares(path)
|
684
691
|
response = @session.do_get build_url("/shares/#{@root}#{format_path(path)}")
|
685
692
|
parse_response(response)
|
@@ -692,7 +699,7 @@ class DropboxClient
|
|
692
699
|
# * size: A string describing the desired thumbnail size. At this time,
|
693
700
|
# 'small', 'medium', and 'large' are officially supported sizes
|
694
701
|
# (32x32, 64x64, and 128x128 respectively), though others may
|
695
|
-
# be available. Check https://www.dropbox.com/developers/
|
702
|
+
# be available. Check https://www.dropbox.com/developers/reference/api#thumbnails
|
696
703
|
# for more details. [defaults to large]
|
697
704
|
# Returns:
|
698
705
|
# * The thumbnail data
|
@@ -717,6 +724,60 @@ class DropboxClient
|
|
717
724
|
return parsed_response, metadata
|
718
725
|
end
|
719
726
|
|
727
|
+
# A way of letting you keep a local representation of the Dropbox folder
|
728
|
+
# heirarchy. You can periodically call delta() to get a list of "delta
|
729
|
+
# entries", which are instructions on how to update your local state to
|
730
|
+
# match the server's state.
|
731
|
+
#
|
732
|
+
# Arguments:
|
733
|
+
# * +cursor+: On the first call, omit this argument (or pass in +nil+). On
|
734
|
+
# subsequent calls, pass in the +cursor+ string returned by the previous
|
735
|
+
# call.
|
736
|
+
#
|
737
|
+
# Returns: A hash with three fields.
|
738
|
+
# * +entries+: A list of "delta entries" (described below)
|
739
|
+
# * +reset+: If +true+, you should reset local state to be an empty folder
|
740
|
+
# before processing the list of delta entries. This is only +true+ only
|
741
|
+
# in rare situations.
|
742
|
+
# * +cursor+: A string that is used to keep track of your current state.
|
743
|
+
# On the next call to delta(), pass in this value to return entries
|
744
|
+
# that were recorded since the cursor was returned.
|
745
|
+
# * +has_more+: If +true+, then there are more entries available; you can
|
746
|
+
# call delta() again immediately to retrieve those entries. If +false+,
|
747
|
+
# then wait at least 5 minutes (preferably longer) before checking again.
|
748
|
+
#
|
749
|
+
# Delta Entries: Each entry is a 2-item list of one of following forms:
|
750
|
+
# * [_path_, _metadata_]: Indicates that there is a file/folder at the given
|
751
|
+
# path. You should add the entry to your local state. (The _metadata_
|
752
|
+
# value is the same as what would be returned by the #metadata() call.)
|
753
|
+
# * If the path refers to parent folders that don't yet exist in your
|
754
|
+
# local state, create those parent folders in your local state. You
|
755
|
+
# will eventually get entries for those parent folders.
|
756
|
+
# * If the new entry is a file, replace whatever your local state has at
|
757
|
+
# _path_ with the new entry.
|
758
|
+
# * If the new entry is a folder, check what your local state has at
|
759
|
+
# _path_. If it's a file, replace it with the new entry. If it's a
|
760
|
+
# folder, apply the new _metadata_ to the folder, but do not modify
|
761
|
+
# the folder's children.
|
762
|
+
# * [path, +nil+]: Indicates that there is no file/folder at the _path_ on
|
763
|
+
# Dropbox. To update your local state to match, delete whatever is at
|
764
|
+
# _path_, including any children (you will sometimes also get separate
|
765
|
+
# delta entries for each child, but this is not guaranteed). If your
|
766
|
+
# local state doesn't have anything at _path_, ignore this entry.
|
767
|
+
#
|
768
|
+
# Remember: Dropbox treats file names in a case-insensitive but case-preserving
|
769
|
+
# way. To facilitate this, the _path_ strings above are lower-cased versions of
|
770
|
+
# the actual path. The _metadata_ dicts have the original, case-preserved path.
|
771
|
+
def delta(cursor=nil)
|
772
|
+
params = {}
|
773
|
+
if cursor
|
774
|
+
params['cursor'] = cursor
|
775
|
+
end
|
776
|
+
|
777
|
+
response = @session.do_post build_url("/delta", params)
|
778
|
+
parse_response(response)
|
779
|
+
end
|
780
|
+
|
720
781
|
# Download a thumbnail (helper method - don't call this directly).
|
721
782
|
#
|
722
783
|
# Args:
|
@@ -741,6 +802,45 @@ class DropboxClient
|
|
741
802
|
end
|
742
803
|
private :thumbnail_impl
|
743
804
|
|
805
|
+
|
806
|
+
# Creates and returns a copy ref for a specific file. The copy ref can be
|
807
|
+
# used to instantly copy that file to the Dropbox of another account.
|
808
|
+
#
|
809
|
+
# Args:
|
810
|
+
# * path: The path to the file for a copy ref to be created on.
|
811
|
+
#
|
812
|
+
# Returns:
|
813
|
+
# * A Hash object that looks like the following example:
|
814
|
+
# {"expires"=>"Fri, 31 Jan 2042 21:01:05 +0000", "copy_ref"=>"z1X6ATl6aWtzOGq0c3g5Ng"}
|
815
|
+
def create_copy_ref(path)
|
816
|
+
path = "/copy_ref/#{@root}#{format_path(path)}"
|
817
|
+
|
818
|
+
response = @session.do_get(build_url(path, {}))
|
819
|
+
|
820
|
+
parse_response(response)
|
821
|
+
end
|
822
|
+
|
823
|
+
# Adds the file referenced by the copy ref to the specified path
|
824
|
+
#
|
825
|
+
# Args:
|
826
|
+
# * copy_ref: A copy ref string that was returned from a create_copy_ref call.
|
827
|
+
# The copy_ref can be created from any other Dropbox account, or from the same account.
|
828
|
+
# * to_path: The path to where the file will be created.
|
829
|
+
#
|
830
|
+
# Returns:
|
831
|
+
# * A hash with the metadata of the new file.
|
832
|
+
def add_copy_ref(to_path, copy_ref)
|
833
|
+
path = "/fileops/copy"
|
834
|
+
|
835
|
+
params = {'from_copy_ref' => copy_ref,
|
836
|
+
'to_path' => "#{format_path(to_path)}",
|
837
|
+
'root' => @root}
|
838
|
+
|
839
|
+
response = @session.do_post(build_url(path, params))
|
840
|
+
|
841
|
+
parse_response(response)
|
842
|
+
end
|
843
|
+
|
744
844
|
def build_url(url, params=nil, content_server=false) # :nodoc:
|
745
845
|
port = 443
|
746
846
|
host = content_server ? Dropbox::API_CONTENT_SERVER : Dropbox::API_SERVER
|
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.
|
4
|
+
version: '1.3'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-27 00:00:00.000000000 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
17
|
-
requirement: &
|
17
|
+
requirement: &2156604720 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2156604720
|
26
26
|
description: ! " A library that provides a plain function-call interface to
|
27
27
|
the\n Dropbox API web endpoints.\n"
|
28
28
|
email:
|