Class: BrickFTP::RESTfulAPI::ListFolders

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/brick_ftp/restful_api/list_folders.rb

Overview

List folder contents

Params

PARAMETER TYPE DESCRIPTION
page integer Page number of items to return in this request.
per_page integer Requested number of items returned per request. Maximum: 5000, leave blank for default (strongly recommended).
search string Only return items matching the given search text.
sort_by[path] enum Sort by file name, and value is either asc or desc to indicate normal or reverse sort. (Note that sort_by[path] = asc is the default.)
sort_by[size] enum Sort by file size, and value is either asc or desc to indicate smaller files first or larger files first, respectively.
sort_by[modified_at_datetime] enum Sort by modification time, and value is either asc or desc to indicate older files first or newer files first, respectively.

Defined Under Namespace

Classes: Params

Instance Method Summary collapse

Methods included from Command

included, #initialize

Instance Method Details

#call(path, params = nil) ⇒ Array<BrickFTP::Types::File>

Lists the contents of the folder provided in the URL.

Remember that a blank URL refers to the root folder. So for example, you can list the contents of the root folder using the REST API by sending a GET request to /folders. Another folder can be listed by inserting its complete path in that URL after /folders, for example: /folders/employee/engineering.

There is a maximum number of entries in the folder that will be listed with a single request (default 1000 or whatever value you provide as the per_page parameter). So if exactly that many entries are returned you will need to increment the value of the page parameter in subsequent queries to continue listing the folder.

Parameters:

Returns:



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/brick_ftp/restful_api/list_folders.rb', line 53

def call(path, params = nil)
  validate_params!(params)

  query = build_query(params)
  endpoint = "/api/rest/v1/folders/#{ERB::Util.url_encode(path)}"
  endpoint = "#{endpoint}?#{query}" unless query.empty?

  res = client.get(endpoint)

  res.map { |i| BrickFTP::Types::File.new(**i.symbolize_keys) }
end