Skip to content

Commit

Permalink
Improves documentation, all API calls available.
Browse files Browse the repository at this point in the history
Added a YARD plugin to add all endpoint methods as part of the Client
class. This'll help a lot to traverse the list of available methods.
  • Loading branch information
Jesús Burgos committed Dec 30, 2016
1 parent ebee6e3 commit eb13f33
Show file tree
Hide file tree
Showing 32 changed files with 70 additions and 29 deletions.
1 change: 1 addition & 0 deletions .yardopts
@@ -1,3 +1,4 @@
--load docs/plugin.rb
-
api_coverage.md
rails_setup.md
68 changes: 68 additions & 0 deletions docs/plugin.rb
@@ -0,0 +1,68 @@
module YARD
class EndpointHandler < Handlers::Ruby::MethodHandler
API_WRAPPER = P("DropboxApi::Client")

handles method_call(:add_endpoint)
namespace_only

process do
register CodeObjects::MethodObject.new(namespace, method_name) do |m|
m.parameters = method_parameters
end

register CodeObjects::MethodObject.new(API_WRAPPER, method_name) do |m|
m.parameters = method_parameters
m.group = namespace.namespace.name.downcase
end
end

def method_name
statement.parameters.first.jump(:tstring_content, :ident).source
end

def method_parameters
# This method is taken from YARD, ideally we would just use it but I
# couldn't find a way to invoke it from here, so I had to copy it over.
# It would be nice to get rid of this method and use YARD's
# implementation instead.
#
# Reference to original code:
# YARD gem (0.9.5): lib/yard/handlers/ruby/method_handler.rb
# Github: https://git.io/vMLQp
args = statement.jump(:block_var).jump(:params)
return [] unless args.is_a? YARD::Parser::Ruby::ParameterNode

params = []

if args.unnamed_required_params
params += args.unnamed_required_params.map {|a| [a.source, nil] }
end

if args.unnamed_optional_params
params += args.unnamed_optional_params.map do |a|
[a[0].source, a[1].source]
end
end

params << ['*' + args.splat_param.source, nil] if args.splat_param

if args.unnamed_end_params
params += args.unnamed_end_params.map {|a| [a.source, nil] }
end

if args.named_params
params += args.named_params.map do |a|
[a[0].source, a[1] ? a[1].source : nil]
end
end

if args.double_splat_param
params << ['**' + args.double_splat_param.source, nil]
end

params << ['&' + args.block_param.source, nil] if args.block_param

params
end
end
end
1 change: 1 addition & 0 deletions lib/dropbox_api/client.rb
Expand Up @@ -4,6 +4,7 @@ def initialize(oauth_bearer = ENV["DROPBOX_OAUTH_BEARER"])
@connection_builder = ConnectionBuilder.new(oauth_bearer)
end

# @!visibility private
def self.add_endpoint(name, endpoint)
define_method(name) do |*args, &block|
endpoint.new(@connection_builder).send(name, *args, &block)
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/copy.rb
Expand Up @@ -5,7 +5,6 @@ class Copy < DropboxApi::Endpoints::Rpc
ResultType = DropboxApi::Metadata::Resource
ErrorType = DropboxApi::Errors::RelocationError

# @method copy(from, to)
# 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.
#
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/create_folder.rb
Expand Up @@ -5,7 +5,6 @@ class CreateFolder < DropboxApi::Endpoints::Rpc
ResultType = DropboxApi::Metadata::Folder
ErrorType = DropboxApi::Errors::CreateFolderError

# @method create_folder(path)
# Create a folder at a given path.
#
# @param path [String] Path in the user's Dropbox to create.
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/delete.rb
Expand Up @@ -5,7 +5,6 @@ class Delete < DropboxApi::Endpoints::Rpc
ResultType = DropboxApi::Metadata::Resource
ErrorType = DropboxApi::Errors::DeleteError

# @method delete(path)
# Delete the file or folder at a given path.
#
# If the path is a folder, all its contents will be deleted too.
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/download.rb
Expand Up @@ -5,7 +5,6 @@ class Download < DropboxApi::Endpoints::ContentDownload
ResultType = DropboxApi::Metadata::File
ErrorType = DropboxApi::Errors::DownloadError

# @method download(path)
# Download a file from a user's Dropbox.
#
# @param path [String] The path of the file to download.
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/get_metadata.rb
Expand Up @@ -7,7 +7,6 @@ class GetMetadata < DropboxApi::Endpoints::Rpc

