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 initWithServiceItem:

RManager *rManager = [[RManager alloc]initWithServiceItem:rServiceItem];

where rService is an instance of the ServiceItem class.

Even though we can create an instance of the Cloud Manager class by calling the init method, 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:(NSString*)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 RManagerDelegate delegate
  • searchItemsInFolder:(NSString*)path forKey:(NSString*)key forType:(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 block.
  • uploadLocalFile:(RItem)file toPath:(NSString)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 RManagerTransferDelegate delegate
  • deleteFile:(RItem*)file: A method to delete a file. We get the response from the method ioTaskCompletedWithResponse of the RManagerDelegate delegate
  • 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 RManagerDelegate delegate
  • renameFile:(RItem)file toFileName:(NSString)fileName: A method to rename a file. We get the response from the method ioTaskCompletedWithResponse of the RManagerDelegate delegate
  • createFolder:(NSString)folderName atPath:(NSString)parentFolder: A method to create a new folder (named folderName) in the parentFolder path. We get the response from the method ioTaskCompletedWithResponse of the RManagerDelegate delegate

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.

Delegates

The Cloud Manager class uses the following delegates:

  • RManagerDelegate:
    • filesListIsReady: 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). That list is saved in the property availableFiles of the Cloud Manager instance (this will change in the future)
    • somethingWasWrong: This method is called every time there was a problem with a request
    • ioTaskCompletedWithResponse:(NSString*)newID forAction:(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
  • RManagerTransferDelegate:
    • onFileIsReadyToBeUploaded:(RItem)file withSyncObj:(RTransferItem)upObj andStatus:(BOOL)status: This method is called when we call the method to upload a file. The object upObj 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 upObj if that flag is NO.

Blocks

The Cloud Manager also uses the following blocks:

  • (^onFileToBeDownloaded)(RTransferItem *downObj): The object downObj has all the information that we need to download a file
  • (^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.