Cloud Manager

These classes have all the code that we need to manage the supported Cloud Services. There is code to list items, rename a file, delete a file, delete a folder, download a file, upload a file, and get information for the logged in user.

We create an instance of that class by calling the constructor RManager(RServiceItem _serviceItem):

RManager rManager = new RManager(RServiceItem _serviceItem);

where rService is an instance of the ServiceItem class.

Even though we can create an instance of the Cloud Manager class by calling the default constructor, we strongly advise against it. The instance of the ServiceItem class that we pass to the Cloud Manager class has all the information that we need to authenticate the user when we make a request to that Cloud Service.

Methods

The Cloud Manager has several methods. Some of them are used internally, but there are some that we need to call in order to manage that Cloud Service:

  • getFilesInFolder(String path): Get the list of items (files and folders) in a folder. The path is the rItem.path. We get the response from the method filesListIsReady of the RManagerCallback callback
  • searchItemsInFolder:(String path, String key, SearchTypes type): Search for files and folders in a folder. The path is the rItem.path. We get the response from the method filesListIsReady of the RManagerCallback callback. The SearchType is an enum with the following two values:
    • stFile: Returns files/folders whose name matches the key
    • stFileAndContent: Return files/folders whose name matches the key, but also returns file(s) whose content contains that key
  • downloadFile(RItem file): We call this method to download a file. We get the response from the onFileToBeDownloaded of the RManagerDownloadCallback callback.
  • uploadLocalFile(RItem file, String path): We call this method to upload a file to a folder. The path is the rItem.path of that folder. We get the response from the method onFileIsReadyToBeUploaded of the RManagerTransferCallback callback
  • deleteFile(RItem file): A method to delete a file. We get the response from the method ioTaskCompletedWithResponse of the RManagerCallback callback
  • deleteFolder(RItem folder): A method to delete a folder. It does not delete the folder recursively. You need to delete the files subfolders that are contained in that folder. We get the response from the method ioTaskCompletedWithResponse of the RManagerCallback callback
  • renameFile(RItem file, String fileName): A method to rename a file. We get the response from the method ioTaskCompletedWithResponse of the RManagerCallback callback
  • createFolder(String folderName, String parentFolder): A method to create a new folder (named folderName) in the parentFolder path. We get the response from the method ioTaskCompletedWithResponse of the RManagerCallback callback

We always call the method uploadLocalFile to upload a file, regardless of the file size. If it is needed, the Rainbow SDK will create a session and upload that file in chunks.

Callbacks

The Cloud Manager class uses the following delegates:

  • RManagerCallback:
    • filesListIsReady(ArrayList<RItem> items): This method is called when the SDK has the list of items (files and folders) in the selected folder (either because we browsed that folder or we searched in that folder)
    • somethingWasWrong: This method is called every time there was a problem with a request
    • ioTaskCompletedWithResponse(String newID, CloudManagerActions action): This method is called when we make a request to rename a file, delete a file (or folder) and create a new folder. The action will inform us about the action that took place. When we create a new folder, the newID is the itemID of that folder. In all other cases it is an empty string
  • RManagerTransferCallback:
    • onFileIsReadyToBeUploaded:(RItem file, RTransferItem transferItem, booleaan status): This method is called when we call the method to upload a file. The object transferItem has all the information that we need to upload that file. The status is a flag to indicate if the process was successful or not. You shouldn’t use the transferItem if that flag is NO.
  • RManagerDownloadCallback:
    • onFileToBeDownloaded(RTransferItem transferItem): The object transferItem has all the information that we need to download a file
  • RManagerAccountCallback
    • onAccount(RAccount raccount):The object rAccount has some information about the logged in user.

Summary

The Rainbow SDK has a Cloud Manager class for each supported Cloud Service. The RLocalManager class is used to save a file on the local filesystem or to upload a local file to a Cloud Service. We give the path of the local file to the property filePath.

We believe that you would never need to call the methods to upload and download a file. Instead you should create an instance of the RTransfer class, and let it do the hard work of uploading or downloading a file.