include DropboxApi::Endpoints::OptionsValidator

# @method get_metadata(path, options = {})
# Returns the metadata for a file or folder.
#
# Note: Metadata for the root folder is unsupported.
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/get_preview.rb
Expand Up @@ -5,7 +5,6 @@ class GetPreview < DropboxApi::Endpoints::ContentDownload
ResultType = DropboxApi::Metadata::File
ErrorType = DropboxApi::Errors::PreviewError

# @method get_preview(path)
# 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
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/get_temporary_link.rb
Expand Up @@ -5,7 +5,6 @@ class GetTemporaryLink < DropboxApi::Endpoints::Rpc
ResultType = DropboxApi::Results::GetTemporaryLinkResult
ErrorType = DropboxApi::Errors::GetMetadataError

# @method get_temporary_link(path)
# 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.
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/get_thumbnail.rb
Expand Up @@ -7,7 +7,6 @@ class GetThumbnail < DropboxApi::Endpoints::ContentDownload

include DropboxApi::Endpoints::OptionsValidator

# @method get_thumbnail(path, options = {})
# Get a thumbnail for an image.
#
# This method currently supports files with the following file extensions:
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/list_folder.rb
Expand Up @@ -7,7 +7,6 @@ class ListFolder < DropboxApi::Endpoints::Rpc

include DropboxApi::Endpoints::OptionsValidator

# @method list_folder(path, options = {})
# Returns the contents of a folder.
#
# @param path [String] The path to the folder you want to read.
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/list_folder_continue.rb
Expand Up @@ -8,7 +8,6 @@ class ListFolderContinue < DropboxApi::Endpoints::Rpc
ResultType = DropboxApi::Results::ListFolderResult
ErrorType = DropboxApi::Errors::ListFolderContinueError

# @method list_folder_continue(cursor)
# Once a cursor has been retrieved from `list_folder`, use this to paginate
# through all files and retrieve updates to the folder.
#
Expand Down
Expand Up @@ -7,7 +7,6 @@ class ListFolderGetLatestCursor < DropboxApi::Endpoints::Rpc

include DropboxApi::Endpoints::OptionsValidator

# @method list_folder_get_latest_cursor(options)
# A way to quickly get a cursor for the folder's state. Unlike
# {DropboxApi::API#list_folder}, this doesn't return any entries. This
# endpoint is for app which only needs to know about new files and
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/list_folder_longpoll.rb
Expand Up @@ -7,7 +7,6 @@ class ListFolderLongpoll < DropboxApi::Endpoints::RpcNotify

include DropboxApi::Endpoints::OptionsValidator

# @method list_folder_longpoll(cursor, options = {})
# 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
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/list_revisions.rb
Expand Up @@ -7,7 +7,6 @@ class ListRevisions < DropboxApi::Endpoints::Rpc

include DropboxApi::Endpoints::OptionsValidator

# @method list_revisions(path, options = {})
# Return revisions of a file
#
# @param path [String] The path to file you want to see the revisions of.
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/move.rb
Expand Up @@ -7,7 +7,6 @@ class Move < DropboxApi::Endpoints::Rpc

include DropboxApi::Endpoints::OptionsValidator

# @method move(from, to, options)
# 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.
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/restore.rb
Expand Up @@ -5,7 +5,6 @@ class Restore < DropboxApi::Endpoints::Rpc
ResultType = DropboxApi::Metadata::File
ErrorType = DropboxApi::Errors::RestoreError

# @method restore(path, rev)
# Restore a file to a specific revision
#
# @param path [String] The path to the file you want to restore.
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/save_url.rb
Expand Up @@ -5,7 +5,6 @@ class SaveUrl < DropboxApi::Endpoints::Rpc
ResultType = DropboxApi::Results::SaveUrlResult
ErrorType = DropboxApi::Errors::SaveUrlError

# @method save_url(path, url)
# 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).
Expand Down
Expand Up @@ -5,7 +5,6 @@ class SaveUrlCheckJobStatus < DropboxApi::Endpoints::Rpc
ResultType = DropboxApi::Results::SaveUrlJobStatus
ErrorType = DropboxApi::Errors::PollError

# @method save_url_check_job_status(job_id)
# Check the status of a +save_url+ job.
#
# @param job_id [String] Id of the asynchronous job. This is the value of
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/search.rb
Expand Up @@ -7,7 +7,6 @@ class Search < DropboxApi::Endpoints::Rpc

