Class: Fileops

Version 1.1 - Updated on 8/11/2016

Contents

Constructor Details

#initialize(session) ⇒ Fileops

Returns a new instance of Fileops.

def initialize(session)  
  # Instance variables  
  @session = session  
end

Instance Method Details

create_folder

#create_folder(folderdata) ⇒ Object

Create a folder.

  • Arguments:

    • folderdata: Folder data in the json format (name, path, override).
  • Returns:

    • A hash with the metadata of the newly created folder.
def create_folder(folderdata)
  params = folderdata
  headers = {'Content-Type' => 'application/json'}
  response = @session.do_post "fops/createfolder", params, headers
  Sdk::parse_response(response)
end

NOTE:
You cannot perform the create_folder operation on a virutal folder.

file_copy

#file_copy(src, target, safe = 'false', conflictsolve = 'copy', override = 'overwrite') ⇒ Object

Copy a file or folder to a new location.

  • Arguments:

    • src: The path to the file or folder to be copied.
    • target: The destination path of the file or folder to be copied.
    • safe: Optional.
    • conflictsolve: Optional.
    • override: Optional.
  • Returns:

    • A hash with the metadata of the new copy of the file or folder.
def file_copy(src,target, safe = 'false',conflictsolve = 'copy',override = 'overwrite')
  params = {
    "src" => src,
    "target" => target,
    "safe" => safe.to_s,
    "conflictsolve" => conflictsolve.to_s,
    "override" => override.to_s,
  }
  
  params = JSON.generate(params)
  headers = {'Content-Type' => 'application/json'}
  response = @session.do_post "fops/copy", params, headers
  Sdk::parse_response(response)
end

NOTE:
You cannot perform the file_copy operation on a virutal folder.

file_delete

#file_delete(path, purge = 'false') ⇒ Object

Deletes a file.

  • Arguments:

    • path: The path of the file to delete
  • Returns:

    • A Hash with the metadata of file just deleted.
def file_delete(path,purge='false')
  params = {
    "path" => format_path(path, false),
    "purge" => purge,
  }
  response = @session.do_delete_with_params "fops/delete", params
  Sdk::parse_response(response, raw=true)
end

NOTE:
You cannot perform the file_delete operation on a virutal folder.

file_move

#file_move(src, target, safe = 'false', conflictsolve = 'copy') ⇒ Object

Moves a file or folder.

  • Arguments:

    • src: The path of the file to be moved
    • target: The destination path of the file or folder to be moved
    • safe: Optional.
    • conflictsolve: Optional.
  • Returns:

    • A Hash with the metadata of file or folder just moved.
def file_move(src,target, safe = 'false',conflictsolve = 'copy')
	params = {
    "src" => src,
    "target" => target,
    "safe" => safe.to_s,
    "conflictsolve" => conflictsolve.to_s,
  }
  
  params = JSON.generate(params)
  headers = {'Content-Type' => 'application/json'}
  response = @session.do_post "fops/move", params, headers
  Sdk::parse_response(response)    
end

NOTE:
You cannot perform the file_move operation on a virutal folder.

fileorfolder_rename

#fileorfolder_rename(src, target, safe = 'false', conflictsolve = 'copy') ⇒ Object

Rename a file or a folder.

  • Arguments:

    • src: The path of the file to be moved
    • target: The destination path of the file or folder to be moved
    • safe: Optional.
    • conflictsolve: Optional.
  • Returns:

    • A Hash with the metadata of the file or the folder just renamed.
def fileorfolder_rename(src,target, safe = 'false',conflictsolve = 'copy')
	params = {
    "src" => src,
    "target" => target,
    "safe" => safe.to_s,
    "conflictsolve" => conflictsolve.to_s,
  }
  
  params = JSON.generate(params)
  headers = {'Content-Type' => 'application/json'}
  response = @session.do_post "fops/rename", params, headers
  Sdk::parse_response(response)    
end

NOTE:
You cannot perform the fileorfolder_rename operation on a virutal folder.

fileUploadIntent

#fileUploadIntent(path, name, size, checksum, chunk = 'false') ⇒ Object

Initiates a file upload intent request.

  • Arguments:

    • path: The path to the folder where the file is to be uploaded.
    • name: Name of the file to be uploaded.
    • size: Size of the file to be uploaded.
    • checksum: Checksum of the file or chunk.
    • chunk:
      • Set to false, if the file binary is to be uploaded with a single request.
      • Set to true when file binary is to be uploaded in multiple requests.
  • Returns:

    • A Hash object with the file upload URL and the file commit URL if the file is uploaded in chunk.
