Class: CloudFS::RestAdapter
- Inherits:
-
Object
- Object
- CloudFS::RestAdapter
- Defined in:
- lib/cloudfs/rest_adapter.rb,
lib/cloudfs/client/error.rb,
lib/cloudfs/client/utils.rb,
lib/cloudfs/client/constants.rb,
lib/cloudfs/client/connection.rb
Overview
Defined Under Namespace
Modules: Errors Classes: Connection
Instance Method Summary collapse
-
#alter_file_meta(path, version, version_conflict: 'FAIL', **properties) ⇒ Hash
Alter file metadata.
-
#alter_folder_meta(path, version, version_conflict: 'FAIL', **properties) ⇒ Hash
Alter folder metadata.
-
#alter_share_info(share_key, current_password: nil, password: nil, name: nil) ⇒ Hash
Alter share info changes, adds, or removes the share’s password or updates the name.
-
#authenticate(username, password) ⇒ true
Obtains an OAuth2 access token that authenticates an end-user for this rest_adapter.
-
#browse_share(share_key, path: nil) ⇒ Hash
List files and folders in a share.
-
#browse_trash(path: nil) ⇒ Hash
List files and folders in trash at specified path.
-
#copy_file(path, destination, name, exists: 'RENAME') ⇒ Hash
Copy file to specified destination folder.
-
#copy_folder(path, destination, name, exists: 'FAIL') ⇒ Hash
Copy folder to specified destination folder.
-
#create_account(username, password, email: nil, first_name: nil, last_name: nil) ⇒ Hash
Creates a new end-user account for a Paid CloudFS (developer’s) account.
-
#create_folder(name, path: nil, exists: 'FAIL') ⇒ Hash
Create folder at specified destination path in end-user's account.
-
#create_share(paths, password: nil) ⇒ Hash
Creates a share of locations specified by the passed list of paths.
-
#delete_file(path, commit: false) ⇒ Hash
Delete file.
- #delete_folder(path, commit: false, force: false) ⇒ Object
-
#delete_share(share_key) ⇒ Hash
Deletes the user created share.
-
#delete_trash_item(path: nil) ⇒ Hash
Delete trash item.
-
#download(path, startbyte: 0, bytecount: 0) {|String| ... } ⇒ String
Download file.
-
#download_url(path) ⇒ String
Get the download URL of the file.
-
#get_file_meta(path) ⇒ Hash
Get file meta.
-
#get_folder_meta(path) ⇒ Hash
Get folder meta.
-
#get_item_meta(path) ⇒ Hash
Get item meta.
-
#get_profile ⇒ Hash
Get cloudfs end-user profile information.
-
#initialize(clientid, secret, host, **params) ⇒ RestAdapter
constructor
Creates RestAdapter instance that manages rest api calls to CloudFS service.
-
#linked? ⇒ Boolean
Whether rest_adapter can make authenticated requests to cloudfs service.
-
#list_file_versions(path, start_version: 0, stop_version: nil, limit: 10) ⇒ Array<Hash>
List versions of file.
-
#list_folder(path: nil, depth: nil, filter: nil, strict_traverse: false) ⇒ Array<Hash>
Errors::ArgumentError].
-
#list_history(start: -10,, stop: nil) ⇒ Array<Hash>
List the history of file, folder, and share actions.
-
#list_shares ⇒ Array<Hash>
Lists the metadata of the shares the authenticated user has created.
-
#list_single_file_version(path, version) ⇒ Hash
List specified version of file.
-
#move_file(path, destination, name, exists: 'RENAME') ⇒ Hash
Move file to specified destination folder.
- #move_folder(path, destination, name, exists: 'FAIL') ⇒ Object
-
#ping ⇒ Object
Ping cloudfs server to verifies the end-user’s access token.
-
#promote_file_version(path, version) ⇒ Hash
Given a specified version, set that version’s metadata to current metadata for the file, creating a new version in the process.
-
#receive_share(share_key, path: nil, exists: 'RENAME') ⇒ Array<Hash>
Add contents of share to user's filesystem.
-
#recover_trash_item(path, restore: 'FAIL', destination: nil) ⇒ Object
Recover trash item.
-
#unlink ⇒ Object
Unlinks this rest_adapter object from cloudfs user's account.
-
#unlock_share(share_key, password) ⇒ Object
Unlock share.
-
#upload(path, source, name: nil, exists: 'FAIL') ⇒ Hash
Upload file.
Constructor Details
#initialize(clientid, secret, host, **params) ⇒ RestAdapter
Creates RestAdapter instance that manages rest api calls to CloudFS service
default is 16KB. Configurable keep alive timeout for persistent connections in connection pool, default is 15 seconds. Async api support
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/cloudfs/rest_adapter.rb', line 76
def initialize(clientid, secret, host, ** params)
fail Errors::ArgumentError,
'Invalid argument provided' if (Utils.is_blank?(clientid) ||
Utils.is_blank?(secret) || Utils.is_blank?(host))
@clientid = "#{clientid}"
@secret = "#{secret}"
@host = /https:\/\// =~ host ? "#{host}" :
"#{Constants::URI_PREFIX_HTTPS}#{host}"
@access_token = nil
connect_timeout, send_timeout, receive_timeout, max_retries, http_debug =
params.values_at(
:connect_timeout,
:send_timeout,
:receive_timeout,
:max_retries,
:http_debug)
connect_timeout ||= 60
send_timeout ||= 0
receive_timeout ||= 120
max_retries ||= 3
@http_connection = Connection.new(
connect_timeout: connect_timeout,
send_timeout: send_timeout,
receive_timeout: receive_timeout,
max_retries: max_retries, debug_dev: http_debug,
agent_name: "#{Constants::HTTP_AGENT_NAME} (#{CloudFS::VERSION})")
end
|
Instance Method Details
#alter_file_meta(path, version, version_conflict: 'FAIL', **properties) ⇒ Hash
Alter file metadata
586 587 588 589 |
# File 'lib/cloudfs/rest_adapter.rb', line 586
def alter_file_meta(path, version, version_conflict: 'FAIL', ** properties)
alter_meta(Constants::ENDPOINT_FILES, path, version,
version_conflict: version_conflict, ** properties)
end
|
#alter_folder_meta(path, version, version_conflict: 'FAIL', **properties) ⇒ Hash
Alter folder metadata
563 564 565 566 |
# File 'lib/cloudfs/rest_adapter.rb', line 563
def alter_folder_meta(path, version, version_conflict: 'FAIL', ** properties)
alter_meta(Constants::ENDPOINT_FOLDERS, path, version,
version_conflict: version_conflict, ** properties)
end
|
#alter_share_info(share_key, current_password: nil, password: nil, name: nil) ⇒ Hash
Alter share info changes, adds, or removes the share’s password or updates the name
982 983 984 985 986 987 988 989 990 991 992 993 994 995 |
# File 'lib/cloudfs/rest_adapter.rb', line 982
def alter_share_info(share_key, current_password: nil,
password: nil, name: nil)
fail Errors::ArgumentError,
'Invalid argument, must pass valid path' if Utils.is_blank?(share_key)
uri = set_uri_params(Constants::ENDPOINT_SHARES, name: share_key,
operation: 'info')
form = {}
form[:current_password] = current_password if current_password
form[:password] = password if password
form[:name] = name unless Utils.is_blank?(name)
request('POST', uri: uri, body: form)
end
|
#authenticate(username, password) ⇒ true
Obtains an OAuth2 access token that authenticates an end-user for this rest_adapter
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/cloudfs/rest_adapter.rb', line 139
def authenticate(username, password)
fail Errors::ArgumentError,
'Invalid argument, must pass username' if Utils.is_blank?(username)
fail Errors::ArgumentError,
'Invalid argument, must pass password' if Utils.is_blank?(password)
date = Time.now.utc.strftime(Constants::DATE_FORMAT)
form = {
Constants::PARAM_GRANT_TYPE => Constants::PARAM_PASSWORD,
Constants::PARAM_PASSWORD => password,
Constants::PARAM_USER => username
}
headers = {
Constants::HEADER_CONTENT_TYPE =>
Constants::CONTENT_TYPE_APP_URLENCODED,
Constants::HEADER_DATE => date
}
uri = {endpoint: Constants::ENDPOINT_OAUTH}
signature = Utils.generate_auth_signature(Constants::ENDPOINT_OAUTH,
form, headers, @secret)
headers[Constants::HEADER_AUTHORIZATION] =
"#{Constants::HEADER_AUTH_PREFIX_BCS} #{@clientid}:#{signature}"
access_info = request('POST', uri: uri, header: headers, body: form)
@access_token = access_info.fetch(:access_token)
true
end
|
#browse_share(share_key, path: nil) ⇒ Hash
List files and folders in a share
900 901 902 903 904 905 906 907 908 909 |
# File 'lib/cloudfs/rest_adapter.rb', line 900
def browse_share(share_key, path: nil)
fail Errors::ArgumentError,
'Invalid argument, must pass valid path' if Utils.is_blank?(share_key)
uri = set_uri_params(Constants::ENDPOINT_SHARES,
name: "#{share_key}#{path}", operation: 'meta')
request('GET', uri: uri,
header: Constants::HEADER_CONTENT_TYPE_APP_URLENCODED)
end
|
#browse_trash(path: nil) ⇒ Hash
List files and folders in trash at specified path
root of trash
representing list of items under browsed item if folder -
{ :meta => Hash, :items =>
1027 1028 1029 1030 1031 |
# File 'lib/cloudfs/rest_adapter.rb', line 1027
def browse_trash(path: nil)
uri = set_uri_params(Constants::ENDPOINT_TRASH, name: path)
request('GET', uri: uri,
header: Constants::HEADER_CONTENT_TYPE_APP_URLENCODED)
end
|
#copy_file(path, destination, name, exists: 'RENAME') ⇒ Hash
Copy file to specified destination folder
380 381 382 |
# File 'lib/cloudfs/rest_adapter.rb', line 380
def copy_file(path, destination, name, exists: 'RENAME')
copy(Constants::ENDPOINT_FILES, path, destination, name, exists: exists)
end
|
#copy_folder(path, destination, name, exists: 'FAIL') ⇒ Hash
Copy folder to specified destination folder
363 364 365 |
# File 'lib/cloudfs/rest_adapter.rb', line 363
def copy_folder(path, destination, name, exists: 'FAIL')
copy(Constants::ENDPOINT_FOLDERS, path, destination, name, exists: exists)
end
|
#create_account(username, password, email: nil, first_name: nil, last_name: nil) ⇒ Hash
Creates a new end-user account for a Paid CloudFS (developer’s) account
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/cloudfs/rest_adapter.rb', line 191
def create_account(username, password, email: nil,
first_name: nil, last_name: nil)
fail Errors::ArgumentError,
'Invalid argument, must pass username' if Utils.is_blank?(username)
fail Errors::ArgumentError,
'Invalid argument, must pass password' if Utils.is_blank?(password)
date = Time.now.utc.strftime(Constants::DATE_FORMAT)
form = {
Constants::PARAM_PASSWORD => password,
Constants::PARAM_USER => username
}
form[Constants::PARAM_EMAIL] = email unless Utils.is_blank?(email)
form[Constants::PARAM_FIRST_NAME] =
first_name unless Utils.is_blank?(first_name)
form[Constants::PARAM_LAST_NAME] =
last_name unless Utils.is_blank?(last_name)
headers = {
Constants::HEADER_CONTENT_TYPE =>
Constants::CONTENT_TYPE_APP_URLENCODED,
Constants::HEADER_DATE => date
}
uri = {endpoint: Constants::ENDPOINT_CUSTOMERS}
signature = Utils.generate_auth_signature(Constants::ENDPOINT_CUSTOMERS,
form, headers, @secret)
headers[Constants::HEADER_AUTHORIZATION] =
"#{Constants::HEADER_AUTH_PREFIX_BCS} #{@clientid}:#{signature}"
request('POST', uri: uri, header: headers, body: form)
end
|
#create_folder(name, path: nil, exists: 'FAIL') ⇒ Hash
Create folder at specified destination path in end-user's account
248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/cloudfs/rest_adapter.rb', line 248
def create_folder(name, path: nil, exists: 'FAIL')
fail Errors::ArgumentError,
'Invalid argument, must pass name' if Utils.is_blank?(name)
exists = Constants::EXISTS.fetch(exists.to_sym) {
fail Errors::ArgumentError, 'Invalid value for exists' }
uri = set_uri_params(Constants::ENDPOINT_FOLDERS, name: path)
query = {operation: Constants::QUERY_OPS_CREATE}
form = {name: name, exists: exists}
response = request('POST', uri: uri, query: query, body: form)
items = response.fetch(:items)
items.first
end
|
#create_share(paths, password: nil) ⇒ Hash
Creates a share of locations specified by the passed list of paths
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
# File 'lib/cloudfs/rest_adapter.rb', line 855
def create_share(paths, password: nil)
fail Errors::ArgumentError,
'Invalid argument, must pass valid list of paths' if Utils.is_blank?(paths)
body = [*paths].map { |path|
path = prepend_path_with_forward_slash(path)
"path=#{Utils.urlencode(path)}" }.join('&')
unless password.nil?
body += "&password=#{password}"
end
uri = {endpoint: Constants::ENDPOINT_SHARES}
request('POST', uri: uri, body: body)
end
|
#delete_file(path, commit: false) ⇒ Hash
Delete file
316 317 318 |
# File 'lib/cloudfs/rest_adapter.rb', line 316
def delete_file(path, commit: false)
delete(Constants::ENDPOINT_FILES, path, commit: commit)
end
|
#delete_folder(path, commit: false, force: false) ⇒ Object
302 303 304 |
# File 'lib/cloudfs/rest_adapter.rb', line 302
def delete_folder(path, commit: false, force: false)
delete(Constants::ENDPOINT_FOLDERS, path, commit: commit, force: force)
end
|
#delete_share(share_key) ⇒ Hash
Deletes the user created share
880 881 882 883 884 885 886 887 888 |
# File 'lib/cloudfs/rest_adapter.rb', line 880
def delete_share(share_key)
fail Errors::ArgumentError,
'Invalid argument, must pass valid share key' if Utils.is_blank?(share_key)
uri = set_uri_params(Constants::ENDPOINT_SHARES, name: "#{share_key}/")
request('DELETE', uri: uri,
header: Constants::HEADER_CONTENT_TYPE_APP_URLENCODED)
end
|
#delete_trash_item(path: nil) ⇒ Hash
Delete trash item
expected behaviour is to delete all items in trash
1044 1045 1046 1047 1048 |
# File 'lib/cloudfs/rest_adapter.rb', line 1044
def delete_trash_item(path: nil)
uri = set_uri_params(Constants::ENDPOINT_TRASH, name: path)
request('DELETE', uri: uri,
header: Constants::HEADER_CONTENT_TYPE_APP_URLENCODED)
end
|
#download(path, startbyte: 0, bytecount: 0) {|String| ... } ⇒ String
Download file
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 |
# File 'lib/cloudfs/rest_adapter.rb', line 724
def download(path, startbyte: 0, bytecount: 0, &block)
fail Errors::ArgumentError,
'Invalid argument, must pass path' if Utils.is_blank?(path)
fail Errors::ArgumentError,
'Size must be positive' if (bytecount < 0 || startbyte < 0)
uri = set_uri_params(Constants::ENDPOINT_FILES, name: path)
header = Constants::HEADER_CONTENT_TYPE_APP_URLENCODED.dup
unless startbyte == 0 && bytecount == 0
if bytecount == 0
header[:Range] = "bytes=#{startbyte}-"
else
header[:Range] = "bytes=#{startbyte}-#{startbyte + bytecount - 1}"
end
end
request('GET', uri: uri, header: header, &block)
end
|
#download_url(path) ⇒ String
Get the download URL of the file.
RestAdapter::Errors::ArgumentError,
RestAdapter::Errors::InvalidItemError, RestAdapter::Errors::OperationNotAllowedError]
753 754 755 756 757 758 759 760 |
# File 'lib/cloudfs/rest_adapter.rb', line 753
def download_url(path)
uri = set_uri_params(Constants::ENDPOINT_FILES, name: path)
header = {
Constants::HEADER_REDIRECT => false
}.merge(Constants::HEADER_CONTENT_TYPE_APP_URLENCODED.dup)
request('GET', uri: uri, header: header)
end
|
#get_file_meta(path) ⇒ Hash
Get file meta
508 509 510 |
# File 'lib/cloudfs/rest_adapter.rb', line 508
def get_file_meta(path)
get_meta(Constants::ENDPOINT_FILES, path)
end
|
#get_folder_meta(path) ⇒ Hash
Get folder meta
496 497 498 |
# File 'lib/cloudfs/rest_adapter.rb', line 496
def get_folder_meta(path)
get_meta(Constants::ENDPOINT_FOLDERS, path)
end
|
#get_item_meta(path) ⇒ Hash
Get item meta
520 521 522 |
# File 'lib/cloudfs/rest_adapter.rb', line 520
def get_item_meta(path)
get_meta(Constants::ENDPOINT_ITEM, path)
end
|
#get_profile ⇒ Hash
Get cloudfs end-user profile information
229 230 231 232 233 234 |
# File 'lib/cloudfs/rest_adapter.rb', line 229
def get_profile
uri = {endpoint: Constants::ENDPOINT_USER_PROFILE}
request('GET', uri: uri,
header: Constants::HEADER_CONTENT_TYPE_APP_URLENCODED)
end
|
#linked? ⇒ Boolean
Returns whether rest_adapter can make authenticated requests to cloudfs service.
111 112 113 114 115 116 |
# File 'lib/cloudfs/rest_adapter.rb', line 111
def linked?
ping
true
rescue Errors::SessionNotLinked
false
end
|
#list_file_versions(path, start_version: 0, stop_version: nil, limit: 10) ⇒ Array<Hash>
List versions of file
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 |
# File 'lib/cloudfs/rest_adapter.rb', line 826
def list_file_versions(path, start_version: 0, stop_version: nil, limit: 10)
fail Errors::ArgumentError,
'Invalid argument, must pass valid path' if Utils.is_blank?(path)
uri = set_uri_params(Constants::ENDPOINT_FILES, name: path,
operation: 'versions')
query = {
:'start-version' => start_version, :'limit' => limit
}
query[:'stop-version'] = stop_version if stop_version
request('GET', uri: uri, query: query,
header: Constants::HEADER_CONTENT_TYPE_APP_URLENCODED)
end
|
#list_folder(path: nil, depth: nil, filter: nil, strict_traverse: false) ⇒ Array<Hash>
accept filter array, return { meta: Hash, items: Array
Errors::ArgumentError]
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/cloudfs/rest_adapter.rb', line 275
def list_folder(path: nil, depth: nil, filter: nil, strict_traverse: false)
fail Errors::ArgumentError,
'Invalid argument must pass strict_traverse of type boolean' unless !!strict_traverse == strict_traverse
uri = set_uri_params(Constants::ENDPOINT_FOLDERS, name: path)
query = {}
query = {depth: depth} if depth
unless Utils.is_blank?(filter)
query[:filter] = filter
query[:'strict-traverse'] = "#{strict_traverse}"
end
response = request('GET', uri: uri, query: query)
response.fetch(:items)
end
|
#list_history(start: -10,, stop: nil) ⇒ Array<Hash>
List the history of file, folder, and share actions
actions from, default -10. It can be negative in order to get most recent actions. from (non-inclusive)
1008 1009 1010 1011 1012 1013 1014 1015 |
# File 'lib/cloudfs/rest_adapter.rb', line 1008
def list_history(start: -10, stop: nil)
uri = {endpoint: Constants::ENDPOINT_HISTORY}
query = {start: start}
query[:stop] = stop if stop
request('GET', uri: uri, query: query,
header: Constants::HEADER_CONTENT_TYPE_APP_URLENCODED)
end
|
#list_shares ⇒ Array<Hash>
Lists the metadata of the shares the authenticated user has created
916 917 918 919 920 921 |
# File 'lib/cloudfs/rest_adapter.rb', line 916
def list_shares
uri = {endpoint: Constants::ENDPOINT_SHARES}
request('GET', uri: uri,
header: Constants::HEADER_CONTENT_TYPE_APP_URLENCODED)
end
|
#list_single_file_version(path, version) ⇒ Hash
List specified version of file
774 775 776 777 778 779 780 781 782 783 784 785 |
# File 'lib/cloudfs/rest_adapter.rb', line 774
def list_single_file_version(path, version)
fail Errors::ArgumentError,
'Invalid argument, must pass valid path' if Utils.is_blank?(path)
fail Errors::ArgumentError,
'Invalid argument, must pass valid path' unless version.is_a?(Fixnum)
uri = set_uri_params(Constants::ENDPOINT_FILES, name: path,
operation: "versions/#{version}")
request('GET', uri: uri,
header: Constants::HEADER_CONTENT_TYPE_APP_URLENCODED)
end
|
#move_file(path, destination, name, exists: 'RENAME') ⇒ Hash
Move file to specified destination folder
448 449 450 |
# File 'lib/cloudfs/rest_adapter.rb', line 448
def move_file(path, destination, name, exists: 'RENAME')
move(Constants::ENDPOINT_FILES, path, destination, name, exists: exists)
end
|
#move_folder(path, destination, name, exists: 'FAIL') ⇒ Object
431 432 433 |
# File 'lib/cloudfs/rest_adapter.rb', line 431
def move_folder(path, destination, name, exists: 'FAIL')
move(Constants::ENDPOINT_FOLDERS, path, destination, name, exists: exists)
end
|
#ping ⇒ Object
Ping cloudfs server to verifies the end-user’s access token
174 175 176 177 178 |
# File 'lib/cloudfs/rest_adapter.rb', line 174
def ping
request('GET', uri: {endpoint: Constants::ENDPOINT_PING},
header: Constants::HEADER_CONTENT_TYPE_APP_URLENCODED)
true
end
|
#promote_file_version(path, version) ⇒ Hash
Given a specified version, set that version’s metadata to current metadata for the file, creating a new version in the process
797 798 799 800 801 802 803 804 805 806 807 808 |
# File 'lib/cloudfs/rest_adapter.rb', line 797
def promote_file_version(path, version)
fail Errors::ArgumentError,
'Invalid argument, must pass valid path' if Utils.is_blank?(path)
fail Errors::ArgumentError,
'Invalid argument, must pass valid version' unless version.is_a?(Fixnum)
uri = set_uri_params(Constants::ENDPOINT_FILES, name: path,
operation: "versions/#{version}")
query = {operation: Constants::QUERY_OPS_PROMOTE}
request('POST', uri: uri, query: query)
end
|
#receive_share(share_key, path: nil, exists: 'RENAME') ⇒ Array<Hash>
Add contents of share to user's filesystem
934 935 936 937 938 939 940 941 942 943 944 945 |
# File 'lib/cloudfs/rest_adapter.rb', line 934
def receive_share(share_key, path: nil, exists: 'RENAME')
fail Errors::ArgumentError,
'Invalid argument, must pass valid share key' if Utils.is_blank?(share_key)
exists = Constants::EXISTS.fetch(exists.to_sym) {
fail Errors::ArgumentError, 'Invalid value for exists' }
uri = set_uri_params(Constants::ENDPOINT_SHARES, name: "#{share_key}/")
form = {exists: exists}
form[:path] = path unless Utils.is_blank?(path)
request('POST', uri: uri, body: form)
end
|
#recover_trash_item(path, restore: 'FAIL', destination: nil) ⇒ Object
Recover trash item
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 |
# File 'lib/cloudfs/rest_adapter.rb', line 1061
def recover_trash_item(path, restore: 'FAIL', destination: nil)
fail Errors::ArgumentError,
'Invalid argument, must pass valid path' if Utils.is_blank?(path)
restore = Constants::RESTORE_METHOD.fetch(restore.to_sym) {
fail Errors::ArgumentError, 'Invalid value for restore' }
uri = set_uri_params(Constants::ENDPOINT_TRASH, name: path)
form = {:'restore' => restore}
if restore == Constants::RESTORE_METHOD[:RESCUE]
unless Utils.is_blank?(destination)
destination = prepend_path_with_forward_slash(destination)
form[:'rescue-path'] = destination
end
elsif restore == Constants::RESTORE_METHOD[:RECREATE]
unless Utils.is_blank?(destination)
destination = prepend_path_with_forward_slash(destination)
form[:'recreate-path'] = destination
end
end
request('POST', uri: uri, body: form)
end
|
#unlink ⇒ Object
this will disconnect all keep alive connections and internal
Unlinks this rest_adapter object from cloudfs user's account
sessions
122 123 124 125 126 127 128 |
# File 'lib/cloudfs/rest_adapter.rb', line 122
def unlink
if @access_token
@access_token = ''
@http_connection.unlink
end
true
end
|
#unlock_share(share_key, password) ⇒ Object
Unlock share
954 955 956 957 958 959 960 961 962 963 964 965 |
# File 'lib/cloudfs/rest_adapter.rb', line 954
def unlock_share(share_key, password)
fail Errors::ArgumentError,
'Invalid argument, must pass valid path' if Utils.is_blank?(share_key)
fail Errors::ArgumentError,
'Invalid argument, must pass valid path' if Utils.is_blank?(password)
uri = set_uri_params(Constants::ENDPOINT_SHARES, name: share_key,
operation: 'unlock')
form = {password: password}
request('POST', uri: uri, body: form)
end
|
#upload(path, source, name: nil, exists: 'FAIL') ⇒ Hash
reuse fallback and reuse attributes
name must be set if source does not respond to #path
Upload file
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
# File 'lib/cloudfs/rest_adapter.rb', line 669
def upload(path, source, name: nil, exists: 'FAIL')
exists = Constants::EXISTS.fetch(exists.to_sym) {
fail Errors::ArgumentError, 'Invalid value for exists' }
if source.respond_to?(:path)
name ||= ::File.basename(source.path)
elsif Utils.is_blank?(name)
fail Errors::ArgumentError, 'Invalid argument, custom name is required if source does not respond to path'
end
if source.respond_to?(:pos) && source.respond_to?(:pos=)
original_pos = source.pos
# Setting source offset to start of stream
source.pos=0
end
uri = set_uri_params(Constants::ENDPOINT_FILES, name: path)
form = {file: source, exists: exists}
form[:name] = name
headers = {
Constants::HEADER_CONTENT_TYPE => Constants::CONTENT_TYPE_MULTI
}
begin
request('POST', uri: uri, header: headers, body: form)
ensure
# Reset source offset to original position
source.pos=original_pos if source.respond_to?(:pos=)
end
end
|