Skip to content

Commit

Permalink
Merge branch 'anshu1992-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesus Burgos Macia committed Feb 16, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents ad7bfb1 + 1dded5e commit 7851bcd
Showing 21 changed files with 682 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -299,7 +299,7 @@ <h3 class="signature first" id="create_shared_link_with_settings-instance_method

<span class='id identifier rubyid_add_endpoint'>add_endpoint</span> <span class='symbol'>:create_shared_link_with_settings</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_path'>path</span><span class='comma'>,</span> <span class='id identifier rubyid_settings'>settings</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='op'>|</span>
<span class='comment'># NOTE: This endpoint accepts an additional option `settings` which
</span> <span class='comment'># hasn&#39;t been implemented.
</span> <span class='comment'># has been implemented but will work only for pro users and it will return no permission error for basic users.
</span> <span class='id identifier rubyid_perform_request'>perform_request</span> <span class='symbol'>:path</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_path'>path</span>
<span class='kw'>end</span></pre>
</td>
2 changes: 2 additions & 0 deletions lib/dropbox_api.rb
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@
require 'dropbox_api/errors/write_error'
require 'dropbox_api/errors/relocation_error'
require 'dropbox_api/errors/restore_error'
require 'dropbox_api/errors/revoke_shared_link_error'
require 'dropbox_api/errors/save_url_error'
require 'dropbox_api/errors/search_error'
require 'dropbox_api/errors/settings_error'
@@ -169,6 +170,7 @@
require 'dropbox_api/endpoints/sharing/list_file_members'
require 'dropbox_api/endpoints/sharing/add_folder_member'
require 'dropbox_api/endpoints/sharing/list_folder_members'
require 'dropbox_api/endpoints/sharing/revoke_shared_link'
require 'dropbox_api/endpoints/sharing/share_folder'
require 'dropbox_api/endpoints/sharing/list_shared_links'
require 'dropbox_api/endpoints/sharing/create_shared_link_with_settings'
Original file line number Diff line number Diff line change
@@ -5,19 +5,43 @@ class CreateSharedLinkWithSettings < DropboxApi::Endpoints::Rpc
ResultType = DropboxApi::Metadata::SharedLinkMetadata
ErrorType = DropboxApi::Errors::CreateSharedLinkWithSettingsError

include DropboxApi::OptionsValidator

# Create a shared link with custom settings. If no settings are given then
# the default visibility is :public. (The resolved
# visibility, though, may depend on other aspects such as team and shared
# folder settings).
#
# NOTE: The `settings` parameter will only work for pro, business or
# enterprise accounts. It will return no permission error otherwise.
#
# @param path [String] The path to be shared by the shared link.
# @param settings [SharedLinkSettings] The requested settings for the newly
# created shared link This field is optional.
# @return [DropboxApi::Metadata::SharedLinkMetadata]
#
# @option settings requested_visibility The requested access for this
# shared link. This field is optional. Must be one of "public",
# "team_only" or "password".
# @option settings link_password If requested_visibility is
# "password" this is needed to specify the password to access the link.
# This field is optional.
# @option settings expires Expiration time of the shared link. By default
# the link won't expire. This field is optional.
add_endpoint :create_shared_link_with_settings do |path, settings = {}|
# NOTE: This endpoint accepts an additional option `settings` which
# hasn't been implemented.
perform_request :path => path
validate_options([
:requested_visibility,
:link_password,
:expires
], settings)
settings[:requested_visibility] ||= 'public'
settings[:link_password] ||= nil
settings[:expires] ||= nil

perform_request({
:path => path,
:settings=> settings
})
end
end
end
23 changes: 23 additions & 0 deletions lib/dropbox_api/endpoints/sharing/revoke_shared_link.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module DropboxApi::Endpoints::Sharing
class RevokeSharedLink < DropboxApi::Endpoints::Rpc
Method = :post
Path = "/2/sharing/revoke_shared_link".freeze
ResultType = DropboxApi::Results::VoidResult
ErrorType = DropboxApi::Errors::RevokeSharedLinkError

# Revoke a shared link.
#
# Note that even after revoking a shared link to a file, the file may be accessible
# if there are shared links leading to any of the file parent folders.
#
# A successful response indicates that the shared link was revoked.
#
# @param url [String] shared url which needs to be revoked.

add_endpoint :revoke_shared_link do |url|
perform_request({
:url => url
})
end
end
end
1 change: 1 addition & 0 deletions lib/dropbox_api/errors/basic_error.rb
Original file line number Diff line number Diff line change
@@ -84,6 +84,7 @@ class RestrictedContentError < BasicError; end
class SharedLinkAccessDeniedError < BasicError; end
class SharedLinkAlreadyExistsError < BasicError; end
class SharedLinkNotFoundError < BasicError; end
class SharedLinkMalformedError < BasicError; end
class TeamFolderError < BasicError; end
class TeamPolicyDisallowsMemberPolicyError < BasicError; end
class TooManyFilesError < BasicError; end
10 changes: 10 additions & 0 deletions lib/dropbox_api/errors/revoke_shared_link_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module DropboxApi::Errors
class RevokeSharedLinkError < BasicError
ErrorSubtypes = {
:shared_link_not_found => SharedLinkNotFoundError,
:shared_link_access_denied => SharedLinkAccessDeniedError,
:unsupported_link_type => UnsupportedLinkTypeError,
:shared_link_malformed => SharedLinkMalformedError
}.freeze
end
end
2 changes: 1 addition & 1 deletion spec/endpoints/files/delete_spec.rb
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
expect(file.name).to eq("will_be_deleted.txt")
end