include DropboxApi::Endpoints::OptionsValidator

# @method search(query, path = "", options = {})
# Searches for files and folders.
#
# Note: Recent changes may not immediately be reflected in search results
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/files/upload.rb
Expand Up @@ -7,7 +7,6 @@ class Upload < DropboxApi::Endpoints::ContentUpload

include DropboxApi::Endpoints::OptionsValidator

# @method upload(path, content, options = {})
# Creates a new file.
#
# Do not use this to upload a file larger than 150 MB. Instead, create an
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/sharing/add_file_member.rb
Expand Up @@ -7,7 +7,6 @@ class AddFileMember < DropboxApi::Endpoints::Rpc

include DropboxApi::Endpoints::OptionsValidator

# @method add_file_member(file, members, options = {})
# Adds specified members to a file.
#
# The +members+ parameter can be an +Array+ or a single member element. Each
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/sharing/add_folder_member.rb
Expand Up @@ -7,7 +7,6 @@ class AddFolderMember < DropboxApi::Endpoints::Rpc

include DropboxApi::Endpoints::OptionsValidator

# @method add_folder_member(folder_id, members, options = {})
# Allows an owner or editor (if the ACL update policy allows) of a shared
# folder to add another member.
#
Expand Down
Expand Up @@ -5,7 +5,6 @@ class CreateSharedLinkWithSettings < DropboxApi::Endpoints::Rpc
ResultType = DropboxApi::Metadata::SharedLink
ErrorType = DropboxApi::Errors::CreateSharedLinkWithSettingsError

# @method create_shared_link_with_settings(path, settings = {})
# 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
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/sharing/list_folder_members.rb
Expand Up @@ -7,7 +7,6 @@ class ListFolderMembers < DropboxApi::Endpoints::Rpc

include DropboxApi::Endpoints::OptionsValidator

# @method list_folder_members(folder_id, actions = [], options = {})
# Returns shared folder membership by its folder ID.
#
# Apps must have full Dropbox access to use this endpoint.
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/sharing/list_shared_links.rb
Expand Up @@ -7,7 +7,6 @@ class ListSharedLinks < DropboxApi::Endpoints::Rpc

include DropboxApi::Endpoints::OptionsValidator

# @method list_shared_links(options)
# List shared links of this user.
#
# If no path is given or the path is empty, returns a list of all shared
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/sharing/share_folder.rb
Expand Up @@ -7,7 +7,6 @@ class ShareFolder < DropboxApi::Endpoints::Rpc

include DropboxApi::Endpoints::OptionsValidator

# @method share_folder(path, options = {})
# Share a folder with collaborators.
#
# Most sharing will be completed synchronously. Large folders will be
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/users/get_account.rb
Expand Up @@ -5,7 +5,6 @@ class GetAccount < DropboxApi::Endpoints::Rpc
ResultType = DropboxApi::Metadata::BasicAccount
ErrorType = DropboxApi::Errors::GetAccountError

# @method get_account(account_id)
# Get information about a user's account.
#
# @param account_id [String] A user's account identifier.
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/users/get_account_batch.rb
Expand Up @@ -5,7 +5,6 @@ class GetAccountBatch < DropboxApi::Endpoints::Rpc
ResultType = DropboxApi::Results::BasicAccountBatch
ErrorType = DropboxApi::Errors::GetAccountError

# @method get_account_batch(account_ids)
# Get information about multiple user accounts. At most 300 accounts may
# be queried per request.
#
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/users/get_current_account.rb
Expand Up @@ -5,7 +5,6 @@ class GetCurrentAccount < DropboxApi::Endpoints::Rpc
ResultType = DropboxApi::Metadata::BasicAccount
ErrorType = nil

# @method get_current_account
# Get information about the current user's account.
#
# @return [BasicAccount] Detailed information about the current user's account.
Expand Down
1 change: 0 additions & 1 deletion lib/dropbox_api/endpoints/users/get_space_usage.rb
Expand Up @@ -5,7 +5,6 @@ class GetSpaceUsage < DropboxApi::Endpoints::Rpc
ResultType = DropboxApi::Metadata::SpaceUsage
ErrorType = nil

# @method get_space_usage
# Get the space usage information for the current user's account.
#
# @return [SpaceUsage] Information about a user's space usage and quota.
Expand Down

0 comments on commit eb13f33

Please sign in to comment.