Yini  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
DBRequest.h
Go to the documentation of this file.
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 
9 
10 @protocol DBNetworkRequestDelegate;
11 
12 /* DBRestRequest will download a URL either into a file that you provied the name to or it will
13  create an NSData object with the result. When it has completed downloading the URL, it will
14  notify the target with a selector that takes the DBRestRequest as the only parameter. */
15 @interface DBRequest : NSObject {
16  NSURLRequest* request;
17  id target;
18  SEL selector;
19  NSURLConnection* urlConnection;
20  NSFileHandle* fileHandle;
21 
25  NSString* resultFilename;
26  NSString* tempFilename;
27  NSDictionary* userInfo;
28 
29  NSHTTPURLResponse* response;
30  NSDictionary* xDropboxMetadataJSON;
31  NSInteger bytesDownloaded;
33  CGFloat uploadProgress;
34  NSMutableData* resultData;
35  NSError* error;
36 }
37 
38 /* Set this to get called when _any_ request starts or stops. This should hook into whatever
39  network activity indicator system you have. */
40 + (void)setNetworkRequestDelegate:(id<DBNetworkRequestDelegate>)delegate;
41 
42 /* This constructor downloads the URL into the resultData object */
43 - (id)initWithURLRequest:(NSURLRequest*)request andInformTarget:(id)target selector:(SEL)selector;
44 
45 /* Cancels the request and prevents it from sending additional messages to the delegate. */
46 - (void)cancel;
47 
48 /* If there is no error, it will parse the response as JSON and make sure the JSON object is the
49  correct type. If not, it will set the error object with an error code of DBErrorInvalidResponse */
50 - (id)parseResponseAsType:(Class)cls;
51 
52 @property (nonatomic, assign) SEL failureSelector; // To send failure events to a different selector set this
53 @property (nonatomic, assign) SEL downloadProgressSelector; // To receive download progress events set this
54 @property (nonatomic, assign) SEL uploadProgressSelector; // To receive upload progress events set this
55 @property (nonatomic, retain) NSString* resultFilename; // The file to put the HTTP body in, otherwise body is stored in resultData
56 @property (nonatomic, retain) NSDictionary* userInfo;
57 
58 @property (nonatomic, readonly) NSURLRequest* request;
59 @property (nonatomic, readonly) NSHTTPURLResponse* response;
60 @property (nonatomic, readonly) NSDictionary* xDropboxMetadataJSON;
61 @property (nonatomic, readonly) NSInteger statusCode;
62 @property (nonatomic, readonly) CGFloat downloadProgress;
63 @property (nonatomic, readonly) CGFloat uploadProgress;
64 @property (nonatomic, readonly) NSData* resultData;
65 @property (nonatomic, readonly) NSString* resultString;
66 @property (nonatomic, readonly) NSObject* resultJSON;
67 @property (nonatomic, readonly) NSError* error;
68 
69 @end
70 
71 
73 
74 - (void)networkRequestStarted;
75 - (void)networkRequestStopped;
76 
77 @end