-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIRWebAPITwitterInterface.m
More file actions
173 lines (91 loc) · 4.84 KB
/
IRWebAPITwitterInterface.m
File metadata and controls
173 lines (91 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//
// IRWebAPITwitterInterface.m
// IRWebAPIKit
//
// Created by Evadne Wu on 12/1/10.
// Copyright 2010 Iridia Productions. All rights reserved.
//
#import "IRWebAPITwitterInterface.h"
@implementation IRWebAPITwitterInterface
@synthesize defaultBatchSize;
@synthesize consumerKey, consumerSecret;
@dynamic authenticator;
- (id) init {
IRWebAPIContext *twitterContext = [[[IRWebAPIContext alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.twitter.com/"]] autorelease];
IRWebAPIEngine *twitterEngine = [[[IRWebAPIEngine alloc] initWithContext:twitterContext] autorelease];
twitterEngine.parser = IRWebAPIResponseDefaultJSONParserMake();
IRWebAPIXOAuthAuthenticator *twitterAuthenticator = [[[IRWebAPIXOAuthAuthenticator alloc] initWithEngine:twitterEngine] autorelease];
self = [self initWithEngine:twitterEngine authenticator:twitterAuthenticator];
if (!self) return nil;
self.defaultBatchSize = 200;
return self;
}
- (void) dealloc {
// IRWebAPIInterfaceXOAuthAuthenticating
self.consumerKey = nil;
self.consumerSecret = nil;
[super dealloc];
}
- (void) setConsumerKey:(NSString *)inConsumerKey {
((IRWebAPIXOAuthAuthenticator *)(self.authenticator)).consumerKey = inConsumerKey;
}
- (NSString *) consumerKey {
return ((IRWebAPIXOAuthAuthenticator *)(self.authenticator)).consumerKey;
}
- (void) setConsumerSecret:(NSString *)inConsumerSecret {
((IRWebAPIXOAuthAuthenticator *)(self.authenticator)).consumerSecret = inConsumerSecret;
}
- (NSString *) consumerSecret {
return ((IRWebAPIXOAuthAuthenticator *)(self.authenticator)).consumerSecret;
}
- (void) authenticateCredentials:(IRWebAPICredentials *)inCredentials onSuccess:(IRWebAPIAuthenticatorCallback)successHandler onFailure:(IRWebAPIAuthenticatorCallback)failureHandler {
NSLog(@"%@ %s", self, __PRETTY_FUNCTION__);
NSLog(@"My authenticator , %@", self.authenticator);
[self.authenticator authenticateCredentials:inCredentials onSuccess: ^ (IRWebAPIAuthenticator *inAuthenticator, BOOL isAuthenticated, BOOL *inShouldRetry) {
NSLog(@"authentication is done.");
if (!isAuthenticated) {
*inShouldRetry = YES;
return;
}
if (successHandler)
successHandler(inAuthenticator, isAuthenticated, inShouldRetry);
} onFailure: ^ (IRWebAPIAuthenticator *inAuthenticator, BOOL isAuthenticated, BOOL *inShouldRetry) {
NSLog(@"Failed. %@", self);
if (failureHandler)
failureHandler(inAuthenticator, isAuthenticated, inShouldRetry);
}];
}
- (void) updateStatusForCurrentUserWithContents:(NSString *)inContents userInfo:(NSDictionary *)inUserInfo onSuccess:(IRWebAPIInterfaceCallback)inSuccessCallback onFailure:(IRWebAPIInterfaceCallback)inFailureCallback {
[self.engine fireAPIRequestNamed:@"1/statuses/update.json" withArguments:[NSDictionary dictionaryWithObjectsAndKeys:
inContents, @"status",
[NSString stringWithFormat:@"%llu", [(NSNumber *)[inUserInfo objectForKey:@"replyingStatusIdentifier"] unsignedLongLongValue]], @"in_reply_to_status_id",
[inUserInfo objectForKey:@"latitude"], @"lat",
[inUserInfo objectForKey:@"longitude"], @"lng",
[inUserInfo objectForKey:@"placeIdentifier"], @"placeID",
[inUserInfo objectForKey:@"displaysCoordinates"], @"display_coordinates",
[NSNumber numberWithBool:YES], @"include_entities",
nil] options:[NSDictionary dictionaryWithObjectsAndKeys:
@"POST", kIRWebAPIEngineRequestHTTPMethod,
nil] validator: ^ (NSDictionary *inResponseOrNil, NSDictionary *inResponseContext) {
id returnedError = [inResponseOrNil objectForKey:@"error"];
return (BOOL)(returnedError == nil);
} successHandler: ^ (NSDictionary *inResponseOrNil, NSDictionary *inResponseContext, BOOL *outNotifyDelegate, BOOL *outShouldRetry) {
NSLog(@"statuses/update response: %@", inResponseOrNil);
if (inSuccessCallback)
inSuccessCallback(inResponseOrNil, outNotifyDelegate, outShouldRetry);
} failureHandler: ^ (NSDictionary *inResponseOrNil, NSDictionary *inResponseContext, BOOL *outNotifyDelegate, BOOL *outShouldRetry) {
NSLog(@"Failed. %@", inResponseOrNil);
if (inFailureCallback)
inFailureCallback(inResponseOrNil, outNotifyDelegate, outShouldRetry);
}];
}
- (void) lookupCurrentUserWithSuccessHandler:(IRWebAPIInterfaceCallback)inSuccessCallback failureHandler:(IRWebAPIInterfaceCallback)inFailureCallback {
[self.engine fireAPIRequestNamed:@"1/account/verify_credentials.json" withArguments:nil options:nil validator:nil successHandler: ^ (NSDictionary *inResponseOrNil, NSDictionary *inResponseContext, BOOL *outNotifyDelegate, BOOL *outShouldRetry) {
if (inSuccessCallback)
inSuccessCallback(inResponseOrNil, outNotifyDelegate, outShouldRetry);
} failureHandler: ^ (NSDictionary *inResponseOrNil, NSDictionary *inResponseContext, BOOL *outNotifyDelegate, BOOL *outShouldRetry) {
if (inFailureCallback)
inFailureCallback(inResponseOrNil, outNotifyDelegate, outShouldRetry);
}];
}
@end