dropbox_api 0.1.3 β†’ 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/TODO.md +12 -12
  3. data/api_coverage.md +6 -6
  4. data/lib/dropbox_api.rb +12 -1
  5. data/lib/dropbox_api/authenticator.rb +2 -2
  6. data/lib/dropbox_api/endpoints/files/move.rb +15 -3
  7. data/lib/dropbox_api/endpoints/files/save_url.rb +23 -0
  8. data/lib/dropbox_api/endpoints/files/save_url_check_job_status.rb +20 -0
  9. data/lib/dropbox_api/endpoints/files/upload.rb +44 -9
  10. data/lib/dropbox_api/endpoints/options_validator.rb +5 -0
  11. data/lib/dropbox_api/endpoints/sharing/add_file_member.rb +11 -9
  12. data/lib/dropbox_api/endpoints/sharing/add_folder_member.rb +14 -6
  13. data/lib/dropbox_api/endpoints/sharing/list_folder_members.rb +5 -6
  14. data/lib/dropbox_api/errors/add_file_member_error.rb +4 -0
  15. data/lib/dropbox_api/errors/basic_error.rb +4 -0
  16. data/lib/dropbox_api/errors/poll_error.rb +8 -0
  17. data/lib/dropbox_api/errors/save_url_error.rb +10 -0
  18. data/lib/dropbox_api/errors/sharing_user_error.rb +7 -0
  19. data/lib/dropbox_api/metadata/access_level.rb +10 -10
  20. data/lib/dropbox_api/metadata/add_member.rb +1 -1
  21. data/lib/dropbox_api/metadata/base.rb +1 -1
  22. data/lib/dropbox_api/metadata/member.rb +32 -23
  23. data/lib/dropbox_api/metadata/member_action.rb +31 -0
  24. data/lib/dropbox_api/metadata/member_action_list.rb +13 -0
  25. data/lib/dropbox_api/metadata/member_permission.rb +13 -1
  26. data/lib/dropbox_api/metadata/member_permission_list.rb +21 -0
  27. data/lib/dropbox_api/metadata/symbol.rb +24 -0
  28. data/lib/dropbox_api/metadata/write_mode.rb +74 -0
  29. data/lib/dropbox_api/results/save_url_job_status.rb +17 -0
  30. data/lib/dropbox_api/results/save_url_result.rb +14 -0
  31. data/lib/dropbox_api/results/share_folder_launch.rb +1 -1
  32. data/lib/dropbox_api/version.rb +1 -1
  33. metadata +13 -3
  34. data/lib/dropbox_api/metadata/member_action_collection.rb +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd04df06e2b79e0a102c34ada12761d414d92484
4
- data.tar.gz: 2d71c761e4b9c05e0207633d2b0d984f434ffd4e
3
+ metadata.gz: 71bc2fe09bb0680e07ef7267a199993f8aa93cc5
4
+ data.tar.gz: 31df4bc163d59790a448e37cb695617fe168d99d
5
5
  SHA512:
6
- metadata.gz: 7cfaf692c3c6625378951ddd42108e12d667477fb9468b5d1648e0891b7cb45cedd93fb7a06dd5e018625baf1955c330824dba14604569e323ceb0ea3aae5ba2
7
- data.tar.gz: 26d60eb6ddfb03c8e3c8b3219d0b1698c4360215b5edbdb39d096f8c7adffa131dbf1e470cb8be911ca58e3322b143d18939e360017e4f4eda6e1a9e170e5331
6
+ metadata.gz: e05027a2944af74b33f56a1a7a6a124459fd0a1c604ebd4ebaa5db3403eed396247aeea1344c69f8828b1172eac17ee32a3fcce60f3a8f280d30d02d4c95e1fa
7
+ data.tar.gz: 99c5f3c37144305dc4a689902e7c61468ef2991ddf4713c4354e4dee7076a83ea87434a5cc6d19122e2de6c0f21bb3a4b96144b60cb94c919a0d3ae7c895bc25
data/TODO.md CHANGED
@@ -1,15 +1,9 @@
1
- # Week
1
+ # Upcoming
2
2
 
3
- TOKEN: VofXAX8DO1sAAAAAAAADiXbd__inZjFI0OTsK9ao8AAKmshXqdbnjOnXz7XylBbf
3
+ TOKEN: VofXAX8DO1sAAAAAAAAEEyqrmzbYmFVaDQKj48yVUfhyhfOomXiG8emqP1xQGRnJ
4
4
 
5
- - add_file_member
6
- - Refactor MemberActionCollection
7
- - Implement DropboxApi::Metadata::Base#to_hash
8
-
9
- - get_file_metadata
10
- - get_folder_metadata
11
- - get_shared_link_file
12
- - get_shared_link_metadata
5
+ - Create website with comparison with other libraries.
6
+ - Implement PermissionDeniedReason
13
7
  - list_shared_folders
14
8
  - continue_list_shared_folders
15
9
  - share_folder
@@ -18,8 +12,12 @@ TOKEN: VofXAX8DO1sAAAAAAAADiXbd__inZjFI0OTsK9ao8AAKmshXqdbnjOnXz7XylBbf
18
12
  - list_folder_members
19
13
  - relinquish_folder_membership
20
14
  - transfer_folder
15
+ - get_file_metadata
16
+ - get_folder_metadata
17
+ - get_shared_link_file
18
+ - get_shared_link_metadata
21
19
 
22
- # Short term goals
20
+ # Mid-term goals
23
21
 
24
22
  - Remove dependency on faraday.
25
23
  - Complete full [API coverage](api_coverage.md).
@@ -35,4 +33,6 @@ TOKEN: VofXAX8DO1sAAAAAAAADiXbd__inZjFI0OTsK9ao8AAKmshXqdbnjOnXz7XylBbf
35
33
 
