Class: DropboxApi::Client
- Inherits:
-
Object
- Object
- DropboxApi::Client
- Defined in:
- lib/dropbox_api/client.rb,
lib/dropbox_api/endpoints/virtual/upload_by_chunks.rb
virtual collapse
-
#upload_by_chunks(path, content, options = {}) ⇒ Object
Creates a new file using the upload session endpoints.
sharing collapse
-
#add_file_member(file, members, options = {}) ⇒ Object
Adds specified members to a file.
-
#add_folder_member(folder_id, members, options = {}) ⇒ Object
Allows an owner or editor (if the ACL update policy allows) of a shared folder to add another member.
-
#create_shared_link_with_settings(path, settings = {}) ⇒ DropboxApi::Metadata::SharedLinkMetadata
Create a shared link with custom settings.
-
#get_shared_link_metadata(preview_link, options = {}) ⇒ SharedFileMembers
Get the Metadata for a shared link.
-
#list_file_members(file_id, actions = [], options = {}) ⇒ SharedFileMembers
Use to obtain the members who have been invited to a file, both inherited and uninherited members.
-
#list_folder_members(folder_id, actions = [], options = {}) ⇒ SharedFolderMembers
Returns shared folder membership by its folder ID.
-
#list_shared_links(options = {}) ⇒ ListSharedLinksResult
List shared links of this user.
-
#revoke_shared_link(url) ⇒ Object
Revoke a shared link.
-
#share_folder(path, options = {}) ⇒ DropboxApi::Results::ShareFolderLaunch
Share a folder with collaborators.
-
#unshare_file(file) ⇒ Object
Remove all members from this file.
files collapse
-
#copy(from, to) ⇒ Object
Copy a file or folder to a different location in the user's Dropbox.
-
#copy_batch(entries, options = {}) ⇒ String, Array
Copy multiple files or folders to different locations at once in the user's Dropbox.
-
#copy_batch_check(async_job_id) ⇒ :in_progress, Array
Returns the status of an asynchronous job for #copy_batch.
-
#copy_reference_get(path) ⇒ DropboxApi::Results::GetCopyReferenceResult
Get a copy reference to a file or folder.
-
#copy_reference_save(copy_reference, path) ⇒ DropboxApi::Results::SaveCopyReferenceResult
Save a copy reference returned by #copy_reference_get to the user's Dropbox.
-
#create_file_request(title, destination) ⇒ Object
Create a file request for a given path.
-
#create_folder(path) ⇒ DropboxApi::Metadata::Folder
Create a folder at a given path.
-
#create_folder_batch(paths, options = {}) ⇒ String, Array
Create multiple folders at once.
-
#create_folder_batch_check(async_job_id) ⇒ Array
Returns the status of an asynchronous job for create_folder_batch.
-
#delete(path, options = {}) ⇒ Object
Delete the file or folder at a given path.
-
#delete_batch(entries) ⇒ String, Array
Delete multiple files/folders at once.
-
#delete_batch_check(async_job_id) ⇒ :in_progress, Array
Returns the status of an asynchronous job for delete_batch.
-
#download(path, &block) ⇒ Object
Download a file from a user's Dropbox.
-
#get_metadata(path, options = {}) ⇒ Object
Returns the metadata for a file or folder.
-
#get_preview(path, &block) ⇒ Object
Get a preview for a file.
-
#get_temporary_link(path) ⇒ Object
Get a temporary link to stream content of a file.
-
#get_thumbnail(path, options = {}, &block) ⇒ Object
Get a thumbnail for an image.
-
#get_thumbnail_batch(paths, options = {}) ⇒ Object
Get a thumbnails for a batch of images.
-
#list_folder(path, options = {}) ⇒ Object
Returns the contents of a folder.
-
#list_folder_continue(cursor) ⇒ Object
Once a cursor has been retrieved from
list_folder
, use this to paginate through all files and retrieve updates to the folder. -
#list_folder_get_latest_cursor(options = {}) ⇒ Object
A way to quickly get a cursor for the folder's state.
-
#list_folder_longpoll(cursor, options = {}) ⇒ Object
A longpoll endpoint to wait for changes on an account.
-
#list_revisions(path, options = {}) ⇒ Object
Return revisions of a file.
-
#move(from, to, options = {}) ⇒ Object
Move a file or folder to a different location in the user's Dropbox.
-
#permanently_delete(path, options = {}) ⇒ Object
Permanently delete the file or folder at a given path.
-
#restore(path, rev) ⇒ Object
Restore a file to a specific revision.
-
#save_url(path, url) ⇒ Object
Save a specified URL into a file in user's Dropbox.
-
#save_url_check_job_status(job_id) ⇒ Object
Check the status of a
save_url
job. -
#search(query, options = nil, match_field_options = nil) ⇒ Object
Searches for files and folders.
-
#search_continue(cursor) ⇒ Object
search:2.
-
#upload(path, content, options = {}) ⇒ Object
Creates a new file.
-
#upload_session_append_v2(cursor, content, options = {}) ⇒ Object
Append more data to an upload session.
-
#upload_session_finish(cursor, commit, content = nil) ⇒ Object
Finish an upload session and save the uploaded data to the given file path.
-
#upload_session_start(content, options = {}) ⇒ DropboxApi::Metadata::UploadSessionCursor
Upload sessions allow you to upload a single file in one or more requests, for example where the size of the file is greater than 150 MB.
users collapse
-
#get_account(account_id) ⇒ BasicAccount
Get information about a user's account.
-
#get_account_batch(account_ids) ⇒ Array<BasicAccount>
Get information about multiple user accounts.
-
#get_current_account ⇒ BasicAccount
Get information about the current user's account.
-
#get_space_usage ⇒ SpaceUsage
Get the space usage information for the current user's account.
auth collapse
-
#token_revoke ⇒ Object
Revoke the access token for the current account.
Instance Method Summary collapse
-
#initialize(oauth_bearer = ENV['DROPBOX_OAUTH_BEARER'], access_token: nil, on_token_refreshed: nil) ⇒ Client
constructor
A new instance of Client.
- #middleware ⇒ Object
- #namespace_id ⇒ Object
- #namespace_id=(value) ⇒ Object
Constructor Details
#initialize(oauth_bearer = ENV['DROPBOX_OAUTH_BEARER'], access_token: nil, on_token_refreshed: nil) ⇒ Client
Returns a new instance of Client.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dropbox_api/client.rb', line 4 def initialize( oauth_bearer = ENV['DROPBOX_OAUTH_BEARER'], access_token: nil, on_token_refreshed: nil ) if access_token @connection_builder = ConnectionBuilder.new( access_token: access_token, on_token_refreshed: on_token_refreshed ) elsif oauth_bearer @connection_builder = ConnectionBuilder.new(oauth_bearer) else raise ArgumentError, "Either oauth_bearer or access_token should be set" end end |
Instance Method Details
#add_file_member(file, members, options = {}) ⇒ Object
Adds specified members to a file.
The members
parameter can be an Array
or a single member element. Each
element is represented by either a String
or a Metadata::Member
object. You can identify a member using his email or a Dropbox ID.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dropbox_api/endpoints/sharing/add_file_member.rb', line 34 add_endpoint :add_file_member do |file, members, = {}| ([:quiet, :custom_message, :access_level, :add_message_as_comment], ) [:quiet] ||= false [:custom_message] ||= nil [:access_level] ||= :viewer [:add_message_as_comment] ||= false perform_request .merge({ file: file, members: build_members_param(members) }) end |
#add_folder_member(folder_id, members, options = {}) ⇒ Object
Allows an owner or editor (if the ACL update policy allows) of a shared folder to add another member.
For the new member to get access to all the functionality for this folder,
you will need to call mount_folder
on their behalf.
Apps must have full Dropbox access to use this endpoint.
The members
parameter can be an Array
or a single member element.
Each element is represented by either a String
or a
Metadata::AddMember object. This parameter can be just a string with
an email.
You can also build a Metadata::AddMember object and use it in the
members
parameter, this allows custom options for each member.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dropbox_api/endpoints/sharing/add_folder_member.rb', line 39 add_endpoint :add_folder_member do |folder_id, members, = {}| ([:quiet, :custom_message], ) [:quiet] ||= false [:custom_message] ||= nil perform_request .merge({ shared_folder_id: folder_id.to_s, members: build_members_param(members) }) end |
#copy(from, to) ⇒ Object
Copy a file or folder to a different location in the user's Dropbox. If the source path is a folder all its contents will be copied.
15 16 17 18 19 20 |
# File 'lib/dropbox_api/endpoints/files/copy.rb', line 15 add_endpoint :copy do |from, to| perform_request({ from_path: from, to_path: to }) end |
#copy_batch(entries, options = {}) ⇒ String, Array
Copy multiple files or folders to different locations at once in the user's Dropbox.
This will either finish synchronously, or return a job ID and do the async copy job in background. Please use #copy_batch_check to check the job status.
Note: No errors are returned by this endpoint.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dropbox_api/endpoints/files/copy_batch.rb', line 25 add_endpoint :copy_batch do |entries, = {}| ([ :autorename ], ) [:autorename] ||= false perform_request(.merge({ entries: entries })) end |
#copy_batch_check(async_job_id) ⇒ :in_progress, Array
Returns the status of an asynchronous job for #copy_batch. It returns a list of results for each entry.
17 18 19 |
# File 'lib/dropbox_api/endpoints/files/copy_batch_check.rb', line 17 add_endpoint :copy_batch_check do |async_job_id| perform_request async_job_id: async_job_id end |
#copy_reference_get(path) ⇒ DropboxApi::Results::GetCopyReferenceResult
Get a copy reference to a file or folder. This reference string can be used to save that file or folder to another user's Dropbox by passing it to #copy_reference_save.
16 17 18 19 20 |
# File 'lib/dropbox_api/endpoints/files/copy_reference_get.rb', line 16 add_endpoint :copy_reference_get do |path| perform_request({ path: path }) end |
#copy_reference_save(copy_reference, path) ⇒ DropboxApi::Results::SaveCopyReferenceResult
Save a copy reference returned by #copy_reference_get to the user's Dropbox.
16 17 18 19 20 21 |
# File 'lib/dropbox_api/endpoints/files/copy_reference_save.rb', line 16 add_endpoint :copy_reference_save do |copy_reference, path| perform_request({ copy_reference: copy_reference, path: path }) end |
#create_file_request(title, destination) ⇒ Object
Create a file request for a given path.
15 16 17 18 19 20 |
# File 'lib/dropbox_api/endpoints/file_requests/create_file_request.rb', line 15 add_endpoint :create_file_request do |title, destination| perform_request({ title: title, destination: destination }) end |
#create_folder(path) ⇒ DropboxApi::Metadata::Folder
Create a folder at a given path.
13 14 15 16 17 |
# File 'lib/dropbox_api/endpoints/files/create_folder.rb', line 13 add_endpoint :create_folder do |path| perform_request({ path: path }) end |
#create_folder_batch(paths, options = {}) ⇒ String, Array
Create multiple folders at once.
This route is asynchronous for large batches, which returns a job ID
immediately and runs the create folder batch asynchronously. Otherwise,
creates the folders and returns the result synchronously for smaller
inputs. You can force asynchronous behaviour by using the :force_async
flag. Use #create_folder_batch_check to check the job status.
Note: No errors are returned by this endpoint.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dropbox_api/endpoints/files/create_folder_batch.rb', line 28 add_endpoint :create_folder_batch do |paths, = {}| ([ :autorename, :force_async ], ) [:autorename] ||= false [:force_async] ||= false perform_request(.merge({ paths: paths })) end |
#create_folder_batch_check(async_job_id) ⇒ Array
Returns the status of an asynchronous job for create_folder_batch. If success, it returns list of result for each entry.
16 17 18 19 20 |
# File 'lib/dropbox_api/endpoints/files/create_folder_batch_check.rb', line 16 add_endpoint :create_folder_batch_check do |async_job_id| perform_request({ async_job_id: async_job_id }) end |
#create_shared_link_with_settings(path, settings = {}) ⇒ DropboxApi::Metadata::SharedLinkMetadata
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.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/dropbox_api/endpoints/sharing/create_shared_link_with_settings.rb', line 32 add_endpoint :create_shared_link_with_settings do |path, settings = {}| ([ :requested_visibility, :link_password, :expires ], settings) settings[:requested_visibility] ||= 'public' settings[:link_password] ||= nil settings[:expires] ||= nil perform_request({ path: path, settings: settings }) end |
#delete(path, options = {}) ⇒ Object
Delete the file or folder at a given path.
If the path is a folder, all its contents will be deleted too.
A successful response indicates that the file or folder was deleted. The returned metadata will be the corresponding Metadata::File or Metadata::Folder for the item at time of deletion, and not a Metadata::Deleted object.
25 26 27 28 29 30 31 |
# File 'lib/dropbox_api/endpoints/files/delete.rb', line 25 add_endpoint :delete do |path, = {}| ([:parent_rev], ) perform_request .merge({ path: path }) end |
#delete_batch(entries) ⇒ String, Array
Delete multiple files/folders at once.
This route is asynchronous, which returns a job ID immediately and runs the delete batch asynchronously. Use #delete_batch_check to check the job status.
17 18 19 20 21 |
# File 'lib/dropbox_api/endpoints/files/delete_batch.rb', line 17 add_endpoint :delete_batch do |entries| perform_request({ entries: entries }) end |
#delete_batch_check(async_job_id) ⇒ :in_progress, Array
Returns the status of an asynchronous job for delete_batch. If success, it returns list of result for each entry.
15 16 17 18 19 |
# File 'lib/dropbox_api/endpoints/files/delete_batch_check.rb', line 15 add_endpoint :delete_batch_check do |async_job_id| perform_request({ async_job_id: async_job_id }) end |
#download(path, &block) ⇒ Object
Download a file from a user's Dropbox.
12 13 14 |
# File 'lib/dropbox_api/endpoints/files/download.rb', line 12 add_endpoint :download do |path, &block| perform_request({path: path}, &block) end |
#get_account(account_id) ⇒ BasicAccount
Get information about a user's account.
13 14 15 |
# File 'lib/dropbox_api/endpoints/users/get_account.rb', line 13 add_endpoint :get_account do |account_id| perform_request account_id: account_id end |
#get_account_batch(account_ids) ⇒ Array<BasicAccount>
Get information about multiple user accounts. At most 300 accounts may be queried per request.
15 16 17 |
# File 'lib/dropbox_api/endpoints/users/get_account_batch.rb', line 15 add_endpoint :get_account_batch do |account_ids| perform_request account_ids: account_ids end |
#get_current_account ⇒ BasicAccount
Get information about the current user's account.
12 13 14 |
# File 'lib/dropbox_api/endpoints/users/get_current_account.rb', line 12 add_endpoint :get_current_account do perform_request nil end |
#get_metadata(path, options = {}) ⇒ Object
Returns the metadata for a file or folder.
Note: Metadata for the root folder is unsupported.
If you request the media_info
attribute, note that it could be set to
:pending
or nil
.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dropbox_api/endpoints/files/get_metadata.rb', line 30 add_endpoint :get_metadata do |path, = {}| ([ :include_media_info, :include_deleted, :include_has_explicit_shared_members ], ) perform_request(.merge({ path: path })) end |
#get_preview(path, &block) ⇒ Object
Get a preview for a file. Currently previews are only generated for the files with the following extensions: .doc, .docx, .docm, .ppt, .pps, .ppsx, .ppsm, .pptx, .pptm, .xls, .xlsx, .xlsm, .rtf
14 15 16 |
# File 'lib/dropbox_api/endpoints/files/get_preview.rb', line 14 add_endpoint :get_preview do |path, &block| perform_request({path: path}, &block) end |
#get_shared_link_metadata(preview_link, options = {}) ⇒ SharedFileMembers
Get the Metadata for a shared link
If a preview url is given, returns the shared file or folder that is represent by that link.
23 24 25 26 27 28 29 |
# File 'lib/dropbox_api/endpoints/sharing/get_shared_link_metadata.rb', line 23 add_endpoint :get_shared_link_metadata do |preview_link, = {}| ([:path, :link_password], ) perform_request .merge( url: preview_link ) end |
#get_space_usage ⇒ SpaceUsage
Get the space usage information for the current user's account.
12 13 14 |
# File 'lib/dropbox_api/endpoints/users/get_space_usage.rb', line 12 add_endpoint :get_space_usage do perform_request nil end |
#get_temporary_link(path) ⇒ Object
Get a temporary link to stream content of a file. This link will expire in four hours and afterwards you will get 410 Gone. Content-Type of the link is determined automatically by the file's mime type.
14 15 16 |
# File 'lib/dropbox_api/endpoints/files/get_temporary_link.rb', line 14 add_endpoint :get_temporary_link do |path| perform_request({path: path}) end |
#get_thumbnail(path, options = {}, &block) ⇒ Object
Get a thumbnail for an image.
This method currently supports files with the following file extensions: jpg, jpeg, png, tiff, tif, gif and bmp. Photos that are larger than 20MB in size won't be converted to a thumbnail.
48 49 50 51 52 53 54 55 56 |
# File 'lib/dropbox_api/endpoints/files/get_thumbnail.rb', line 48 add_endpoint :get_thumbnail do |path, = {}, &block| ([:format, :size], ) [:format] ||= :jpeg [:size] ||= :w64h64 perform_request(.merge({ path: path }), &block) end |
#get_thumbnail_batch(paths, options = {}) ⇒ Object
Get a thumbnails for a batch of images.
23 24 25 26 27 28 29 30 |
# File 'lib/dropbox_api/endpoints/files/get_thumbnail_batch.rb', line 23 add_endpoint :get_thumbnail_batch do |paths, = {}| ([:format, :size, :mode], ) [:format] ||= :jpeg [:size] ||= :w64h64 [:mode] ||= :strict perform_request entries: build_entries_params(paths, ) end |
#list_file_members(file_id, actions = [], options = {}) ⇒ SharedFileMembers
Use to obtain the members who have been invited to a file, both inherited and uninherited members.
Apps must have full Dropbox access to use this endpoint.
37 38 39 40 41 42 43 44 45 |
# File 'lib/dropbox_api/endpoints/sharing/list_file_members.rb', line 37 add_endpoint :list_file_members do |file_id, actions = [], = {}| ([:limit, :include_inherited], ) [:limit] ||= 100 perform_request .merge({ file: file_id, actions: DropboxApi::Metadata::MemberActionList.new(actions) }) end |
#list_folder(path, options = {}) ⇒ Object
Returns the contents of a folder.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dropbox_api/endpoints/files/list_folder.rb', line 29 add_endpoint :list_folder do |path, = {}| ([ :recursive, :include_media_info, :include_deleted, :shared_link, :include_has_explicit_shared_members, :limit ], ) [:recursive] ||= false [:include_media_info] ||= false [:include_deleted] ||= false [:shared_link] = build_shared_link_param([:shared_link]) if [:shared_link] [:limit] = [:limit] if [:limit] perform_request .merge({ path: path }) end |
#list_folder_continue(cursor) ⇒ Object
Once a cursor has been retrieved from list_folder
, use this to paginate
through all files and retrieve updates to the folder.
17 18 19 |
# File 'lib/dropbox_api/endpoints/files/list_folder_continue.rb', line 17 add_endpoint :list_folder_continue do |cursor| perform_request cursor: cursor end |
#list_folder_get_latest_cursor(options = {}) ⇒ Object
A way to quickly get a cursor for the folder's state. Unlike #list_folder, this doesn't return any entries. This endpoint is for app which only needs to know about new files and modifications and doesn't need to know about files that already exist in Dropbox.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dropbox_api/endpoints/files/list_folder_get_latest_cursor.rb', line 28 add_endpoint :list_folder_get_latest_cursor do | = {}| ([ :path, :recursive, :include_media_info, :include_deleted, :include_has_explicit_shared_members ], ) [:recursive] ||= false [:include_media_info] ||= false [:include_deleted] ||= false perform_request end |
#list_folder_longpoll(cursor, options = {}) ⇒ Object
A longpoll endpoint to wait for changes on an account. In conjunction with list_folder, this call gives you a low-latency way to monitor an account for file changes. The connection will block until there are changes available or a timeout occurs. This endpoint is useful mostly for client-side apps. If you're looking for server-side notifications, check out our webhooks documentation.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dropbox_api/endpoints/files/list_folder_longpoll.rb', line 25 add_endpoint :list_folder_longpoll do |cursor, = {}| ([ :timeout ], ) [:timeout] ||= 30 perform_request .merge({ cursor: cursor }) end |
#list_folder_members(folder_id, actions = [], options = {}) ⇒ SharedFolderMembers
Returns shared folder membership by its folder ID.
Apps must have full Dropbox access to use this endpoint.
30 31 32 33 34 35 36 37 38 |
# File 'lib/dropbox_api/endpoints/sharing/list_folder_members.rb', line 30 add_endpoint :list_folder_members do |folder_id, actions = [], = {}| ([:limit], ) [:limit] ||= 100 perform_request .merge({ shared_folder_id: folder_id, actions: DropboxApi::Metadata::MemberActionList.new(actions) }) end |
#list_revisions(path, options = {}) ⇒ Object
Return revisions of a file
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dropbox_api/endpoints/files/list_revisions.rb', line 16 add_endpoint :list_revisions do |path, = {}| ([ :limit ], ) [:limit] ||= 10 perform_request .merge({ path: path }) end |
#list_shared_links(options = {}) ⇒ ListSharedLinksResult
List shared links of this user.
If no path is given or the path is empty, returns a list of all shared links for the current user.
If a non-empty path is given, returns a list of all shared links that allow access to the given path - direct links to the given path and links to parent folders of the given path. Links to parent folders can be suppressed by setting direct_only to true.
25 26 27 28 29 |
# File 'lib/dropbox_api/endpoints/sharing/list_shared_links.rb', line 25 add_endpoint :list_shared_links do | = {}| ([:path, :cursor, :direct_only], ) perform_request end |
#middleware ⇒ Object
21 22 23 |
# File 'lib/dropbox_api/client.rb', line 21 def middleware @connection_builder.middleware end |
#move(from, to, options = {}) ⇒ Object
Move a file or folder to a different location in the user's Dropbox.
If the source path is a folder all its contents will be moved.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dropbox_api/endpoints/files/move.rb', line 20 add_endpoint :move do |from, to, = {}| # We're not implementing support for the `allow_shared_folder` option # because according to Dropbox's documentation: "This field is always # true for move". ([ :autorename ], ) perform_request .merge({ from_path: from, to_path: to }) end |
#namespace_id ⇒ Object
29 30 31 |
# File 'lib/dropbox_api/client.rb', line 29 def namespace_id @connection_builder.namespace_id end |
#namespace_id=(value) ⇒ Object
25 26 27 |
# File 'lib/dropbox_api/client.rb', line 25 def namespace_id=(value) @connection_builder.namespace_id = value end |
#permanently_delete(path, options = {}) ⇒ Object
Permanently delete the file or folder at a given path.
See https://www.dropbox.com/en/help/40
Note: This endpoint is only available for Dropbox Business apps.
21 22 23 24 25 26 27 |
# File 'lib/dropbox_api/endpoints/files/permanently_delete.rb', line 21 add_endpoint :permanently_delete do |path, = {}| ([:parent_rev], ) perform_request .merge({ path: path }) end |
#restore(path, rev) ⇒ Object
Restore a file to a specific revision
13 14 15 16 17 18 |
# File 'lib/dropbox_api/endpoints/files/restore.rb', line 13 add_endpoint :restore do |path, rev| perform_request({ path: path, rev: rev }) end |
#revoke_shared_link(url) ⇒ Object
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.
18 19 20 21 22 |
# File 'lib/dropbox_api/endpoints/sharing/revoke_shared_link.rb', line 18 add_endpoint :revoke_shared_link do |url| perform_request({ url: url }) end |
#save_url(path, url) ⇒ Object
Save a specified URL into a file in user's Dropbox. If the given path already exists, the file will be renamed to avoid the conflict (e.g. myfile (1).txt).
16 17 18 19 20 21 |
# File 'lib/dropbox_api/endpoints/files/save_url.rb', line 16 add_endpoint :save_url do |path, url| perform_request({ path: path, url: url }) end |
#save_url_check_job_status(job_id) ⇒ Object
Check the status of a save_url
job.
14 15 16 17 18 |
# File 'lib/dropbox_api/endpoints/files/save_url_check_job_status.rb', line 14 add_endpoint :save_url_check_job_status do |job_id| perform_request({ async_job_id: job_id }) end |
#search(query, options = nil, match_field_options = nil) ⇒ Object
Searches for files and folders.
Note: Recent changes may not immediately be reflected in search results due to a short delay in indexing.
22 23 24 25 26 27 28 29 30 |
# File 'lib/dropbox_api/endpoints/files/search.rb', line 22 add_endpoint :search do |query, = nil, = nil| params = { query: query } params[:options] = .to_hash unless .nil? params[:match_field_options] = .to_hash unless .nil? perform_request(params) end |
#search_continue(cursor) ⇒ Object
search:2. Used to fetch the next page of results.
19 20 21 |
# File 'lib/dropbox_api/endpoints/files/search_continue.rb', line 19 add_endpoint :search_continue do |cursor| perform_request cursor: cursor end |
#share_folder(path, options = {}) ⇒ DropboxApi::Results::ShareFolderLaunch
Share a folder with collaborators.
Most sharing will be completed synchronously. Large folders will be
completed asynchronously. To make testing the async case repeatable, set
force_async
.
If a ShareFolderLaunch.async_job_id is returned, you'll need to call check_share_job_status until the action completes to get the metadata for the folder.
Apps must have full Dropbox access to use this endpoint.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/dropbox_api/endpoints/sharing/share_folder.rb', line 37 add_endpoint :share_folder do |path, = {}| ([ :member_policy, :acl_update_policy, :shared_link_policy, :force_async ], ) [:member_policy] ||= :anyone [:acl_update_policy] ||= :owner [:shared_link_policy] ||= :anyone [:force_async] ||= false begin perform_request .merge({ path: path }) rescue DropboxApi::Errors::AlreadySharedError => error error.shared_folder end end |
#token_revoke ⇒ Object
Revoke the access token for the current account
11 12 13 |
# File 'lib/dropbox_api/endpoints/auth/token_revoke.rb', line 11 add_endpoint :token_revoke do perform_request(nil) end |
#unshare_file(file) ⇒ Object
Remove all members from this file. Does not remove inherited members.
A successful response indicates that the file was unshared.
14 15 16 17 18 |
# File 'lib/dropbox_api/endpoints/sharing/unshare_file.rb', line 14 add_endpoint :unshare_file do |file| perform_request({ file: file }) end |
#upload(path, content, options = {}) ⇒ Object
Creates a new file.
Do not use this to upload a file larger than 150 MB.
For larger files you can use #upload_by_chunks.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dropbox_api/endpoints/files/upload.rb', line 50 add_endpoint :upload do |path, content, = {}| ([ :mode, :autorename, :client_modified, :mute ], ) [:path] = path commit_info = DropboxApi::Metadata::CommitInfo. perform_request(commit_info.to_hash, content) end |
#upload_by_chunks(path, content, options = {}) ⇒ Object
Creates a new file using the upload session endpoints. You can use this method to upload files larger than 150 MB.
41 42 43 44 45 46 47 48 |
# File 'lib/dropbox_api/endpoints/virtual/upload_by_chunks.rb', line 41 def upload_by_chunks(path, content, = {}) content = StringIO.new(content) if content.is_a?(String) uploader = DropboxApi::ChunkedUploader.new(self, path, content, ) uploader.start uploader.upload uploader.finish end |
#upload_session_append_v2(cursor, content, options = {}) ⇒ Object
Append more data to an upload session.
When the parameter close
is set, this call will close the session.
A single request should not upload more than 150 MB.
The maximum size of a file one can upload to an upload session is 350 GB.
Calling this method may update the cursor received. In particular, the
offset variable will be increased to match the new position. This allows
you to make subsequent calls to the endpoint using the same cursor
, as
you can see in the example.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dropbox_api/endpoints/files/upload_session_append_v2.rb', line 39 add_endpoint :upload_session_append_v2 do |cursor, content, = {}| ([ :close ], ) perform_request(.merge({ cursor: cursor.to_hash }), content) cursor.offset += content.bytesize end |
#upload_session_finish(cursor, commit, content = nil) ⇒ Object
Finish an upload session and save the uploaded data to the given file path.
A single request should not upload more than 150 MB.
The maximum size of a file one can upload to an upload session is 350 GB.
22 23 24 25 26 27 |
# File 'lib/dropbox_api/endpoints/files/upload_session_finish.rb', line 22 add_endpoint :upload_session_finish do |cursor, commit, content = nil| perform_request({ cursor: cursor.to_hash, commit: commit.to_hash }, content) end |
#upload_session_start(content, options = {}) ⇒ DropboxApi::Metadata::UploadSessionCursor
Upload sessions allow you to upload a single file in one or more requests, for example where the size of the file is greater than 150 MB.
This call starts a new upload session with the given data. You can then use #upload_session_append_v2 to add more data and #upload_session_finish to save all the data to a file in Dropbox.
A single request should not upload more than 150 MB of file contents.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dropbox_api/endpoints/files/upload_session_start.rb', line 26 add_endpoint :upload_session_start do |content, = {}| ([ :close ], ) session = perform_request(, content) DropboxApi::Metadata::UploadSessionCursor.new({ 'session_id' => session.session_id, 'offset' => content.bytesize }) end |