Class: BrickFTP::RESTfulAPI::CountFolderContents

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

Overview

Count folder contents

Instance Method Summary collapse

Methods included from Command

included, #initialize

Instance Method Details

#call(path, recursive: false) ⇒ BrickFTP::Types::FolderContentsCount

Returns number of files and folders.

  • Returns the combined total number of files and subfolders in a given folder recursively.
  • Returns the number of files and folders, separately, located inside a given folder (non-recursively).

Parameters:

  • path (String)
  • recursive (Boolean) (defaults to: false)

Returns:



25
26
27
28
29
30
31
32
33
34
# File 'lib/brick_ftp/restful_api/count_folder_contents.rb', line 25

def call(path, recursive: false)
  action = recursive ? 'count' : 'count_nrs'
  res = client.get("/api/rest/v1/folders/#{ERB::Util.url_encode(path)}?action=#{action}")

  if recursive
    BrickFTP::Types::FolderContentsCount.new(total: res['data']['count'])
  else
    BrickFTP::Types::FolderContentsCount.new(**res['data']['count'].symbolize_keys)
  end
end