-
Notifications
You must be signed in to change notification settings - Fork 164
/
MGTwitterHTTPURLConnection.m
119 lines (78 loc) · 1.93 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
117
118
119
//
// 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
@synthesize response = _response;
#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
{
[_response release];
[_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