Class: CloudFS::Share
- Inherits:
-
Object
- Object
- CloudFS::Share
- Defined in:
- lib/cloudfs/share.rb
Overview
Share class is used to create and manage shares in end-user's account
Instance Attribute Summary collapse
-
#application_data ⇒ String
readonly
Application data.
-
#date_content_last_modified ⇒ Time
readonly
Modified time.
-
#date_created ⇒ Time
readonly
Creation time.
-
#date_meta_last_modified ⇒ Time
readonly
Modified time.
-
#name ⇒ String
readonly
Name.
-
#share_key ⇒ String
readonly
Share_key.
-
#short_url ⇒ String
readonly
Short_url.
-
#size ⇒ String
readonly
Size.
-
#type ⇒ String
readonly
Type.
-
#url ⇒ String
readonly
Url.
Instance Method Summary collapse
-
#change_attributes(values, password: nil) ⇒ Boolean
Changes, adds, or removes the share’s password or updates the name.
-
#delete ⇒ true
Delete this share.
-
#exists? ⇒ Boolean
Whether the share exists, false only if it has been deleted.
-
#initialize(rest_adapter, **properties) ⇒ Share
constructor
A new instance of Share.
-
#list ⇒ Array<File, Folder>
List items in this share RestAdapter::Errors::InvalidShareError].
-
#receive(path: nil, exists: 'RENAME') ⇒ Array<File, Folder>
Receive contents of this share at specified path in user's filesystem.
-
#refresh ⇒ Share
Refresh this share to latest state RestAdapter::Errors::InvalidShareError].
-
#save(password: nil) ⇒ Share
Save this share's current state.
-
#set_name(new_name, password: nil) ⇒ Object
Set the name of the share.
-
#set_password(password, current_password: nil) ⇒ Share
Change password of this share.
Constructor Details
#initialize(rest_adapter, **properties) ⇒ Share
Returns a new instance of Share.
88 89 90 91 92 93 |
# File 'lib/cloudfs/share.rb', line 88
def initialize(rest_adapter, ** properties)
fail RestAdapter::Errors::ArgumentError,
'Invalid RestAdapter, input type must be CloudFS::RestAdapter' unless rest_adapter.is_a?(CloudFS::RestAdapter)
@rest_adapter = rest_adapter
set_share_info(** properties)
end
|
Instance Attribute Details
#application_data ⇒ String (readonly)
Returns application data.
29 30 31 |
# File 'lib/cloudfs/share.rb', line 29
def application_data
@application_data
end
|
#date_content_last_modified ⇒ Time (readonly)
Returns modified time.
60 61 62 63 64 65 66 |
# File 'lib/cloudfs/share.rb', line 60
def date_content_last_modified
if @date_content_last_modified
Time.at(@date_content_last_modified)
else
nil
end
end
|
#date_created ⇒ Time (readonly)
Returns creation time.
50 51 52 53 54 55 56 |
# File 'lib/cloudfs/share.rb', line 50
def date_created
if @date_created
Time.at(@date_created)
else
nil
end
end
|
#date_meta_last_modified ⇒ Time (readonly)
Returns modified time.
70 71 72 73 74 75 76 |
# File 'lib/cloudfs/share.rb', line 70
def date_meta_last_modified
if @date_meta_last_modified
Time.at(@date_meta_last_modified)
else
nil
end
end
|
#name ⇒ String (readonly)
Returns name.
14 15 16 |
# File 'lib/cloudfs/share.rb', line 14
def name
@name
end
|
#share_key ⇒ String (readonly)
Returns share_key.
11 12 13 |
# File 'lib/cloudfs/share.rb', line 11
def share_key
@share_key
end
|
#short_url ⇒ String (readonly)
Returns short_url.
23 24 25 |
# File 'lib/cloudfs/share.rb', line 23
def short_url
@short_url
end
|
#size ⇒ String (readonly)
Returns size.
26 27 28 |
# File 'lib/cloudfs/share.rb', line 26
def size
@size
end
|
#type ⇒ String (readonly)
Returns type.
17 18 19 |
# File 'lib/cloudfs/share.rb', line 17
def type
@type
end
|
#url ⇒ String (readonly)
Returns url.
20 21 22 |
# File 'lib/cloudfs/share.rb', line 20
def url
@url
end
|
Instance Method Details
#change_attributes(values, password: nil) ⇒ Boolean
Changes, adds, or removes the share’s password or updates the name.
197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/cloudfs/share.rb', line 197
def change_attributes(values, password: nil)
current_password = values.has_key?('current_password') ? values['current_password'] : password
new_password = values.has_key?('password') ? values['password'] : nil
name = values.has_key?('name') ? values['name'] : nil
response = @rest_adapter.alter_share_info(
@share_key, current_password: current_password, password: new_password, name: name)
set_share_info(** response)
response.has_key?(:share_key)
end
|
#delete ⇒ true
Subsequent operations shall fail
Delete this share
RestAdapter::Errors::InvalidShareError
RestAdapter::Errors::InvalidShareError]
155 156 157 158 159 160 |
# File 'lib/cloudfs/share.rb', line 155
def delete
FileSystemCommon.validate_share_state(self)
@rest_adapter.delete_share(@share_key)
@exists = false
true
end
|
#exists? ⇒ Boolean
Returns whether the share exists, false only if it has been deleted.
125 126 127 |
# File 'lib/cloudfs/share.rb', line 125
def exists?
@exists
end
|
#list ⇒ Array<File, Folder>
List items in this share RestAdapter::Errors::InvalidShareError]
135 136 137 138 139 140 141 142 143 |
# File 'lib/cloudfs/share.rb', line 135
def list
FileSystemCommon.validate_share_state(self)
response = @rest_adapter.browse_share(@share_key).fetch(:items)
FileSystemCommon.create_items_from_hash_array(
response,
@rest_adapter,
parent_state: @parent_state,
in_share: true)
end
|
#receive(path: nil, exists: 'RENAME') ⇒ Array<File, Folder>
Receive contents of this share at specified path in user's filesystem. All items found in share are copied to given location.
RestAdapter::Errors::InvalidShareError]
245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/cloudfs/share.rb', line 245
def receive(path: nil, exists: 'RENAME')
FileSystemCommon.validate_share_state(self)
response = @rest_adapter.receive_share(
@share_key,
path: path,
exists: exists)
FileSystemCommon.create_items_from_hash_array(
response,
@rest_adapter,
parent: path)
end
|
#refresh ⇒ Share
Locally changed properties i.e. name get discarded
raises RestAdapter::Errors::ServiceError if share is locked, unlock share if password is set
Refresh this share to latest state RestAdapter::Errors::InvalidShareError]
269 270 271 272 273 274 |
# File 'lib/cloudfs/share.rb', line 269
def refresh
FileSystemCommon.validate_share_state(self)
response = @rest_adapter.browse_share(share_key).fetch(:share)
set_share_info(** response)
self
end
|
#save(password: nil) ⇒ Share
Save this share's current state. Only name, is committed to this share in user's account
219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/cloudfs/share.rb', line 219
def save(password: nil)
FileSystemCommon.validate_share_state(self)
if @changed_properties[:name]
response = @rest_adapter.alter_share_info(
@share_key,
current_password: password,
name: @changed_properties[:name])
set_share_info(** response)
end
self
end
|
#set_name(new_name, password: nil) ⇒ Object
Set the name of the share
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cloudfs/share.rb', line 34
def set_name(new_name, password: nil)
FileSystemCommon.validate_share_state(self)
fail RestAdapter::Errors::ArgumentError,
'Invalid input, expected new name' if RestAdapter::Utils.is_blank?(new_name)
response = @rest_adapter.alter_share_info(
@share_key,
current_password: password,
name: new_name)
set_share_info(** response)
self
end
|
#set_password(password, current_password: nil) ⇒ Share
Change password of this share
RestAdapter::Errors::InvalidShareError]
173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/cloudfs/share.rb', line 173
def set_password(password, current_password: nil)
FileSystemCommon.validate_share_state(self)
fail RestAdapter::Errors::ArgumentError,
'Invalid input, expected the password' if RestAdapter::Utils.is_blank?(password)
response = @rest_adapter.alter_share_info(
@share_key,
current_password: current_password,
password: password)
set_share_info(** response)
self
end
|