36
34
  1. Bump version in `version.rb`.
37
35
  2. Create tag and write release notes in Github.com.
38
- 3.
36
+ 3. `git fetch`
37
+ 4. `gem build dropbox_api.gemspec`
38
+ 5. `gem push dropbox_api-version.gem`
data/api_coverage.md CHANGED
@@ -36,11 +36,11 @@ API call | Status
36
36
  `/properties/template/get` | πŸŒ‘
37
37
  `/properties/template/list` | πŸŒ‘
38
38
  `/properties/update` | πŸŒ‘
39
- `/restore` | πŸŒ‘
40
- `/save_url` | πŸŒ‘
41
- `/save_url/check_job_status` | πŸŒ‘
42
- `/search` | πŸŒ•
43
- `/upload` | πŸŒ”
39
+ `/restore` | πŸŒ•
40
+ `/save_url` | πŸŒ•
41
+ `/save_url/check_job_status` | πŸŒ•
42
+ `/search` | πŸŒ”
43
+ `/upload` | πŸŒ•
44
44
  `/upload_session/append` | πŸŒ‘
45
45
  `/upload_session/append_v2` | πŸŒ‘
46
46
  `/upload_session/finish` | πŸŒ‘
@@ -51,7 +51,7 @@ API call | Status
51
51
  ## Sharing namespace
52
52
  API call | Status
53
53
  --- | :---:
54
- `/add_file_member` | πŸŒ”
54
+ `/add_file_member` | πŸŒ•
55
55
  `/add_folder_member` | πŸŒ•
56
56
  `/change_file_member_access` | πŸŒ‘
57
57
  `/check_job_status` | πŸŒ‘
data/lib/dropbox_api.rb CHANGED
@@ -11,18 +11,21 @@ require 'dropbox_api/middleware/decode_result'
11
11
  require 'dropbox_api/metadata/field'
12
12
  require 'dropbox_api/metadata/base'
13
13
 
14
+ require 'dropbox_api/metadata/symbol'
14
15
  require 'dropbox_api/metadata/access_level'
16
+ require 'dropbox_api/metadata/member_action'
17
+
15
18
  require 'dropbox_api/metadata/member'
16
19
  require 'dropbox_api/metadata/add_member'
17
20
  require 'dropbox_api/metadata/name'
18
21
  require 'dropbox_api/metadata/file_member_action'
22
+ require 'dropbox_api/metadata/member_action_list'
19
23
  require 'dropbox_api/metadata/member_permission'
20
24
  require 'dropbox_api/metadata/member_permission_list'
21
25
  require 'dropbox_api/metadata/add_file_member_result'
22
26
  require 'dropbox_api/metadata/parent_folder_access_info'
23
27
  require 'dropbox_api/metadata/basic_account'
24
28
  require 'dropbox_api/metadata/link_permissions'
25
- require 'dropbox_api/metadata/member_action_collection'
26
29
  require 'dropbox_api/metadata/team'
27
30
  require 'dropbox_api/metadata/team_member_info'
28
31
  require 'dropbox_api/metadata/file'
@@ -37,6 +40,7 @@ require 'dropbox_api/metadata/folder_link'
37
40
  require 'dropbox_api/metadata/shared_link'
38
41
  require 'dropbox_api/metadata/space_allocation'
39
42
  require 'dropbox_api/metadata/space_usage'
43
+ require 'dropbox_api/metadata/write_mode'
40
44
 
41
45
  require 'dropbox_api/errors/http_error'
42
46
  require 'dropbox_api/errors/basic_error'
@@ -46,6 +50,7 @@ require 'dropbox_api/errors/write_conflict_error'
46
50
  require 'dropbox_api/errors/write_error'
47
51
  require 'dropbox_api/errors/relocation_error'
48
52
  require 'dropbox_api/errors/restore_error'
53
+ require 'dropbox_api/errors/save_url_error'
49
54
  require 'dropbox_api/errors/search_error'
50
55
  require 'dropbox_api/errors/settings_error'
51
56
  require 'dropbox_api/errors/share_path_error'
@@ -55,6 +60,7 @@ require 'dropbox_api/errors/create_shared_link_with_settings_error'
55
60
  require 'dropbox_api/errors/delete_error'
56
61
  require 'dropbox_api/errors/download_error'
57
62
  require 'dropbox_api/errors/sharing_file_access_error'
63
+ require 'dropbox_api/errors/sharing_user_error'
58
64
  require 'dropbox_api/errors/file_member_action_error'
59
65
  require 'dropbox_api/errors/get_metadata_error'
60
66
  require 'dropbox_api/errors/list_folder_error'
@@ -67,6 +73,7 @@ require 'dropbox_api/errors/add_member_selector_error'
67
73
  require 'dropbox_api/errors/shared_folder_access_error'
68
74
  require 'dropbox_api/errors/upload_write_failed_error'
69
75
  require 'dropbox_api/errors/upload_error'
76
+ require 'dropbox_api/errors/poll_error'
70
77
  require 'dropbox_api/errors/add_file_member_error'
71
78
  require 'dropbox_api/errors/add_folder_member_error'
72
79
  require 'dropbox_api/errors/too_many_requests_error'
@@ -82,6 +89,8 @@ require 'dropbox_api/results/list_revisions_result'
82
89
  require 'dropbox_api/results/list_folder_longpoll_result'
83
90
  require 'dropbox_api/results/list_folder_get_latest_cursor_result'
84
91
  require 'dropbox_api/results/list_shared_links_result'
92
+ require 'dropbox_api/results/save_url_result'
93
+ require 'dropbox_api/results/save_url_job_status'
85
94
  require 'dropbox_api/results/search/match'
86
95
  require 'dropbox_api/results/search_result'
87
96
  require 'dropbox_api/results/share_folder_launch'