def fileUploadIntent(path, name, size, checksum, chunk = 'false')
  params = {
    "path" => path.to_s,
    "name" => name.to_s,
    "size" => size,
    "checksum" => checksum,
 "chunk" => chunk.to_s
  }
  response = @session.do_get "fileupload/intent", params
  if response.kind_of? Net::HTTPRedirection
    raise SdkNotModified.new("metadata not modified")
  end
  Sdk::parse_response(response)
end

NOTE:
You cannot perform the fileUploadIntent operation on a virutal folder.

format_path

#format_path(path, escape = true) ⇒ Object

def format_path(path, escape=true) # :nodoc:
  path = path.gsub(/\/+/,"/")
  # replace multiple slashes with a single one

  path = path.gsub(/^\/?/,"/")
  # ensure the path starts with a slash

  path.gsub(/\/?$/,"")
  # ensure the path doesn't end with a slash

  return URI.escape(path, RESERVED_CHARACTERS) if escape
  path
end

fullview

#fullview(virtualfolder, xheaderetag) ⇒ Object

Full view of the user’s Personal Cloud Storage Account - includes the information about all files and folders stored in the user’s Personal Cloud Storage Account.

  • Arguments:

    • virtualfolder: Optional. Folder that represents various client types at the root level and contains their respective data.
    • -Header-ETag: Optional. Request only changes since a previous call to fullview.
  • Returns:

    • A Hash object with a list of the metadata of the files or folders matching the specified query.
def fullview(virtualfolder, xheaderetag)
  params = {
 'virtualfolder' => virtualfolder.to_s,
    "X-Header-ETag" => xheaderetag.to_s
  }
  response = @session.do_get "fullview", params
  Sdk::parse_response(response)
end

get_file

#get_file(from_path) ⇒ Object

Returns the content of the file at the specified path.

  • Arguments:

    • from_path: The path to the file to be downloaded.
  • Returns:

    • The file content.
def get_file(from_path)
  response = get_file_impl(from_path)
  Sdk::parse_response(response, raw=true)
end

metadata

#metadata(path, include_deleted = false, sort = 'name+asc', start = "", count = "", filter = '') ⇒ Object

Retrives the metadata for a file or folder.

  • Arguments:

    • path: Optional. The path to the file or folder.
    • include_deleted: Optional. Specifies whether to include deleted files in metadata results.
    • sort: Optional. Sort order for response
    • start: Optional. Starting point for partial responses, for folder requests. Default is 1.
    • count: Optional. Maximum items to include in a paginated response, for folder requests. Required if start is specified.
    • filter: Optional. Set to file or folder, to include only those types of items in the response.
  • Returns:

    • A Hash object with the metadata of the file or folder (and contained files if appropriate).
def metadata(path, include_deleted=false, sort='name+asc', start="", count="", filter='' )
  params = {
    "include_deleted" => include_deleted.to_s,
    "sort" => sort.to_s,
    "start" => start,
    "count" => count,
 "filter" => filter.to_s
  }
  response = @session.do_get "metadata#{format_path(path)}", params
  if response.kind_of? Net::HTTPRedirection
    raise SdkNotModified.new("metadata not modified")
  end
  Sdk::parse_response(response)
end

purgetrash

#purgetrash(virtualfolder) ⇒ Object

Purges the files and folders that are in a deleted state in the user’s Personal Storage Account.

  • Arguments:

    • virtualfolder: Folder that represents various client types at the root level and contains their respective data.
  • Returns:

    • A Hash object.
def purgetrash(virtualfolder)
  params = { 'virtualfolder' => virtualfolder }
  headers = {'Content-Type' => 'application/json'}
  response = @session.do_delete_with_params "trash", params, headers
  Sdk::parse_response(response)
end

restore

#restore(path) ⇒ Object

Restore a file to a previous revision.

  • Arguments:

    • path: Request object to restore files or folders from trash.
  • Returns:

    • A Hash object.
def restore(path)
  params = path
  headers = {'Content-Type' => 'application/json'}
  response = @session.do_post "fops/restore", params, headers
  Sdk::parse_response(response, raw=true)
end

#search(query, path, sort = 'name+asc', start = 1, count = '') ⇒ Object

Search the directory for files and folders that match the specified query.

  • Arguments:

    • query: Contains the text to be searched and supports a number of query fields that allow clients to restrict the search to particular parts of a file’s or folder’s metadata query
    • path: Optional. Folder that represents various client types at the root level and contains their respective data.
    • sort: Optional. Specify sort order for response
    • start: Optional. Page number to return, for paginated responses. Default is 1.
    • count: Optional. Maximum items to include in a paginated response, for folder requests. Required if start is specified.
  • Returns:

    • A Hash object with a list the metadata of the files and folders matching query.