it "wont' delete the file if `parent_rev` doesn't match", :cassette => "delete/invalid_parent_rev" do
it "won't delete the file if `parent_rev` doesn't match", :cassette => "delete/invalid_parent_rev" do
expect {
@client.delete "#{path_prefix}/wont_be_deleted.txt", :parent_rev => "1c0576c68d6"
}.to raise_error(DropboxApi::Errors::FileConflictError)
30 changes: 27 additions & 3 deletions spec/endpoints/sharing/create_shared_link_with_settings_spec.rb
Original file line number Diff line number Diff line change
@@ -4,24 +4,48 @@
end

context "on a file" do
it "creates a shared link", :cassette => "create_shared_link_with_settings/success_file" do
it "creates a shared link for basic and pro users", :cassette => "create_shared_link_with_settings/success_file" do
link = @client.create_shared_link_with_settings "/file_for_sharing.docx"

expect(link).to be_a(DropboxApi::Metadata::FileLinkMetadata)
end

it "raises an error if already shared", :cassette => "create_shared_link_with_settings/already_shared" do
it "creates a shared link with settings for pro users", :cassette => "create_shared_link_with_settings/success_file_with_settings" do
link = @client.create_shared_link_with_settings("/file_for_sharing.docx", { expires: "2019-03-12T10:34:42Z" })

expect(link).to be_a(DropboxApi::Metadata::FileLinkMetadata)
end

it "raises an error if settings options are passed for basic users", :cassette => "create_shared_link_with_settings/error_no_permission_for_file" do
expect {
@client.create_shared_link_with_settings("/file_for_sharing.docx", { expires: "2019-03-12T10:34:42Z" })
}.to raise_error(DropboxApi::Errors::NoPermissionError)
end

it "raises an error if already shared for basic and pro users", :cassette => "create_shared_link_with_settings/already_shared" do
expect {
@client.create_shared_link_with_settings "/file_for_sharing.docx"
}.to raise_error(DropboxApi::Errors::SharedLinkAlreadyExistsError)
end
end

context "on a folder" do
it "creates a shared link", :cassette => "create_shared_link_with_settings/success_folder" do
it "creates a shared link for basic and pro users", :cassette => "create_shared_link_with_settings/success_folder" do
link = @client.create_shared_link_with_settings "/folder_for_sharing"

expect(link).to be_a(DropboxApi::Metadata::FolderLinkMetadata)
end

it "creates a shared link with settings for pro users", :cassette => "create_shared_link_with_settings/success_folder_with_settings" do
link = @client.create_shared_link_with_settings("/folder_for_sharing", { expires: "2019-03-12T10:34:42Z" })

expect(link).to be_a(DropboxApi::Metadata::FolderLinkMetadata)
end

it "raises an error if settings options are passed for basic user", :cassette => "create_shared_link_with_settings/error_no_permission_for_folder" do
expect {
@client.create_shared_link_with_settings("/folder_for_sharing", { expires: "2019-03-12T10:34:42Z" })
}.to raise_error(DropboxApi::Errors::NoPermissionError)
end
end
end
31 changes: 31 additions & 0 deletions spec/endpoints/sharing/revoke_shared_link_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
describe DropboxApi::Client, "#revoke_shared_link" do
before :each do
@client = DropboxApi::Client.new
end

context "revoke shared link access" do
it "revoke a shared link", :cassette => "revoke_shared_link/success" do
link = @client.revoke_shared_link "https://www.dropbox.com/sh/t0ebpiojwy4l1bn/AAAcU6qf20b8R-SG5_PJCBOQa?dl=0"

# The endpoint doesn't have any return values, can't test the output!
end

it "raises an error if link is not found", :cassette => "revoke_shared_link/not_found" do
expect {
@client.revoke_shared_link "https://www.dropbox.com/sh/t0ebpiojwy4l1bn/AAAcU6qf20b8R-SG5_PJCBOQa?dl=0"
}.to raise_error(DropboxApi::Errors::SharedLinkNotFoundError)
end

it "raises access denied error if not permitted", :cassette => "revoke_shared_link/access_denied" do
expect {
@client.revoke_shared_link "https://www.dropbox.com/s/al0w4e11j0e1kp3/file_for_sharing.docx?dl=0"
}.to raise_error(DropboxApi::Errors::SharedLinkAccessDeniedError)
end

it "raises shared link malformed error if link is malformed", :cassette => "revoke_shared_link/malformed_shared_link" do
expect {
@client.revoke_shared_link "https://www.dropbox.com/al0w4e11j0e1kp3/file_for_sharing.docx?dl=0"
}.to raise_error(DropboxApi::Errors::SharedLinkMalformedError)
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7851bcd

Please sign in to comment.