Class: SdkClient

Version 1.1 - Updated on 8/11/2016

Contents

Overview

Use this class to make API calls. First you will need to obtain an OAuth 2.0 access token. You can obtain the access token using either SdkOAuth2Flow or SdkOAuth2FlowNoRedirect.

Constructor Details

initialize

#initialize(oauth2_access_token, root = "auto", locale = nil) ⇒ SdkClient

def initialize(oauth2_access_token, root="auto", locale=nil)
  if oauth2_access_token.is_a?(String)
    @session = SdkOAuth2Session.new(oauth2_access_token, locale)
  elsif oauth2_access_token.is_a?(SdkSession)
    @session = oauth2_access_token
    @session.get_access_token
    if not locale.nil?
      @session.locale = locale
    end
  else
    raise ArgumentError.new("oauth2_access_token doesn't have a valid type")
  end

  @root = root.to_s  # If they passed in a symbol, make it a string

  if not ["sdk","app_folder","auto"].include?(@root)
    raise ArgumentError.new("root must be :sdk, :app_folder, or :auto")
  end
  if @root == "app_folder"
    #App Folder is the name of the access type, but for historical reasons
    #sandbox is the URL root component that indicates this
    @root = "sandbox"
  end

Instance Method Details

Authentiction and Authorization

create_oauth2_access_token

#create_oauth2_access_token ⇒ Object

You can use this method to create an equivalent of an OAuth 2.0 access token. This method can be helpful if the SdkClient has been created with an OAuth 1.0 access token. You can use it to upgrade your app’s existing access tokens from OAuth 1.0 to OAuth 2.0.

def create_oauth2_access_token
  if not @session.is_a?(SdkSession)
    raise ArgumentError.new("This call requires a SdkClient that is configured with " \
                            "an OAuth 1 access token.")
  end
  response = @session.do_post "/oauth2/token_from_oauth1"
  Sdk::parse_response(response)['access_token']
end

disable_access_token

#disable_access_token ⇒ Object

Disables the access token that this SdkClient is using. If this call succeeds, further API calls using this object will fail.

def disable_access_token
  @session.do_post "/disable_access_token"
  nil
end

Account Information

account_info

#account_info ⇒ Object

—————————— List of Account Functions —————————-

Retrieves account information.

  • Arguments:

  • Returns:

    • A Hash object with account usage of the user.
def account_info()
  request = Account.new(@session)
  return request.account_info()
end

Contacts

contacts

#contacts ⇒ Object

—————————— List of Contact function —————————-

Retrieves the account information.

  • Arguments:

  • Returns:

    • A Hash object with account usage
def contacts()
  request = Contact.new(@session)
  return request.contacts()
end

File and Folder Operations

create_folder

#create_folder(folderdata) ⇒ Object

Creates 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)
  
  request = Fileops.new(@session)
  return request.create_folder(folderdata)
end

file_copy

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

Copies a file or a 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')
  
  request = Fileops.new(@session)
  return request.file_copy(src,target, safe = 'false',conflictsolve = 'copy',override = 'overwrite')
end

file_delete

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

Deletes a file.

  • Arguments:

    • path: The path of the file to be deleted
  • Returns:

    • A Hash with the metadata of the file just deleted.
def file_delete(path,purge='false')
 
  request = Fileops.new(@session)
  return request.file_delete(path,purge)
end

file_move

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

Moves 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 folder just moved.
def file_move(src,target, safe = 'false',conflictsolve = 'copy')
	
  request = Fileops.new(@session)
  return request.file_move(src,target, safe = 'false',conflictsolve = 'copy')
end

fileorfolder_rename

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

Renames 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 file or folder just renamed.
def fileorfolder_rename(src,target, safe = 'false',conflictsolve = 'copy')
	
  request = Fileops.new(@session)
  return request.fileorfolder_rename(src,target, safe = 'false',conflictsolve = 'copy')
end

fileUploadIntent

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

