DBRestClient.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // DBRestClient.h
  3. // DropboxSDK
  4. //
  5. // Created by Brian Smith on 4/9/10.
  6. // Copyright 2010 Dropbox, Inc. All rights reserved.
  7. //
  8. #import "DBSession.h"
  9. @protocol DBRestClientDelegate;
  10. @class DBAccountInfo;
  11. @class DBMetadata;
  12. @interface DBRestClient : NSObject {
  13. DBSession* session;
  14. NSString* userId;
  15. NSString* root;
  16. NSMutableSet* requests;
  17. /* Map from path to the load request. Needs to be expanded to a general framework for cancelling
  18. requests. */
  19. NSMutableDictionary* loadRequests;
  20. NSMutableDictionary* imageLoadRequests;
  21. NSMutableDictionary* uploadRequests;
  22. id<DBRestClientDelegate> delegate;
  23. }
  24. - (id)initWithSession:(DBSession*)session;
  25. - (id)initWithSession:(DBSession *)session userId:(NSString *)userId;
  26. /* Cancels all outstanding requests. No callback for those requests will be sent */
  27. - (void)cancelAllRequests;
  28. /* Loads metadata for the object at the given root/path and returns the result to the delegate as a
  29. dictionary */
  30. - (void)loadMetadata:(NSString*)path withHash:(NSString*)hash;
  31. - (void)loadMetadata:(NSString*)path;
  32. /* This will load the metadata of a file at a given rev */
  33. - (void)loadMetadata:(NSString *)path atRev:(NSString *)rev;
  34. /* Loads a list of files (represented as DBDeltaEntry objects) that have changed since the cursor was generated */
  35. - (void)loadDelta:(NSString *)cursor;
  36. /* Loads the file contents at the given root/path and stores the result into destinationPath */
  37. - (void)loadFile:(NSString *)path intoPath:(NSString *)destinationPath;
  38. /* This will load a file as it existed at a given rev */
  39. - (void)loadFile:(NSString *)path atRev:(NSString *)rev intoPath:(NSString *)destPath;
  40. - (void)cancelFileLoad:(NSString*)path;
  41. - (void)loadThumbnail:(NSString *)path ofSize:(NSString *)size intoPath:(NSString *)destinationPath;
  42. - (void)cancelThumbnailLoad:(NSString*)path size:(NSString*)size;
  43. /* Uploads a file that will be named filename to the given path on the server. sourcePath is the
  44. full path of the file you want to upload. If you are modifying a file, parentRev represents the
  45. rev of the file before you modified it as returned from the server. If you are uploading a new
  46. file set parentRev to nil. */
  47. - (void)uploadFile:(NSString *)filename toPath:(NSString *)path withParentRev:(NSString *)parentRev
  48. fromPath:(NSString *)sourcePath;
  49. - (void)cancelFileUpload:(NSString *)path;
  50. /* Avoid using this because it is very easy to overwrite conflicting changes. Provided for backwards
  51. compatibility reasons only */
  52. - (void)uploadFile:(NSString*)filename toPath:(NSString*)path fromPath:(NSString *)sourcePath __attribute__((deprecated));
  53. /* These calls allow you to upload files in chunks, which is better for file larger than a few megabytes.
  54. You can append bytes to the file using -[DBRestClient uploadFileChunk:offset:uploadId:] and then call
  55. -[DBRestClient uploadFile:toPath:withParentRev:fromUploadId:] to turn the bytes appended at that uploadId
  56. into an actual file in the user's Dropbox.
  57. Use a nil uploadId to start uploading a new file. */
  58. - (void)uploadFileChunk:(NSString *)uploadId offset:(unsigned long long)offset fromPath:(NSString *)localPath;
  59. - (void)uploadFile:(NSString *)filename toPath:(NSString *)parentFolder withParentRev:(NSString *)parentRev
  60. fromUploadId:(NSString *)uploadId;
  61. /* Loads a list of up to 10 DBMetadata objects representing past revisions of the file at path */
  62. - (void)loadRevisionsForFile:(NSString *)path;
  63. /* Same as above but with a configurable limit to number of DBMetadata objects returned, up to 1000 */
  64. - (void)loadRevisionsForFile:(NSString *)path limit:(NSInteger)limit;
  65. /* Restores a file at path as it existed at the given rev and returns the metadata of the restored
  66. file after restoration */
  67. - (void)restoreFile:(NSString *)path toRev:(NSString *)rev;
  68. /* Creates a folder at the given root/path */
  69. - (void)createFolder:(NSString*)path;
  70. - (void)deletePath:(NSString*)path;
  71. - (void)copyFrom:(NSString*)fromPath toPath:(NSString *)toPath;
  72. - (void)createCopyRef:(NSString *)path; // Used to copy between Dropboxes
  73. - (void)copyFromRef:(NSString*)copyRef toPath:(NSString *)toPath; // Takes copy ref created by above call
  74. - (void)moveFrom:(NSString*)fromPath toPath:(NSString *)toPath;
  75. - (void)loadAccountInfo;
  76. - (void)searchPath:(NSString*)path forKeyword:(NSString*)keyword;
  77. - (void)loadSharableLinkForFile:(NSString *)path;
  78. - (void)loadSharableLinkForFile:(NSString *)path shortUrl:(BOOL)createShortUrl;
  79. - (void)loadStreamableURLForFile:(NSString *)path;
  80. - (NSUInteger)requestCount;
  81. @property (nonatomic, assign) id<DBRestClientDelegate> delegate;
  82. @end
  83. /* The delegate provides allows the user to get the result of the calls made on the DBRestClient.
  84. Right now, the error parameter of failed calls may be nil and [error localizedDescription] does
  85. not contain an error message appropriate to show to the user. */
  86. @protocol DBRestClientDelegate <NSObject>
  87. @optional
  88. - (void)restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata;
  89. - (void)restClient:(DBRestClient*)client metadataUnchangedAtPath:(NSString*)path;
  90. - (void)restClient:(DBRestClient*)client loadMetadataFailedWithError:(NSError*)error;
  91. // [error userInfo] contains the root and path of the call that failed
  92. - (void)restClient:(DBRestClient*)client loadedDeltaEntries:(NSArray *)entries reset:(BOOL)shouldReset cursor:(NSString *)cursor hasMore:(BOOL)hasMore;
  93. - (void)restClient:(DBRestClient*)client loadDeltaFailedWithError:(NSError *)error;
  94. - (void)restClient:(DBRestClient*)client loadedAccountInfo:(DBAccountInfo*)info;
  95. - (void)restClient:(DBRestClient*)client loadAccountInfoFailedWithError:(NSError*)error;
  96. - (void)restClient:(DBRestClient*)client loadedFile:(NSString*)destPath;
  97. // Implement the following callback instead of the previous if you care about the value of the
  98. // Content-Type HTTP header and the file metadata. Only one will be called per successful response.
  99. - (void)restClient:(DBRestClient*)client loadedFile:(NSString*)destPath contentType:(NSString*)contentType metadata:(DBMetadata*)metadata;
  100. - (void)restClient:(DBRestClient*)client loadProgress:(CGFloat)progress forFile:(NSString*)destPath;
  101. - (void)restClient:(DBRestClient*)client loadFileFailedWithError:(NSError*)error;
  102. // [error userInfo] contains the destinationPath
  103. - (void)restClient:(DBRestClient*)client loadedThumbnail:(NSString*)destPath metadata:(DBMetadata*)metadata;
  104. - (void)restClient:(DBRestClient*)client loadThumbnailFailedWithError:(NSError*)error;
  105. - (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)destPath from:(NSString*)srcPath
  106. metadata:(DBMetadata*)metadata;
  107. - (void)restClient:(DBRestClient*)client uploadProgress:(CGFloat)progress
  108. forFile:(NSString*)destPath from:(NSString*)srcPath;
  109. - (void)restClient:(DBRestClient*)client uploadFileFailedWithError:(NSError*)error;
  110. // [error userInfo] contains the sourcePath
  111. - (void)restClient:(DBRestClient *)client uploadedFileChunk:(NSString *)uploadId newOffset:(unsigned long long)offset
  112. fromFile:(NSString *)localPath expires:(NSDate *)expiresDate;
  113. - (void)restClient:(DBRestClient *)client uploadFileChunkFailedWithError:(NSError *)error;
  114. - (void)restClient:(DBRestClient *)client uploadFileChunkProgress:(CGFloat)progress
  115. forFile:(NSString *)uploadId offset:(unsigned long long)offset fromPath:(NSString *)localPath;
  116. - (void)restClient:(DBRestClient *)client uploadedFile:(NSString *)destPath fromUploadId:(NSString *)uploadId
  117. metadata:(DBMetadata *)metadata;
  118. - (void)restClient:(DBRestClient *)client uploadFromUploadIdFailedWithError:(NSError *)error;
  119. // Deprecated upload callback
  120. - (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)destPath from:(NSString*)srcPath;
  121. // Deprecated download callbacks
  122. - (void)restClient:(DBRestClient*)client loadedFile:(NSString*)destPath contentType:(NSString*)contentType;
  123. - (void)restClient:(DBRestClient*)client loadedThumbnail:(NSString*)destPath;
  124. - (void)restClient:(DBRestClient*)client loadedRevisions:(NSArray *)revisions forFile:(NSString *)path;
  125. - (void)restClient:(DBRestClient*)client loadRevisionsFailedWithError:(NSError *)error;
  126. - (void)restClient:(DBRestClient*)client restoredFile:(DBMetadata *)fileMetadata;
  127. - (void)restClient:(DBRestClient*)client restoreFileFailedWithError:(NSError *)error;
  128. - (void)restClient:(DBRestClient*)client createdFolder:(DBMetadata*)folder;
  129. // Folder is the metadata for the newly created folder
  130. - (void)restClient:(DBRestClient*)client createFolderFailedWithError:(NSError*)error;
  131. // [error userInfo] contains the root and path
  132. - (void)restClient:(DBRestClient*)client deletedPath:(NSString *)path;
  133. - (void)restClient:(DBRestClient*)client deletePathFailedWithError:(NSError*)error;
  134. // [error userInfo] contains the root and path
  135. - (void)restClient:(DBRestClient*)client copiedPath:(NSString *)fromPath to:(DBMetadata *)to;
  136. - (void)restClient:(DBRestClient*)client copyPathFailedWithError:(NSError*)error;
  137. // [error userInfo] contains the root and path
  138. - (void)restClient:(DBRestClient*)client createdCopyRef:(NSString *)copyRef forPath:(NSString *)path;
  139. - (void)restClient:(DBRestClient*)client createCopyRefFailedWithError:(NSError *)error;
  140. // Deprecated copy ref callback
  141. - (void)restClient:(DBRestClient*)client createdCopyRef:(NSString *)copyRef;
  142. - (void)restClient:(DBRestClient*)client copiedRef:(NSString *)copyRef to:(DBMetadata *)to;
  143. - (void)restClient:(DBRestClient*)client copyFromRefFailedWithError:(NSError*)error;
  144. - (void)restClient:(DBRestClient*)client movedPath:(NSString *)from_path to:(DBMetadata *)result;
  145. - (void)restClient:(DBRestClient*)client movePathFailedWithError:(NSError*)error;
  146. // [error userInfo] contains the root and path
  147. - (void)restClient:(DBRestClient*)restClient loadedSearchResults:(NSArray*)results
  148. forPath:(NSString*)path keyword:(NSString*)keyword;
  149. // results is a list of DBMetadata * objects
  150. - (void)restClient:(DBRestClient*)restClient searchFailedWithError:(NSError*)error;
  151. - (void)restClient:(DBRestClient*)restClient loadedSharableLink:(NSString*)link
  152. forFile:(NSString*)path;
  153. - (void)restClient:(DBRestClient*)restClient loadSharableLinkFailedWithError:(NSError*)error;
  154. - (void)restClient:(DBRestClient*)restClient loadedStreamableURL:(NSURL*)url forFile:(NSString*)path;
  155. - (void)restClient:(DBRestClient*)restClient loadStreamableURLFailedWithError:(NSError*)error;
  156. @end