@@ -112,6 +121,8 @@ require 'dropbox_api/endpoints/files/list_folder_get_latest_cursor'
112
121
  require 'dropbox_api/endpoints/files/list_revisions'
113
122
  require 'dropbox_api/endpoints/files/move'
114
123
  require 'dropbox_api/endpoints/files/restore'
124
+ require 'dropbox_api/endpoints/files/save_url'
125
+ require 'dropbox_api/endpoints/files/save_url_check_job_status'
115
126
  require 'dropbox_api/endpoints/files/search'
116
127
  require 'dropbox_api/endpoints/files/upload'
117
128
  require 'dropbox_api/endpoints/sharing/add_file_member'
@@ -6,8 +6,8 @@ module DropboxApi
6
6
 
7
7
  def initialize(client_id, client_secret)
8
8
  @auth_code = OAuth2::Client.new(client_id, client_secret, {
9
- :authorize_url => 'https://www.dropbox.com/1/oauth2/authorize',
10
- :token_url => 'https://api.dropboxapi.com/1/oauth2/token'
9
+ :authorize_url => 'https://www.dropbox.com/oauth2/authorize',
10
+ :token_url => 'https://api.dropboxapi.com/oauth2/token'
11
11
  }).auth_code
12
12
  end
13
13
 
@@ -5,15 +5,27 @@ module DropboxApi::Endpoints::Files
5
5
  ResultType = DropboxApi::Metadata::Resource
6
6
  ErrorType = DropboxApi::Errors::RelocationError
7
7
 
8
- # @method move(from, to)
8
+ include DropboxApi::Endpoints::OptionsValidator
9
+
10
+ # @method move(from, to, options)
9
11
  # Move a file or folder to a different location in the user's Dropbox.
10
12
  #
11
13
  # If the source path is a folder all its contents will be moved.
12
14
  #
13
15
  # @param from [String] Path in the user's Dropbox to be copied or moved.
14
16
  # @param to [String] Path in the user's Dropbox that is the destination.
