DBRequest.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // DBRestRequest.h
  3. // DropboxSDK
  4. //
  5. // Created by Brian Smith on 4/9/10.
  6. // Copyright 2010 Dropbox, Inc. All rights reserved.
  7. //
  8. @protocol DBNetworkRequestDelegate;
  9. /* DBRestRequest will download a URL either into a file that you provied the name to or it will
  10. create an NSData object with the result. When it has completed downloading the URL, it will
  11. notify the target with a selector that takes the DBRestRequest as the only parameter. */
  12. @interface DBRequest : NSObject {
  13. NSURLRequest* request;
  14. id target;
  15. SEL selector;
  16. NSURLConnection* urlConnection;
  17. NSFileHandle* fileHandle;
  18. NSFileManager* fileManager;
  19. SEL failureSelector;
  20. SEL downloadProgressSelector;
  21. SEL uploadProgressSelector;
  22. NSString* resultFilename;
  23. NSString* tempFilename;
  24. NSDictionary* userInfo;
  25. NSString *sourcePath;
  26. NSHTTPURLResponse* response;
  27. NSDictionary* xDropboxMetadataJSON;
  28. NSInteger bytesDownloaded;
  29. CGFloat downloadProgress;
  30. CGFloat uploadProgress;
  31. NSMutableData* resultData;
  32. NSError* error;
  33. }
  34. /* Set this to get called when _any_ request starts or stops. This should hook into whatever
  35. network activity indicator system you have. */
  36. + (void)setNetworkRequestDelegate:(id<DBNetworkRequestDelegate>)delegate;
  37. /* This constructor downloads the URL into the resultData object */
  38. - (id)initWithURLRequest:(NSURLRequest*)request andInformTarget:(id)target selector:(SEL)selector;
  39. /* Cancels the request and prevents it from sending additional messages to the delegate. */
  40. - (void)cancel;
  41. /* If there is no error, it will parse the response as JSON and make sure the JSON object is the
  42. correct type. If not, it will set the error object with an error code of DBErrorInvalidResponse */
  43. - (id)parseResponseAsType:(Class)cls;
  44. @property (nonatomic, assign) SEL failureSelector; // To send failure events to a different selector set this
  45. @property (nonatomic, assign) SEL downloadProgressSelector; // To receive download progress events set this
  46. @property (nonatomic, assign) SEL uploadProgressSelector; // To receive upload progress events set this
  47. @property (nonatomic, retain) NSString* resultFilename; // The file to put the HTTP body in, otherwise body is stored in resultData
  48. @property (nonatomic, retain) NSDictionary* userInfo;
  49. @property (nonatomic, retain) NSString *sourcePath; // Used by methods that upload to refresh the input stream
  50. @property (nonatomic, readonly) NSURLRequest* request;
  51. @property (nonatomic, readonly) NSHTTPURLResponse* response;
  52. @property (nonatomic, readonly) NSDictionary* xDropboxMetadataJSON;
  53. @property (nonatomic, readonly) NSInteger statusCode;
  54. @property (nonatomic, readonly) CGFloat downloadProgress;
  55. @property (nonatomic, readonly) CGFloat uploadProgress;
  56. @property (nonatomic, readonly) NSData* resultData;
  57. @property (nonatomic, readonly) NSString* resultString;
  58. @property (nonatomic, readonly) NSObject* resultJSON;
  59. @property (nonatomic, readonly) NSError* error;
  60. @end
  61. @protocol DBNetworkRequestDelegate
  62. - (void)networkRequestStarted;
  63. - (void)networkRequestStopped;
  64. @end