-
Notifications
You must be signed in to change notification settings - Fork 3
/
WBRequest.h
85 lines (65 loc) · 2.85 KB
/
WBRequest.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// WBRequest.h
// SinaWeiBoSDK
// Based on OAuth 2.0
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright 2011 Sina. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef enum
{
kWBRequestPostDataTypeNone,
kWBRequestPostDataTypeNormal, // for normal data post, such as "user=name&password=psd"
kWBRequestPostDataTypeMultipart, // for uploading images and files.
}WBRequestPostDataType;
@class WBRequest;
@protocol WBRequestDelegate <NSObject>
@optional
- (void)request:(WBRequest *)request didReceiveResponse:(NSURLResponse *)response;
- (void)request:(WBRequest *)request didReceiveRawData:(NSData *)data;
- (void)request:(WBRequest *)request didFailWithError:(NSError *)error;
- (void)request:(WBRequest *)request didFinishLoadingWithResult:(id)result;
@end
@interface WBRequest : NSObject
{
NSString *url;
NSString *httpMethod;
NSDictionary *params;
WBRequestPostDataType postDataType;
NSDictionary *httpHeaderFields;
NSURLConnection *connection;
NSMutableData *responseData;
id<WBRequestDelegate> delegate;
}
@property (nonatomic, retain) NSString *url;
@property (nonatomic, retain) NSString *httpMethod;
@property (nonatomic, retain) NSDictionary *params;
@property WBRequestPostDataType postDataType;
@property (nonatomic, retain) NSDictionary *httpHeaderFields;
@property (nonatomic, assign) id<WBRequestDelegate> delegate;
+ (WBRequest *)requestWithURL:(NSString *)url
httpMethod:(NSString *)httpMethod
params:(NSDictionary *)params
postDataType:(WBRequestPostDataType)postDataType
httpHeaderFields:(NSDictionary *)httpHeaderFields
delegate:(id<WBRequestDelegate>)delegate;
+ (WBRequest *)requestWithAccessToken:(NSString *)accessToken
url:(NSString *)url
httpMethod:(NSString *)httpMethod
params:(NSDictionary *)params
postDataType:(WBRequestPostDataType)postDataType
httpHeaderFields:(NSDictionary *)httpHeaderFields
delegate:(id<WBRequestDelegate>)delegate;
+ (NSString *)serializeURL:(NSString *)baseURL params:(NSDictionary *)params httpMethod:(NSString *)httpMethod;
- (void)connect;
- (void)disconnect;
@end