15
- add_endpoint :move do |from, to|
16
- perform_request({
17
+ # @option options autorename [Boolean] If there's a conflict, have the
18
+ # Dropbox server try to autorename the file to avoid the conflict. The
19
+ # default for this field is +false+.
20
+ add_endpoint :move do |from, to, options = {}|
21
+ # We're not implementing support for the `allow_shared_folder` option
22
+ # because according to Dropbox's documentation: "This field is always
23
+ # true for move".
24
+ validate_options([
25
+ :autorename
26
+ ], options)
27
+
28
+ perform_request options.merge({
17
29
  :from_path => from,
18
30
  :to_path => to
19
31
  })
@@ -0,0 +1,23 @@
1
+ module DropboxApi::Endpoints::Files
2
+ class SaveUrl < DropboxApi::Endpoints::Rpc
3
+ Method = :post
4
+ Path = "/2/files/save_url".freeze
5
+ ResultType = DropboxApi::Results::SaveUrlResult
6
+ ErrorType = DropboxApi::Errors::SaveUrlError
7
+
8
+ # @method save_url(path, url)
9
+ # Save a specified URL into a file in user's Dropbox. If the given path
10
+ # already exists, the file will be renamed to avoid the conflict (e.g.
11
+ # myfile (1).txt).
12
+ #
13
+ # @param path [String] The path in Dropbox where the URL will be saved to.
14
+ # @param url [String] The URL to be saved.
15
+ # @return Either the saved file or a reference to the async job.
16
+ add_endpoint :save_url do |path, url|
17
+ perform_request({
18
+ :path => path,
19
+ :url => url
20
+ })
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ module DropboxApi::Endpoints::Files
2
+ class SaveUrlCheckJobStatus < DropboxApi::Endpoints::Rpc
3
+ Method = :post
4
+ Path = "/2/files/save_url/check_job_status".freeze
5
+ ResultType = DropboxApi::Results::SaveUrlJobStatus
6
+ ErrorType = DropboxApi::Errors::PollError
7
+
8
+ # @method save_url_check_job_status(job_id)
9
+ # Check the status of a +save_url+ job.
10
+ #
11
+ # @param job_id [String] Id of the asynchronous job. This is the value of
12
+ # a response returned from the method that launched the job.
13
+ # @return The current status of the job.
14
+ add_endpoint :save_url_check_job_status do |job_id|
15
+ perform_request({
16
+ :async_job_id => job_id
17
+ })
18
+ end
19
+ end
20
+ end
@@ -5,6 +5,8 @@ module DropboxApi::Endpoints::Files
5
5
  ResultType = DropboxApi::Metadata::File
6
6
  ErrorType = DropboxApi::Errors::UploadError
7
7
 
8
+ include DropboxApi::Endpoints::OptionsValidator
9
+
8
10
  # @method upload(path, content, options = {})
9
11
  # Creates a new file.
10
12
  #
@@ -20,19 +22,52 @@ module DropboxApi::Endpoints::Files
20
22
  # client = DropboxApi::Client.new
21
23
  # client.upload "/file.txt", "Contents of a plain text file."
22
24
  # #=> #<DropboxApi::Metadata::File: @name="file.txt" ...>
25
+ # @example
26
+ # client = DropboxApi::Client.new
27
+ # client.upload "/file.txt", "File contents...", :mode => :add
28
+ # #=> #<DropboxApi::Metadata::File: @name="file (1).txt" ...>
23
29
  # @param path [String] Path in the user's Dropbox to save the file.
24
30
  # @param content The contents of the file that will be uploaded. This
25
31
  # could be the result of the +IO::read+ method.
26
- # @option options autorename [Boolean] If there's a conflict, as
27
- # determined by mode, have the Dropbox server try to autorename the
28
- # file to avoid conflict. The default for this field is False.
29
- # @option options mute [Boolean] Normally, users are made aware of any file
30
- # modifications in their Dropbox account via notifications in the client
31
- # software. If true, this tells the clients that this modification
32
- # shouldn't result in a user notification. The default for this field is
33
- # `false`.
32
+ # @option options mode [DropboxApi::Metadata::WriteMode] Selects what to
33
+ # do if the file already exists. The default is +add+.
34
+ # @option options autorename [Boolean] If there's a conflict, as determined
35
+ # by +mode+, have the Dropbox server try to autorename the file to avoid
36
+ # conflict. The default for this field is +false+.
37
+ # @option options client_modified [DateTime] The value to store as the
38
+ # +client_modified+ timestamp. Dropbox automatically records the time at
39
+ # which the file was written to the Dropbox servers. It can also record
40
+ # an additional timestamp, provided by Dropbox desktop clients, mobile
41
+ # clients, and API apps of when the file was actually created or
42
+ # modified.
43
+ # @see DropboxApi::Metadata::WriteMode
34
44
  add_endpoint :upload do |path, content, options = {}|
35
- perform_request({:path => path}, content)
45
+ validate_options([
46
+ :mode,
47
+ :autorename,
48
+ :client_modified,
49
+ :mute
50
+ ], options)
51
+
52
+ options[:mode] = build_write_mode_param(options[:mode]) if options[:mode]
53
+ options[:client_modified] = options[:client_modified].utc.strftime("%FT%TZ") if options[:client_modified]
54
+
55
+ perform_request(options.merge({
56
+ :path => path
57
+ }), content)
58
+ end
59
+
60
+ private
61
+
62
+ def build_write_mode_param(write_mode)
63
+ case write_mode
64
+ when String, Symbol
65
+ DropboxApi::Metadata::WriteMode.new write_mode
66
+ when DropboxApi::Metadata::WriteMode
67
+ write_mode
68
+ else
69
+ raise ArgumentError, "Invalid write mode: #{write_mode.inspect}"
70
+ end.to_hash
36
71
  end
37
72
  end
38
73
  end
@@ -1,5 +1,10 @@
1
1
  module DropboxApi::Endpoints
2
2
  module OptionsValidator
3
+ # Takes in a list of valid option keys and a hash of options. If one of the
4
+ # keys in the hash is invalid an ArgumentError will be raised.
5
+ #
6
+ # @param valid_option_keys List of valid keys for the options hash.
7
+ # @param options [Hash] Options hash.
3
8
  def validate_options(valid_option_keys, options)
4
9
  options.keys.each do |key|
5
10
  unless valid_option_keys.include? key.to_sym
@@ -10,15 +10,16 @@ module DropboxApi::Endpoints::Sharing
10
10
  # @method add_file_member(file, members, options = {})
11
11
  # Adds specified members to a file.
12
12
  #
13
- # The +members+ parameter must be an Array. Each item in the array could
14
- # be either a String or a {Metadata::Member} object, which allows more
15
- # advanced options.
13
+ # The +members+ parameter can be an +Array+ or a single member element. Each
14
+ # element is represented by either a +String+ or a {Metadata::Member}
15
+ # object. You can identify a member using his email or a Dropbox ID.
16
16
  #
17
17
  # @param file [String] File to which to add members. It can be a path or
18
18
  # an ID such as +id:3kmLmQFnf1AAAAAAAAAAAw+.
19
- # @param members [Array<Member,String>] Members to add. Note that even
20
- # an email address is given, this may result in a user being directy
21
- # added to the membership if that email is the user's main account email.
19
+ # @param members Members to add. Note
20
+ # that even if an email address is given, this may result in a user
21
+ # being directy added to the membership if that email is the user's
22
+ # main account email.
22
23
  # @option options quiet [Boolean] Whether added members should be notified
23
24
  # via email and device notifications of their invite. The default for
24
25
  # this field is +false+.
@@ -29,8 +30,9 @@ module DropboxApi::Endpoints::Sharing
29
30
  # for this is +:viewer+.
30
31
  # @option options add_message_as_comment [String] Optional message to
31
32
  # display to added members in their invitation. This field is optional.
33
+ # @see DropboxApi::Metadata::Member
32
34
  add_endpoint :add_file_member do |file, members, options = {}|
33
- validate_options([:quiet, :custom_message], options)
35
+ validate_options([:quiet, :custom_message, :access_level, :add_message_as_comment], options)
34
36
  options[:quiet] ||= false
35
37
  options[:custom_message] ||= nil
36
38
  options[:access_level] ||= :viewer
@@ -45,10 +47,10 @@ module DropboxApi::Endpoints::Sharing
45
47
  private
46
48
 
47
49
  def build_members_param(members)
48
- members.map do |member|
50
+ Array(members).map do |member|
49
51
  case member
50
52
  when String
51
- DropboxApi::Metadata::Member.build_from_email_or_dropbox_id member
53
+ DropboxApi::Metadata::Member.new member
52
54
  when DropboxApi::Metadata::Member
53
55
  member
54
56
  else
@@ -12,13 +12,21 @@ module DropboxApi::Endpoints::Sharing
12
12
  # folder to add another member.
13
13
  #
14
14
  # For the new member to get access to all the functionality for this folder,
15
- # you will need to call mount_folder on their behalf.
15
+ # you will need to call +mount_folder+ on their behalf.
16
16
  #
17
17
  # Apps must have full Dropbox access to use this endpoint.
18
18
  #
19
- # The +members+ parameter must be an Array. Each item in the array could
20
- # be either a String or a {Metadata::AddMember} object.
19
+ # The +members+ parameter can be an +Array+ or a single member element.
20
+ # Each element is represented by either a +String+ or a
21
+ # {Metadata::AddMember} object. This parameter can be just a string with
22
+ # an email.
21
23
  #
24
+ # You can also build a {Metadata::AddMember} object and use it in the
25
+ # +members+ parameter, this allows custom options for each member.
26
+ #
27
+ # @example
28
+ # client = DropboxApi::Client.new
29
+ # client.add_folder_member "1363389221", "somebody@test.com"
22
30
  # @param folder_id [String] The ID for the shared folder.
23
31
  # @param members [Array<AddMember,String>] The intended list of members to
24
32
  # add. Added members will receive invites to join the shared folder.
@@ -27,14 +35,14 @@ module DropboxApi::Endpoints::Sharing
27
35
  # this field is False.
28
36
  # @option options custom_message [String] Optional message to display to
29
37
  # added members in their invitation. This field is optional.
30
- # @see DropboxApi::Metadata::Member
38
+ # @see DropboxApi::Metadata::AddMember
31
39
  add_endpoint :add_folder_member do |folder_id, members, options = {}|
32
40
  validate_options([:quiet, :custom_message], options)
33
41
  options[:quiet] ||= false
34
42
  options[:custom_message] ||= nil
35
43
 
36
44
  perform_request options.merge({
37
- :shared_folder_id => folder_id,
45
+ :shared_folder_id => folder_id.to_s,
38
46
  :members => build_members_param(members)
39
47
  })
40
48
  end
@@ -42,7 +50,7 @@ module DropboxApi::Endpoints::Sharing
42
50
  private
43
51
 
44
52
  def build_members_param(members)
45
- members.map do |member|
53
+ Array(members).map do |member|
46
54
  case member
47
55
  when String
48
56
  DropboxApi::Metadata::AddMember.build_from_string member
@@ -22,19 +22,18 @@ module DropboxApi::Endpoints::Sharing
22
22
  # @param actions [Array]
23
23
  # This is an optional list of actions. The permissions for the actions
24
24
  # requested will be included in the result.
25
- # @option options
26
- # limit [Numeric] The maximum number of results that include
27
- # members, groups and invitees to return per request. The default for
28
- # this field is 1000.
25
+ # @option options limit [Numeric] The maximum number of results that
26
+ # include members, groups and invitees to return per request. The default
27
+ # for this field is 1000.
29
28
  # @return [SharedFolderMembers] Shared folder user and group membership.
30
- # @see DropboxApi::Metadata::MemberActionCollection
29
+ # @see Metadata::MemberActionList
31
30
  add_endpoint :list_folder_members do |folder_id, actions = [], options = {}|
32
31
  validate_options([:limit], options)
33
32
  options[:limit] ||= 100
34
33
 
35
34
  perform_request options.merge({
36
35
  :shared_folder_id => folder_id,
37
- :actions => DropboxApi::Metadata::MemberActionCollection.new(actions)
36
+ :actions => DropboxApi::Metadata::MemberActionList.new(actions)
38
37
  })
39
38
  end
40
39
  end
@@ -1,6 +1,10 @@
1
1
  module DropboxApi::Errors
2
2
  class AddFileMemberError < BasicError
3
3
  ErrorSubtypes = {
4
+ :user_error => SharingUserError,
5
+ :access_error => SharingFileAccessError,
6
+ :rate_limit => RateLimitError,
7
+ :invalid_comment => InvalidCommentError
4
8
  }.freeze
5
9
  end
6
10
  end
@@ -36,6 +36,7 @@ module DropboxApi::Errors
36
36
  class ContainsSharedFolderError < BasicError; end
37
37
  class DisallowedNameError < BasicError; end
38
38
  class DisallowedSharedLinkPolicyError < BasicError; end
39
+ class DownloadFailedError < BasicError; end
39
40
  class EmailUnverifiedError < BasicError; end
40
41
  class FileAncestorConflictError < BasicError; end
41
42
  class FileConflictError < BasicError; end
@@ -49,6 +50,8 @@ module DropboxApi::Errors
49
50
  class InsideSharedFolderError < BasicError; end
50
51
  class InsufficientPlanError < BasicError; end
51
52
  class InsufficientSpaceError < BasicError; end
53
+ class InternalError < BasicError; end
54
+ class InvalidCommentError < BasicError; end
52
55
  class InvalidCursorError < BasicError; end
53
56
  class InvalidDropboxIdError < BasicError; end
54
57
  class InvalidEmailError < BasicError; end
@@ -58,6 +61,7 @@ module DropboxApi::Errors
58
61
  class InvalidPathError < BasicError; end
59
62
  class InvalidRevisionError < BasicError; end
60
63
  class InvalidSettingsError < BasicError; end
64
+ class InvalidUrlError < BasicError; end
61
65
  class IsAppFolderError < BasicError; end
62
66
  class IsFileError < BasicError; end
63
67
  class IsFolderError < BasicError; end
@@ -0,0 +1,8 @@
1
+ module DropboxApi::Errors
2
+ class PollError < BasicError
3
+ ErrorSubtypes = {
4
+ :invalid_async_job_id => InvalidIdError,
5
+ :internal_error => InternalError
6
+ }.freeze
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ module DropboxApi::Errors
2
+ class SaveUrlError < BasicError
3
+ ErrorSubtypes = {
4
+ :path => WriteError,
5
+ :download_failed => DownloadFailedError,
6
+ :invalid_url => InvalidUrlError,
7
+ :not_found => NotFoundError
8
+ }.freeze
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module DropboxApi::Errors
2
+ class SharingUserError < BasicError
3
+ ErrorSubtypes = {
4
+ :email_unverified => EmailUnverifiedError
5
+ }.freeze
6
+ end
7
+ end
@@ -3,16 +3,16 @@ module DropboxApi::Metadata
3
3
  # {
4
4
  # ".tag": "viewer"
5
5
  # }
6
- class AccessLevel < Base
7
- def self.new(data)
8
- case data
9
- when Symbol
10
- data
11
- when Hash
12
- data[".tag"].to_sym
13
- else
14
- raise ArgumentError, "Invalid value for AccessLevel: #{data.inspect}."
15
- end
6
+ class AccessLevel < DropboxApi::Metadata::Symbol
7
+ VALID_ACCESS_LEVELS = [
8
+ :owner,
9
+ :editor,
10
+ :viewer,
11
+ :viewer_no_comment
12
+ ]
13
+
14
+ def self.valid_values
15
+ VALID_ACCESS_LEVELS
16
16
  end
17
17
  end
18
18
  end
@@ -22,7 +22,7 @@ module DropboxApi::Metadata
22
22
  class << self
23
23
  def build_from_string(member, access_level = :editor)
24
24
  new({
25
- "member" => Member.build_from_email_or_dropbox_id(member),
25
+ "member" => Member.new(member),
26
26
  "access_level" => access_level
27
27
  })
28
28
  end
@@ -47,7 +47,7 @@ module DropboxApi::Metadata
47
47
  case value
48
48
  when Time
49
49
  value.utc.strftime("%FT%TZ")
50
- when DropboxApi::Metadata
50
+ when DropboxApi::Metadata::Base
51
51
  value.to_hash
52
52
  else
53
53
  value
@@ -10,38 +10,47 @@ module DropboxApi::Metadata
10
10
  # }
11
11
  # ]
12
12
  class Member < Base
13
- class << self
14
- def build_from_email_or_dropbox_id(email_or_id)
15
- if email_or_id.start_with? "dbid:"
16
- build_from_dropbox_id email_or_id
17
- elsif email_or_id =~ /\A[^@\s]+@[^@\s]+\z/
18
- build_from_email email_or_id
13
+ def initialize(member)
14
+ @member_hash = case member
15
+ when Hash
16
+ member
17
+ when String
18
+ hash_from_email_or_dropbox_id member
19
+ when DropboxApi::Metadata::Member
20
+ member.to_hash
19
21
  else
20
- raise ArgumentError, "Invalid email or Dropbox ID: #{email_or_id}"
22
+ raise ArgumentError, "Invalid object for Member: #{member.inspect}"
21
23
  end
22
- end
24
+ end
23
25
 
24
- def build_from_dropbox_id(dropbox_id)
25
- new({
26
- :".tag" => :dropbox_id,
27
- :dropbox_id => dropbox_id
28
- })
29
- end
26
+ def to_hash
27
+ @member_hash
28
+ end
29
+
30
+ private
30
31
 
31
- def build_from_email(email)
32
- new({
33
- :".tag" => :email,
34
- :email => email
35
- })
32
+ def hash_from_email_or_dropbox_id(email_or_id)
33
+ if email_or_id.start_with? "dbid:"
34
+ hash_from_dropbox_id email_or_id
35
+ elsif email_or_id =~ /\A[^@\s]+@[^@\s]+\z/
36
+ hash_from_email email_or_id
37
+ else
38
+ raise ArgumentError, "Invalid email or Dropbox ID: #{email_or_id}"
36
39
  end
37
40
  end
38
41
 
39
- def initialize(member)
40
- @member = member
42
+ def hash_from_dropbox_id(dropbox_id)
43
+ {
44
+ :".tag" => :dropbox_id,
45
+ :dropbox_id => dropbox_id
46
+ }
41
47
  end
42
48
 
43
- def to_hash
44
- @member
49
+ def hash_from_email(email)
50
+ {
51
+ :".tag" => :email,
52
+ :email => email
53
+ }
45
54
  end
46
55
  end
47
56
  end
@@ -0,0 +1,31 @@
1
+ module DropboxApi::Metadata
2
+ # An action will be one of the following:
3
+ #
4
+ # - +:leave_a_copy+: Allow the member to keep a copy of the folder when
5
+ # removing.
6
+ # - +:make_editor+: Make the member an editor of the folder.
7
+ # - +:make_owner+: Make the member an owner of the folder.
8
+ # - +:make_viewer+: Make the member a viewer of the folder.
9
+ # - +:make_viewer_no_comment+: Make the member a viewer of the folder without
10
+ # commenting permissions.
11
+ # - +:remove+: Remove the member from the folder.
12
+ #
13
+ # Example of a serialized {MemberAction} object:
14
+ # {
15
+ # ".tag": "leave_a_copy"
16
+ # }
17
+ class MemberAction < DropboxApi::Metadata::Symbol
18
+ VALID_MEMBER_ACTIONS = [
19
+ :leave_a_copy,
20
+ :make_editor,
21
+ :make_owner,
22
+ :make_viewer,
23
+ :make_viewer_no_comment,
24
+ :remove
25
+ ]
26
+
27
+ def self.valid_values
28
+ VALID_MEMBER_ACTIONS
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ module DropboxApi::Metadata
2
+ class MemberActionList < Array
3
+ # Builds a list of actions for a shared folder.
4
+ #
5
+ # @example
6
+ # DropboxApi::Metadata::MemberActionList.new([:leave_a_copy, :make_editor])
7
+ # # => [:leave_a_copy, :make_editor]
8
+ # @see Metadata::MemberAction
9
+ def initialize(list)
10
+ super(list.map { |a| DropboxApi::Metadata::MemberAction.new a })
11
+ end
12
+ end
13
+ end
@@ -1,6 +1,18 @@
1
1
  module DropboxApi::Metadata
2
+ # This is an example of a serialized {MemberPermission}:
3
+ # {
4
+ # "action": {
5
+ # ".tag": "remove"
6
+ # },
7
+ # "allow": false,
8
+ # "reason": {
9
+ # ".tag": "target_is_self"
10
+ # }
11
+ # }
12
+ #
13
+ # This is normally contained in a {MemberPermissionList} object.
2
14
  class MemberPermission < Base
3
- field :action, String # This is actually a MemberAction object
15
+ field :action, DropboxApi::Metadata::MemberAction
4
16
  field :allow, :boolean
5
17
  field :reason, String # This is actually a PermissionDeniedReason object
6
18
  end
@@ -1,4 +1,25 @@
1
1
  module DropboxApi::Metadata
2
+ # This represents a collection of permissions on allowed on a
3
+ # shared file or folder.
4
+ #
5
+ # This is an example of a serialized {MemberActionList}:
6
+ # [{
7
+ # "action": {
8
+ # ".tag": "remove"
9
+ # },
10
+ # "allow": false,
11
+ # "reason": {
12
+ # ".tag": "target_is_self"
13
+ # }
14
+ # }, {
15
+ # "action": {
16
+ # ".tag": "make_owner"
17
+ # },
18
+ # "allow": false,
19
+ # "reason": {
20
+ # ".tag": "target_is_self"
21
+ # }
22
+ # }]
2
23
  class MemberPermissionList < Array
3
24
  def initialize(list)
4
25
  super(list.map { |i| DropboxApi::Metadata::MemberPermission.new i })
@@ -0,0 +1,24 @@
1
+ module DropboxApi::Metadata
2
+ class Symbol < DropboxApi::Metadata::Base
3
+ def self.new(data)
4
+ case data
5
+ when ::Symbol
6
+ validate(data)
7
+ when Hash
8
+ new(data[".tag"].to_sym)
9
+ when String
10
+ new(data.to_sym)
11
+ else
12
+ raise ArgumentError, "Invalid object for #{name}: #{data.inspect}."
13
+ end
14
+ end
15
+
16
+ def self.validate(value)
17
+ if valid_values.include? value
18
+ value
19
+ else
20
+ raise ArgumentError, "Invalid value for #{name}: #{value.inspect}"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,74 @@
1
+ module DropboxApi::Metadata
2
+ # Your intent when writing a file to some path. This is used to determine
3
+ # what constitutes a conflict and what the autorename strategy is.
4
+ #
5
+ # In some situations, the conflict behavior is identical:
6
+ #
7
+ # - If the target path doesn't contain anything, the file is always
8
+ # written; no conflict.
9
+ # - If the target path contains a folder, it's always a conflict.
10
+ # - If the target path contains a file with identical contents, nothing
11
+ # gets written; no conflict.
12
+ #
13
+ # The conflict checking differs in the case where there's a file at the
14
+ # target path with contents different from the contents you're trying to
15
+ # write. The value will be one of the following datatypes:
16
+ #
17
+ # - +:add+: Do not overwrite an existing file if there is a conflict. The
18
+ # autorename strategy is to append a number to the file name. For example,
19
+ # "document.txt" might become "document (2).txt".
20
+ # - +:overwrite+: Always overwrite the existing file. The autorename strategy
21
+ # is the same as it is for add.
22
+ # - +:update+: Overwrite if the given "rev" matches the existing file's
23
+ # "rev". The autorename strategy is to append the string "conflicted copy"
24
+ # to the file name. For example, "document.txt" might become
25
+ # "document (conflicted copy).txt" or
26
+ # "document (Panda's conflicted copy).txt".
27
+ class WriteMode < Base
28
+ VALID_WRITE_MODES = [
29
+ :add,
30
+ :overwrite,
31
+ :update
32
+ ]
33
+
34
+ # @example
35
+ # DropboxApi::Metadata::WriteMode.new :add
36
+ #
37
+ # @example
38
+ # DropboxApi::Metadata::WriteMode.new :overwrite
39
+ #
40
+ # @example
41
+ # DropboxApi::Metadata::WriteMode.new :update, "a1c10ce0dd78"
42
+ def initialize(write_mode, rev = nil)
43
+ @write_mode = write_mode.to_sym
44
+ @rev = rev
45
+
46
+ check_validity
47
+ end
48
+
49
+ def check_validity
50
+ unless valid_mode? @write_mode
51
+ raise ArgumentError, "Invalid write mode: #{value}"
52
+ end
53
+
54
+ if @write_mode == :update && @rev.nil?
55
+ raise ArgumentError, "Mode `:update` expects a `rev` number"
56
+ end
57
+ end
58
+
59
+ def to_hash
60
+ hash = {
61
+ ".tag" => @write_mode
62
+ }
63
+ hash["update"] = @rev if @write_mode == :update
64
+
65
+ hash
66
+ end
67
+
68
+ private
69
+
70
+ def valid_mode?(value)
71
+ VALID_WRITE_MODES.include? value.to_sym
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,17 @@
1
+ module DropboxApi::Results
2
+ class SaveUrlJobStatus < DropboxApi::Results::Base
3
+ def self.new(result_data)
4
+ case result_data[".tag"]
5
+ when "in_progress"
6
+ :in_progress
7
+ when "complete"
8
+ DropboxApi::Metadata::File.new result_data
9
+ when "failed"
10
+ DropboxApi::Errors::SaveUrlError.build("Async job failed",
11
+ result_data["failed"])
12
+ else
13
+ raise NotImplementedError, "Unknown result type: #{result_data[".tag"]}"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ module DropboxApi::Results
2
+ class SaveUrlResult < DropboxApi::Results::Base
3
+ # Example with an async job:
4
+ # {
5
+ # ".tag": "async_job_id",
6
+ # "async_job_id": "VofXAX8DO1sAAAAAAAAD_Q"
7
+ # }
8
+ #
9
+ # I couldn't manage to get anything other than an async job.
10
+ def async_job_id
11
+ @data["async_job_id"]
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  module DropboxApi::Results
2
- class ShareFolderLaunch < DropboxApi::Results::Base
2
+ class ShareFolderLaunch
3
3
  def self.new(result_data)
4
4
  case result_data[".tag"]
5
5
  when "complete"
@@ -1,3 +1,3 @@
1
1
  module DropboxApi
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '0.1.4'.freeze
3
3
  end
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.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - JesΓΊs Burgos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-28 00:00:00.000000000 Z
11
+ date: 2016-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -158,6 +158,8 @@ files:
158
158
  - lib/dropbox_api/endpoints/files/list_revisions.rb
159
159
  - lib/dropbox_api/endpoints/files/move.rb
160
160
  - lib/dropbox_api/endpoints/files/restore.rb
161
+ - lib/dropbox_api/endpoints/files/save_url.rb
162
+ - lib/dropbox_api/endpoints/files/save_url_check_job_status.rb
161
163
  - lib/dropbox_api/endpoints/files/search.rb
162
164
  - lib/dropbox_api/endpoints/files/upload.rb
163
165
  - lib/dropbox_api/endpoints/options_validator.rb
@@ -192,15 +194,18 @@ files:
192
194
  - lib/dropbox_api/errors/list_revisions_error.rb
193
195
  - lib/dropbox_api/errors/list_shared_links_error.rb
194
196
  - lib/dropbox_api/errors/lookup_error.rb
197
+ - lib/dropbox_api/errors/poll_error.rb
195
198
  - lib/dropbox_api/errors/preview_error.rb
196
199
  - lib/dropbox_api/errors/relocation_error.rb
197
200
  - lib/dropbox_api/errors/restore_error.rb
201
+ - lib/dropbox_api/errors/save_url_error.rb
198
202
  - lib/dropbox_api/errors/search_error.rb
199
203
  - lib/dropbox_api/errors/settings_error.rb
200
204
  - lib/dropbox_api/errors/share_folder_error.rb
201
205
  - lib/dropbox_api/errors/share_path_error.rb
202
206
  - lib/dropbox_api/errors/shared_folder_access_error.rb
203
207
  - lib/dropbox_api/errors/sharing_file_access_error.rb
208
+ - lib/dropbox_api/errors/sharing_user_error.rb
204
209
  - lib/dropbox_api/errors/too_many_requests_error.rb
205
210
  - lib/dropbox_api/errors/upload_error.rb
206
211
  - lib/dropbox_api/errors/upload_write_failed_error.rb
@@ -221,7 +226,8 @@ files:
221
226
  - lib/dropbox_api/metadata/folder_sharing_info.rb
222
227
  - lib/dropbox_api/metadata/link_permissions.rb
223
228
  - lib/dropbox_api/metadata/member.rb
224
- - lib/dropbox_api/metadata/member_action_collection.rb
229
+ - lib/dropbox_api/metadata/member_action.rb
230
+ - lib/dropbox_api/metadata/member_action_list.rb
225
231
  - lib/dropbox_api/metadata/member_permission.rb
226
232
  - lib/dropbox_api/metadata/member_permission_list.rb
227
233
  - lib/dropbox_api/metadata/name.rb
@@ -232,8 +238,10 @@ files:
232
238
  - lib/dropbox_api/metadata/shared_link.rb
233
239
  - lib/dropbox_api/metadata/space_allocation.rb
234
240
  - lib/dropbox_api/metadata/space_usage.rb
241
+ - lib/dropbox_api/metadata/symbol.rb
235
242
  - lib/dropbox_api/metadata/team.rb
236
243
  - lib/dropbox_api/metadata/team_member_info.rb
244
+ - lib/dropbox_api/metadata/write_mode.rb
237
245
  - lib/dropbox_api/middleware/decode_result.rb
238
246
  - lib/dropbox_api/result_builder.rb
239
247
  - lib/dropbox_api/results/add_file_member_result_list.rb
@@ -245,6 +253,8 @@ files:
245
253
  - lib/dropbox_api/results/list_folder_result.rb
246
254
  - lib/dropbox_api/results/list_revisions_result.rb
247
255
  - lib/dropbox_api/results/list_shared_links_result.rb
256
+ - lib/dropbox_api/results/save_url_job_status.rb
257
+ - lib/dropbox_api/results/save_url_result.rb
248
258
  - lib/dropbox_api/results/search/match.rb
249
259
  - lib/dropbox_api/results/search_result.rb
250
260
  - lib/dropbox_api/results/share_folder_launch.rb
@@ -1,44 +0,0 @@
1
- module DropboxApi::Metadata
2
- # This represents a collection of actions that may be taken on members of a
3
- # shared folder. Each action will be one of the following:
4
- #
5
- # - leave_a_copy: Allow the member to keep a copy of the folder when removing.
6
- # - make_editor: Make the member an editor of the folder.
7
- # - make_owner: Make the member an owner of the folder.
8
- # - make_viewer: Make the member a viewer of the folder.
9
- # - make_viewer_no_comment: Make the member a viewer of the folder without commenting permissions.
10
- # - remove: Remove the member from the folder.
11
- #
12
- # TODO: Split this object in two: MemberAction & MemberActionList,
13
- # DropboxApi::Metadata::MemberPermission will use it.
14
- class MemberActionCollection < Array
15
- ValidActions = [
16
- :leave_a_copy,
17
- :make_editor,
18
- :make_owner,
19
- :make_viewer,
20
- :make_viewer_no_comment,
21
- :remove
22
- ]
23
-
24
- def initialize(actions)
25
- actions = symbolize actions
26
- validate actions
27
-
28
- super(actions)
29
- end
30
-
31
- private
32
-
33
- def symbolize(actions)
34
- actions.map &:to_sym
35
- end
36
-
37
- def validate(actions)
38
- actions.each do |action|
39
- raise ArgumentError,
40
- "Invalid action: `#{action}`" unless ValidActions.include? action
41
- end
42
- end
43
- end
44
- end