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