Initiates a file upload intent request.

  • Arguments:

    • path: The path to the folder where 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 the 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 for chunked file uploads.
def fileUploadIntent(path, name, size, checksum, chunk = 'false')
  
  request = Fileops.new(@session)
  return request.fileUploadIntent(path, name, size, checksum, chunk )
end

fullview

#fullview(virtualfolder, xheaderetag) ⇒ Object

Retrieves information on all files and folders in a user’s Personal Cloud Storage account.

  • Arguments:

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

    • A Hash object with a list of the metadata for the files or folders that match the query.
def fullview(virtualfolder, xheaderetag)
 
  request = Fileops.new(@session)
  return request.fullview(virtualfolder, xheaderetag)
end

get_file

#get_file(from_path) ⇒ Object

Returns the content of a file at the specified path.

  • Arguments:

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

    • The file contents.
def get_file(from_path)
  
  request = Fileops.new(@session)
  return request.get_file(from_path)
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 the metadata results.
    • sort: Optional. Sort order of the 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, as well as the files contained in the folders.
def metadata(path, include_deleted=false, sort='name+asc', start="", count="", filter='' )
  
  request = Fileops.new(@session)
  return request.metadata(path, include_deleted, sort, start, count, filter)
end

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

Retrieves files and folders that match a specified search query.

  • Arguments:

    • query: Contains the text to be searched for 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. Specifies a sort order for the 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 of the metadata for the files and folders matching the specified query.
def search(query,path, sort='name+asc', start=1, count='')
  
  request = Fileops.new(@session)
  return request.search(query,path, sort, start, count)
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)
  
  request = Fileops.new(@session)
  return request.thumbnail(content_token, size, th , tw )
end

File Upload

upload_chunk_data

#upload_chunk_data(uploadurl, offset, file_obj) ⇒ Object

Uploads chunked data.

  • Arguments:

    • uploadurl: Upload URL.
    • offset: offset of file.
    • binarydata: binary data of the file.
  • Returns:

    • A hash object.
def upload_chunk_data(uploadurl, offset, file_obj)
  
  request = Fileops.new(@session)
  return request.upload_chunk_data(uploadurl, offset, file_obj)
end

upload_data

#upload_data(uploadurl, checksum, file_obj) ⇒ Object

Uploadsa complete file.

  • Arguments:

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

    • A hash object.
def upload_data(uploadurl, checksum, file_obj)
	
  request = Fileops.new(@session)
  return request.upload_data(uploadurl, checksum, file_obj)
end

uploadCommit

#uploadCommit(uploadurl) ⇒ Object

Indicates that file content upload is complete and the file is ready to be created.

  • Arguments:

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

    • A hash object.
def uploadCommit(uploadurl)
  
  request = Fileops.new(@session)
  return request.uploadCommit(uploadurl)
end

Playlists

add_playlist_item

#add_playlist_item(playlistUid, playlistitemdata) ⇒ Object

Add items to a playlist.

  • Arguments:

    • playlistid: The ID of the playlist to which items are to be added.
    • playlistitemdata: Playlist item data in the json format.
  • Returns:

    • A Hash object.
def add_playlist_item(playlistUid,playlistitemdata)
  request = Playlist.new(@session)
  return request.add_playlist_item(playlistUid,playlistitemdata)
end

create_playlist

#create_playlist(playlistdata) ⇒ Object

Creates a playlist.

  • Arguments:

    • playlistdata: Playlist data in the json format.
  • Returns:

    • A Hash object.
def create_playlist(playlistdata)
  request = Playlist.new(@session)
  return request.create_playlist(playlistdata)
end

deletePlaylist

#deletePlaylist(playlistUid) ⇒ Object

Deletes a playlist.

  • Arguments:

    • playlistUid: ID of the playlist
  • Returns:

    • A Hash object.
def deletePlaylist(playlistUid)
  request = Playlist.new(@session)
  return request.deletePlaylist(playlistUid)
