forked from mattgemmell/MGTwitterEngine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MGTwitterHTTPURLConnection.m
116 lines (76 loc) · 1.88 KB
/
MGTwitterHTTPURLConnection.m
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
//
// MGTwitterHTTPURLConnection.m
// MGTwitterEngine
//
// Created by Matt Gemmell on 16/02/2008.
// Copyright 2008 Instinctive Code.
//
#import "MGTwitterHTTPURLConnection.h"
#import "NSString+UUID.h"
@interface NSURLRequest (OAuthExtensions)
-(void)prepare;
@end
@implementation NSURLRequest (OAuthExtensions)
-(void)prepare{
// do nothing
}
@end
@implementation MGTwitterHTTPURLConnection
#pragma mark Initializer
- (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate
requestType:(MGTwitterRequestType)requestType responseType:(MGTwitterResponseType)responseType
{
// OAuth requests need to have -prepare called on them first. handle that case before the NSURLConnection sends it
[request prepare];
if ((self = [super initWithRequest:request delegate:delegate])) {
_data = [[NSMutableData alloc] initWithCapacity:0];
_identifier = [[NSString stringWithNewUUID] retain];
_requestType = requestType;
_responseType = responseType;
_URL = [[request URL] retain];
}
return self;
}
- (void)dealloc
{
[_data release];
[_identifier release];
[_URL release];
[super dealloc];
}
#pragma mark Data helper methods
- (void)resetDataLength
{
[_data setLength:0];
}
- (void)appendData:(NSData *)data
{
[_data appendData:data];
}
#pragma mark Accessors
- (NSString *)identifier
{
return [[_identifier retain] autorelease];
}
- (NSData *)data
{
return [[_data retain] autorelease];
}
- (NSURL *)URL
{
return [[_URL retain] autorelease];
}
- (MGTwitterRequestType)requestType
{
return _requestType;
}
- (MGTwitterResponseType)responseType
{
return _responseType;
}
- (NSString *)description
{
NSString *description = [super description];
return [description stringByAppendingFormat:@" (requestType = %d, identifier = %@)", _requestType, _identifier];
}
@end