-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDCHTTPTask.h
More file actions
141 lines (117 loc) · 4.84 KB
/
DCHTTPTask.h
File metadata and controls
141 lines (117 loc) · 4.84 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// DCHTTPTask.h
//
// Created by Dalton Cherry on 5/5/14.
//
////////////////////////////////////////////////////////////////////////////////////////////////////
#import "DCTask.h"
#import "DCHTTPRequestSerializer.h"
#import "DCHTTPResponseSerializer.h"
typedef void (^DCHTTPTaskProgress)(CGFloat progress);
@interface DCHTTPResponse : NSObject
/**
The response headers when the request finishes.
*/
@property(nonatomic,strong)NSDictionary *headers;
/**
The response object that is returned after the responseSerializer has serialized/parsed it.
*/
@property(nonatomic,strong)id responseObject;
@end
@interface DCHTTPTask : DCTask<NSURLSessionDelegate>
/**
The url you want to load.
*/
@property(nonatomic,copy)NSString *url;
/**
The parameters you want to send with the request.
*/
@property(nonatomic,strong)NSDictionary *parameters;
/**
The serializer you want to encode the parameters with. Default is to use the standard DCHTTPRequestSerializer.
*/
@property(nonatomic,strong)DCHTTPRequestSerializer *requestSerializer;
/**
The serializer you want to encode the response with (JSON,XML,etc). Default is nil, which means a NSData object will be returned.
*/
@property(nonatomic,strong)id<DCHTTPResponseSerializerDelegate> responseSerializer;
/**
The HTTP method for this request. The default is GET.
@see NSMutableURLRequest -setHTTPMethod:
*/
@property (nonatomic, copy) NSString *HTTPMethod;
/**
This BOOL controls if the request needs to be done as a background downloaded.
This ONLY needs to be set if the desired is for the request to be in the background.
The request must be a download.
*/
@property(nonatomic,assign,getter = isDownload)BOOL download;
/**
This BOOL controls if the request needs to be done as a background upload.
This ONLY needs to be set if the desired is for the request to be in the background.
The request must be a upload.
*/
@property(nonatomic,assign,getter = isUpload)BOOL upload;
/**
This can be used to allow different serializer for different content types.
This differs from the responseSerializer property as it is used only for the content type defined,
where the responseSerializer property is use for all responses not specified in this method.
@param: responseSerializer is responseSerializer object to use for the response serializing/parsing of the contentType choosen.
@param: contentType is the content type to map to the response Serializer (e.g application/json to DCJSONResponseSerializer).
*/
-(void)setResponseSerializer:(id<DCHTTPResponseSerializerDelegate>)responseSerializer forContentType:(NSString*)contentType;
/**
This is used to get called back on a download/upload progress.
The progress return is between 0 and 1, just like NSProgressView or UIProgressView (your welcome).
@param: block is the progress block to add.
*/
-(void)setProgress:(DCHTTPTaskProgress)block;
/**
Factory method to create a request with HTTPMethod of GET.
@param: url is the full url you want to load (e.g. http://apple.com)
@return A newly initialized DCHTTPTask.
*/
+(DCHTTPTask*)GET:(NSString*)url;
/**
Factory method to create a request with HTTPMethod of GET.
@param: url is the full url you want to load (e.g. http://apple.com)
@param: parameters to send along with the request.
@return A newly initialized DCHTTPTask.
*/
+(DCHTTPTask*)GET:(NSString*)url parameters:(NSDictionary*)parameters;
/**
Factory method to create a request with HTTPMethod of HEAD.
@param: url is the full url you want to load (e.g. http://apple.com)
@return A newly initialized DCHTTPTask.
*/
+(DCHTTPTask*)HEAD:(NSString*)url;
/**
Factory method to create a request with HTTPMethod of HEAD.
@param: url is the full url you want to load (e.g. http://apple.com)
@param: parameters to send along with the request.
@return A newly initialized DCHTTPTask.
*/
+(DCHTTPTask*)HEAD:(NSString*)url parameters:(NSDictionary*)parameters;
/**
Factory method to create a request with HTTPMethod of DELETE.
@param: url is the full url you want to load (e.g. http://apple.com)
@param: parameters to send along with the request.
@return A newly initialized DCHTTPTask.
*/
+(DCHTTPTask*)DELETE:(NSString*)url parameters:(NSDictionary*)parameters;
/**
Factory method to create a request with HTTPMethod of POST.
@param: url is the full url you want to load (e.g. http://apple.com)
@param: parameters to send along with the request.
@return A newly initialized DCHTTPTask.
*/
+(DCHTTPTask*)POST:(NSString*)url parameters:(NSDictionary*)parameters;
/**
Factory method to create a request with HTTPMethod of PUT.
@param: url is the full url you want to load (e.g. http://apple.com)
@param: parameters to send along with the request.
@return A newly initialized DCHTTPTask.
*/
+(DCHTTPTask*)PUT:(NSString*)url parameters:(NSDictionary*)parameters;
@end