Class: CloudFS::FileSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudfs/filesystem.rb

Overview

FileSystem class provides interface to maintain cloudfs user's filesystem

Instance Method Summary collapse

Constructor Details

#initialize(rest_adapter) ⇒ FileSystem

Returns a new instance of FileSystem.

Parameters:

  • rest_adapter (RestAdapter)

    cloudfs RESTful api object

Raises:



25
26
27
28
29
# File 'lib/cloudfs/filesystem.rb', line 25

def initialize(rest_adapter)
  fail RestAdapter::Errors::ArgumentError,
       'invalid RestAdapter, input type must be RestAdapter' unless rest_adapter.is_a?(RestAdapter)
  @rest_adapter = rest_adapter
end

Instance Method Details

#create_share(paths, password: nil) ⇒ Share

Create share of paths in user's filesystem

Parameters:

  • paths (Array<File, Folder, String>)

    file, folder or url

  • password (String) (defaults to: nil)

    password.

Returns:

Raises:



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cloudfs/filesystem.rb', line 65

def create_share(paths, password: nil)
  fail RestAdapter::Errors::ArgumentError,
       'Invalid input, expected items or paths' unless paths

  path_list = []
  [*paths].each do |path|
    FileSystemCommon.validate_item_state(path)
    path_list << FileSystemCommon.get_item_url(path)
  end

  response = @rest_adapter.create_share(path_list, password: password)
  FileSystemCommon.create_item_from_hash(@rest_adapter, ** response)
end

#get_item(path) ⇒ Object

Get an item located in a given location.



99
100
101
102
103
104
105
106
107
108
# File 'lib/cloudfs/filesystem.rb', line 99

def get_item(path)
  fail RestAdapter::Errors::ArgumentError,
       'Invalid input, expected item path' if RestAdapter::Utils.is_blank?(path)

  if path.is_a?(String)
    FileSystemCommon.get_item(@rest_adapter, path)
  else
    nil
  end
end

#list_sharesArray<Share>

List shares created by end-user RestAdapter::Errors::ServiceError]

Returns:

  • (Array<Share>)

    shares

Raises:



49
50
51
52
# File 'lib/cloudfs/filesystem.rb', line 49

def list_shares
  response = @rest_adapter.list_shares
  FileSystemCommon.create_items_from_hash_array(response, @rest_adapter)
end

#list_trashArray<File, Folder>

Returns items in trash.



36
37
38
39
40
41
42
# File 'lib/cloudfs/filesystem.rb', line 36

def list_trash
  response = @rest_adapter.browse_trash.fetch(:items)
  FileSystemCommon.create_items_from_hash_array(
      response,
      @rest_adapter,
      in_trash: true)
end

#retrieve_share(share_key, password: nil) ⇒ Share

Note:

This method is intended for retrieving share from another user

Fetches share associated with share key.

Parameters:

  • share_key (String)

    valid share key

  • password (String) (defaults to: nil)

    password if share is locked

Returns:

  • (Share)

    instance of share

Raises:



89
90
91
92
93
94
95
96
# File 'lib/cloudfs/filesystem.rb', line 89

def retrieve_share(share_key, password: nil)
  fail RestAdapter::Errors::ArgumentError,
       'Invalid input, expected items or paths' if RestAdapter::Utils.is_blank?(share_key)

  @rest_adapter.unlock_share(share_key, password) if password
  response = @rest_adapter.browse_share(share_key).fetch(:share)
  FileSystemCommon.create_item_from_hash(@rest_adapter, ** response)
end

#rootFolder

Get root object of filesystem

Returns:

  • (Folder)

    represents root folder of filesystem

Raises:

  • RestAdapter::Errors::SessionNotLinked, RestAdapter::Errors::ServiceError



17
18
19
20
# File 'lib/cloudfs/filesystem.rb', line 17

def root
  response = @rest_adapter.get_folder_meta('/')
  FileSystemCommon.create_item_from_hash(@rest_adapter, ** response)
end