def search(query,path, sort='name+asc', start=1, count='')
  params = {
    'query' => query,
 'virtualfolder' => path,
    "sort" => sort.to_s,
    "start" => start.to_i,
    "count" => count.to_i
  }
  response = @session.do_get "search", params
  Sdk::parse_response(response)
end

thumbnail

#thumbnail(content_token, size = 'x', th = 100, tw = 100) ⇒ Object

Retrieves a thumbnail for an image.

  • Arguments:

    • content_token: The path to the file to be thumbnailed.
    • size: A string describing the desired thumbnail size.
    • th: thumnail height
    • tw: thumnail width
  • Returns:

    • The thumbnail data.
def thumbnail(content_token, size='x', th= 100 , tw = 100)
  response = thumbnail_impl(content_token, size, th, tw)
  Sdk::parse_response(response, raw=true)
end

trash

#trash(path, sort = 'name+asc', start = 1, count = '', filter = '', deep = false) ⇒ Object

Retrieves the list of files and folders that have been deleted from a user’s Personal Cloud Storage.

  • Arguments:

    • path: (virtualfolder) Folder that represents various client types at the root level and contains their respective data.
    • sort: Controls the sort order in which the response is returned.
    • start: Starting point for partial responses, for folder requests. Default is 1.
    • count: Maximum items to include in a paginated response, for folder requests.
    • filter: Set to file or folder, to include only those types of items in the response.
    • deep: Specifies whether the search should stop at the topmost deleted item in the tree.
  • Returns:

    • A Hash object
def trash(path, sort='name+asc', start=1, count='', filter= '' , deep = false)
  params = {
 'virtualfolder' => path,
    "sort" => sort.to_s,
    "start" => start.to_i,
    "count" => count.to_i,
 "filter" => filter.to_s,
    "deep" => deep.to_s
  }
  response = @session.do_get "trash", params
  Sdk::parse_response(response)
end

upload_chunk_data

#upload_chunk_data(uploadurl, offset, file_obj) ⇒ Object

Uploads chunk data.

  • Arguments:

    • uploadurl: Upload url.
    • offset: offset of file.
    • binarydata: Binary Data of file.
  • Returns:

    • A hash object.
def upload_chunk_data(uploadurl, offset, file_obj)
  uploadurldata = uploadurl.split(/\//)
  logger = Logger.new(STDOUT)
  uploadurldata = uploadurldata.last
  uploadid = uploadurldata.split('?')
  uploadid = uploadid.first
  logger.info file_obj
  params = {
    "chunk" => true,
    "offset" => offset
  }
  headers = {'Content-Type' => 'application/octet-stream','Content-Transfer-Encoding' => 'binary'}
  response = @session.do_post_with_body 'upload/'+uploadid, params, headers,file_obj, :content
  #logger.info response
  Sdk::parse_response(response,raw=true)
end

NOTE:
You cannot perform the upload_chunk_data operation on a virutal folder.

upload_data

#upload_data(uploadurl, checksum, file_obj) ⇒ Object

Upload complete file.

  • Arguments:

    • uploadurl: Upload URL.
    • checksum: Checksum of a file.
    • binarydata: Binary Data of a file.
  • Returns:

    • A hash object.
def upload_data(uploadurl, checksum, file_obj)
  uploadurldata = uploadurl.split(/\//)
  logger = Logger.new(STDOUT)
  uploadurldata = uploadurldata.last
  uploadid = uploadurldata.split('?')
  uploadid = uploadid.first
  
  params = {
    "chunk" => false,
    "checksum" => checksum     
  }
  headers = {'Content-Type' => 'application/octet-stream','Content-Transfer-Encoding' => 'binary'}
  response = @session.do_post_with_body 'upload/'+uploadid, params, headers,file_obj, :content
  Sdk::parse_response(response)
end

NOTE:
You cannot perform the upload_data operation on a virutal folder.

uploadCommit

#uploadCommit(uploadurl) ⇒ Object

Indicates that the file content upload is complete, and the file should be created.

  • Arguments:

    • uploadid: upload id of the file.
  • Returns:

    • A hash object.
def uploadCommit(uploadurl)
  uploadurldata = uploadurl.split(/\//)
  
  uploadurldata = uploadurldata.last
  uploadid = uploadurldata.split('?')
  uploadid = uploadid.first
  
  headers = {'Content-Type' => 'application/json'}
  response = @session.do_post_without_params 'commit/'+uploadid, headers
  Sdk::parse_response(response)
end

NOTE:
You cannot perform the uploadCommit operation on a virutal folder.

Copyright © 2015-2017, Verizon and/or its Licensors. All rights reserved.