end

deletePlaylistItem

#deletePlaylistItem(playlistUid, itemUid) ⇒ Object

Deletes an item from a playlist.

  • Arguments:

    • playlistUid: ID of the playlist
    • itemUid: ID of the item to be deleted
  • Returns:

    • A Hash object.
def deletePlaylistItem(playlistUid, itemUid)
  request = Playlist.new(@session)
  return request.deletePlaylistItem(playlistUid, itemUid)
end

playlistContent

#playlistContent(playlistUid, itemUid) ⇒ Object

Retrives a playlist content.

  • Arguments:

    • playlistUid: ID of the playlist.
    • itemUid: ID of the item contained in a playlist.
  • Returns:

    • A Hash object.
def playlistContent(playlistUid,itemUid)
  request = Playlist.new(@session)
  return request.playlistContent(playlistUid,itemUid)
end

playlistDefinition

#playlistDefinition(playlistUid) ⇒ Object

Retrives playlist’s definition.

  • Arguments:

    • playlistUid: ID of a playlist.
    • start: Start of a playlist.
    • count: Count of a playlist.
    • sort: Sorting of a playlist.
  • Returns:

    • A Hash object.
def playlistDefinition(playlistUid)
  request = Playlist.new(@session)
  return request.playlistDefinition(playlistUid)
end

playlistItems

#playlistItems(playlistUid, start = "", count = "", sort = 'name+asc') ⇒ Object

Retrives playlist items.

  • Arguments:

    • playlistUid: ID of a playlist.
    • start: Start of a playlist.
    • count: Count of a playlist.
    • sort: S orting of a playlist.
  • Returns:

    • A Hash object.
def playlistItems(playlistUid, start="", count="", sort='name+asc')
  request = Playlist.new(@session)
  return request.playlistItems(playlistUid, start, count, sort)
end

playlists

#playlists(type = "", start = "", count = "", sort = 'name+asc') ⇒ Object

Retrives a playlist.

  • Arguments:

    • type: Type ofa playlist.
    • start: Start of a playlist.
    • count: Count ofa playlist.
    • sort: Sorting of a playlist.
  • Returns:

    • A Hash object.
def playlists(type = "", start="", count="", sort='name+asc')
  request = Playlist.new(@session)
  return request.playlists(type , start, count, sort)
end

update_playlist

#update_playlist(playlistUid, playlistupdateData) ⇒ Object

Updates a playlist.

  • Arguments:

    • playlistid: ID of the playlist
    • playlistupdateData: Data in json format which is to be updated.
  • Returns:

    • A hash object.
def update_playlist(playlistUid,playlistupdateData)
  request = Playlist.new(@session)
  return request.update_playlist(playlistUid,playlistupdateData)
end

update_playlist_items

#update_playlist_items(playlistUid, updateplaylistdata) ⇒ Object

Updates a playlist item’s definition.

  • Arguments:

    • playlistUid: ID of the playlist
    • updateplaylistdata: Items data in json format which are to be updated.
  • Returns:

    • A hash object.
def update_playlist_items(playlistUid,updateplaylistdata)
  request = Playlist.new(@session)
  return request.update_playlist_items(playlistUid,updateplaylistdata)
end

Trash Can

purgetrash

#purgetrash(virtualfolder) ⇒ Object

Deletes the files and folders that are in a deleted state in the user’s Personal Cloud 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)
  
  request = Fileops.new(@session)
  return request.purgetrash(virtualfolder)
end

restore

#restore(path) ⇒ Object

Restores a file or folder from trash.

  • Arguments:

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

    • A Hash object.
def restore(path)
  
  request = Fileops.new(@session)
  return request.restore(path)
end

trash

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

Retrieves a list of files and folders that are in the deleted state in the user’s Personal Cloud Storage account.

  • 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)
  
  request = Fileops.new(@session)
  return request.trash(path, sort, start, count, filter , deep )
end

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