-
Notifications
You must be signed in to change notification settings - Fork 0
/
DCNetworkOperation.h
59 lines (45 loc) · 2.13 KB
/
DCNetworkOperation.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
//
// DCNetworkOperation.h
//
// Created by David Cairns on 11/21/10.
// Copyright 2010 David Cairns. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "DCOperation.h"
#import "NSString+DCNetworkOperationAdditions.h"
extern NSString *DCNetworkOperationErrorDomain;
enum {
DCNetworkOperationErrorCodeBadRequest = 1,
DCNetworkOperationErrorCodeConnectionFailed,
};
#define DCProgressIndeterminate -1.0
@class DCNetworkOperation;
typedef void (^DCResponseProcessingBlock)(DCNetworkOperation *networkOperation);
@interface DCNetworkOperation : DCOperation
@property(nonatomic, copy)NSString *urlString;
@property(nonatomic, copy)NSString *HTTPMethod;
@property(nonatomic, copy)NSDictionary *headerFields;
// NOTE: One may provide data via either a key/value-style approach (which supports uploading
// files, etc), or by providing just the raw data. These methods are not compatible
// with one another. --DRC
// Key / Value API.
- (NSString *)requestValueForParameter:(NSString *)parameter;
- (void)setRequestValue:(NSString *)value forParameter:(NSString *)parameter;
- (void)setRequestFilename:(NSString *)filename forParameter:(NSString *)parameter;
// Raw-data API.
- (void)setRequestData:(NSData *)requestData;
// This fields are populated during execution of the URL request.
@property(nonatomic, assign, readonly)long long expectedContentLength;
@property(nonatomic, strong, readonly)NSData *responseData;
// This block is called every time the operation receives data.
@property(nonatomic, copy)dispatch_block_t transferUpdateBlock;
// Progress in [0.0, 1.0]. If the expected content length isn't yet known, returns DCProgressIndeterminate.
@property(nonatomic, assign, readonly)float progress;
// The block to be called by each operation when it needs to process its response data.
// Generally, you'd interpret the response data as e.g. JSON and parse it in to the network
// operation's responseDictionary object.
@property(nonatomic, copy)DCResponseProcessingBlock responseProcessingBlock;
// Authentication
@property(nonatomic, copy)NSString *authenticationUserName;
@property(nonatomic, copy)NSString *authenticationPassword;
@end