Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 231 lines (171 sloc) 9.713 kb
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
1 //
2 // AppController.m
3 // MGTwitterEngine
4 //
5 // Created by Matt Gemmell on 10/02/2008.
6 // Copyright 2008 Instinctive Code.
7 //
8
9 #import "AppController.h"
10
11 @implementation AppController
12
13
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
14 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
15 {
16 // Put your Twitter username and password here:
c8ba147 Removed -getFollowedTimelineFor:* methods since they are no longer suppo...
Craig Hockenberry authored
17 NSString *username = nil;
18 NSString *password = nil;
c5be05d @stevestreza Added support for OAuth and an XAuth login API
stevestreza authored
19
20 NSString *consumerKey = nil;
21 NSString *consumerSecret = nil;
22
c8ba147 Removed -getFollowedTimelineFor:* methods since they are no longer suppo...
Craig Hockenberry authored
23 // Most API calls require a name and password to be set...
c5be05d @stevestreza Added support for OAuth and an XAuth login API
stevestreza authored
24 if (! username || ! password || !consumerKey || !consumerSecret) {
25 NSLog(@"You forgot to specify your username/password/key/secret in AppController.m, things might not work!");
c8ba147 Removed -getFollowedTimelineFor:* methods since they are no longer suppo...
Craig Hockenberry authored
26 NSLog(@"And if things are mysteriously working without the username/password, it's because NSURLConnection is using a session cookie from another connection.");
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
27 }
28
29 // Create a TwitterEngine and set our login details.
30 twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self];
c5be05d @stevestreza Added support for OAuth and an XAuth login API
stevestreza authored
31 [twitterEngine setUsesSecureConnection:NO];
32 [twitterEngine setConsumerKey:consumerKey secret:consumerSecret];
60d02ad @tarasis Un depreciated setting the username in MGTwitterEngine.
tarasis authored
33 // This has been undepreciated for the purposes of dealing with Lists.
34 // At present the list API calls require you to specify a user that owns the list.
35 [twitterEngine setUsername:username];
c5be05d @stevestreza Added support for OAuth and an XAuth login API
stevestreza authored
36
37 [twitterEngine getXAuthAccessTokenForUsername:username password:password];
38 }
39
40 -(void)runTests{
41 [twitterEngine setAccessToken:token];
42
66f80fe Added documentation and sample code for delivery options.
Craig Hockenberry authored
43 // Configure how the delegate methods are called to deliver results. See MGTwitterEngineDelegate.h for more info
44 //[twitterEngine setDeliveryOptions:MGTwitterEngineDeliveryIndividualResultsOption];
c8ba147 Removed -getFollowedTimelineFor:* methods since they are no longer suppo...
Craig Hockenberry authored
45
46 // Get the public timeline
47 NSLog(@"getPublicTimelineSinceID: connectionIdentifier = %@", [twitterEngine getPublicTimeline]);
48
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
49 // Other types of information available from the API:
50
51 #define TESTING_ID 1131604824
52 #define TESTING_PRIMARY_USER @"gnitset"
53 #define TESTING_SECONDARY_USER @"chockenberry"
54 #define TESTING_MESSAGE_ID 52182684
55
56 // Status methods:
c5be05d @stevestreza Added support for OAuth and an XAuth login API
stevestreza authored
57 NSLog(@"getHomeTimelineFor: connectionIdentifier = %@", [twitterEngine getHomeTimelineSinceID:0 startingAtPage:0 count:20]);
58 NSLog(@"getUserTimelineFor: connectionIdentifier = %@", [twitterEngine getUserTimelineFor:TESTING_SECONDARY_USER sinceID:0 startingAtPage:0 count:3]);
59 NSLog(@"getUpdate: connectionIdentifier = %@", [twitterEngine getUpdate:TESTING_ID]);
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
60 //NSLog(@"sendUpdate: connectionIdentifier = %@", [twitterEngine sendUpdate:[@"This is a test on " stringByAppendingString:[[NSDate date] description]]]);
c5be05d @stevestreza Added support for OAuth and an XAuth login API
stevestreza authored
61 NSLog(@"getRepliesStartingAtPage: connectionIdentifier = %@", [twitterEngine getRepliesStartingAtPage:0]);
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
62 //NSLog(@"deleteUpdate: connectionIdentifier = %@", [twitterEngine deleteUpdate:TESTING_ID]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
63
0b58bc2 @catsby Added method to create lists for authenticated users.
catsby authored
64 // Lists
65 //NSLog(@"get Lists for User:%@ connectionIdentifier = %@", TESTING_PRIMARY_USER, [twitterEngine getListsForUser:TESTING_PRIMARY_USER]);
66
67 // NSString *listName = @"test list 3";
68 // NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"private", @"mode", @"a description", @"description", nil];
69 //
70 // NSLog(@"creating list %@, connection identifier: %@", listName, [twitterEngine createListsForUser:TESTING_PRIMARY_USER withName:listName withOptions:dict]);
71
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
72 // User methods:
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
73 //NSLog(@"getRecentlyUpdatedFriendsFor: connectionIdentifier = %@", [twitterEngine getRecentlyUpdatedFriendsFor:nil startingAtPage:0]);
74 //NSLog(@"getFollowersIncludingCurrentStatus: connectionIdentifier = %@", [twitterEngine getFollowersIncludingCurrentStatus:YES]);
75 //NSLog(@"getUserInformationFor: connectionIdentifier = %@", [twitterEngine getUserInformationFor:TESTING_PRIMARY_USER]);
8784e62 @tarasis Added initial support for the Social Graph API requests.
tarasis authored
76
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
77 // Direct Message methods:
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
78 //NSLog(@"getDirectMessagesSinceID: connectionIdentifier = %@", [twitterEngine getDirectMessagesSinceID:0 startingAtPage:0]);
79 //NSLog(@"getSentDirectMessagesSinceID: connectionIdentifier = %@", [twitterEngine getSentDirectMessagesSinceID:0 startingAtPage:0]);
80 //NSLog(@"sendDirectMessage: connectionIdentifier = %@", [twitterEngine sendDirectMessage:[@"This is a test on " stringByAppendingString:[[NSDate date] description]] to:TESTING_SECONDARY_USER]);
81 //NSLog(@"deleteDirectMessage: connectionIdentifier = %@", [twitterEngine deleteDirectMessage:TESTING_MESSAGE_ID]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
82
83
84 // Friendship methods:
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
85 //NSLog(@"enableUpdatesFor: connectionIdentifier = %@", [twitterEngine enableUpdatesFor:TESTING_SECONDARY_USER]);
86 //NSLog(@"disableUpdatesFor: connectionIdentifier = %@", [twitterEngine disableUpdatesFor:TESTING_SECONDARY_USER]);
87 //NSLog(@"isUser:receivingUpdatesFor: connectionIdentifier = %@", [twitterEngine isUser:TESTING_SECONDARY_USER receivingUpdatesFor:TESTING_PRIMARY_USER]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
88
89
90 // Account methods:
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
91 //NSLog(@"checkUserCredentials: connectionIdentifier = %@", [twitterEngine checkUserCredentials]);
92 //NSLog(@"endUserSession: connectionIdentifier = %@", [twitterEngine endUserSession]);
93 //NSLog(@"setLocation: connectionIdentifier = %@", [twitterEngine setLocation:@"Playing in Xcode with a location that is really long and may or may not get truncated to 30 characters"]);
94 //NSLog(@"setNotificationsDeliveryMethod: connectionIdentifier = %@", [twitterEngine setNotificationsDeliveryMethod:@"none"]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
95 // TODO: Add: account/update_profile_colors
96 // TODO: Add: account/update_profile_image
97 // TODO: Add: account/update_profile_background_image
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
98 //NSLog(@"getRateLimitStatus: connectionIdentifier = %@", [twitterEngine getRateLimitStatus]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
99 // TODO: Add: account/update_profile
100
101 // Favorite methods:
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
102 //NSLog(@"getFavoriteUpdatesFor: connectionIdentifier = %@", [twitterEngine getFavoriteUpdatesFor:nil startingAtPage:0]);
103 //NSLog(@"markUpdate: connectionIdentifier = %@", [twitterEngine markUpdate:TESTING_ID asFavorite:YES]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
104
105 // Notification methods
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
106 //NSLog(@"enableNotificationsFor: connectionIdentifier = %@", [twitterEngine enableNotificationsFor:TESTING_SECONDARY_USER]);
107 //NSLog(@"disableNotificationsFor: connectionIdentifier = %@", [twitterEngine disableNotificationsFor:TESTING_SECONDARY_USER]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
108
109 // Block methods
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
110 //NSLog(@"block: connectionIdentifier = %@", [twitterEngine block:TESTING_SECONDARY_USER]);
111 //NSLog(@"unblock: connectionIdentifier = %@", [twitterEngine unblock:TESTING_SECONDARY_USER]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
112
113 // Help methods:
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
114 //NSLog(@"testService: connectionIdentifier = %@", [twitterEngine testService]);
e744c0b @tarasis Added a LibXML parser for the Social Graph API requests (friends/ids & f...
tarasis authored
115
116 // Social Graph methods
57edfe7 @tarasis Fixed error where I used ints and not "long long" values for the cursor'...
tarasis authored
117 //NSLog(@"getFriendIDsFor: connectionIdentifier = %@", [twitterEngine getFriendIDsFor:TESTING_SECONDARY_USER startingFromCursor:-1]);
118 //NSLog(@"getFollowerIDsFor: connectionIdentifier = %@", [twitterEngine getFollowerIDsFor:TESTING_SECONDARY_USER startingFromCursor:-1]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
119
9463f27 @stevestreza Architectural support for TouchJSON
stevestreza authored
120 #if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
121 // Search method
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
122 //NSLog(@"getSearchResultsForQuery: connectionIdentifier = %@", [twitterEngine getSearchResultsForQuery:TESTING_PRIMARY_USER sinceID:0 startingAtPage:1 count:20]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
123
124 // Trends method
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
125 //NSLog(@"getTrends: connectionIdentifier = %@", [twitterEngine getTrends]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
126 #endif
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
127 }
128
129 - (void)dealloc
130 {
131 [twitterEngine release];
132 [super dealloc];
133 }
134
135
136 #pragma mark MGTwitterEngineDelegate methods
137
138
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
139 - (void)requestSucceeded:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
140 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
141 NSLog(@"Request succeeded for connectionIdentifier = %@", connectionIdentifier);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
142 }
143
144
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
145 - (void)requestFailed:(NSString *)connectionIdentifier withError:(NSError *)error
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
146 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
147 NSLog(@"Request failed for connectionIdentifier = %@, error = %@ (%@)",
148 connectionIdentifier,
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
149 [error localizedDescription],
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
150 [error userInfo]);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
151 }
152
153
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
154 - (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
155 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
156 NSLog(@"Got statuses for %@:\r%@", connectionIdentifier, statuses);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
157 }
158
159
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
160 - (void)directMessagesReceived:(NSArray *)messages forRequest:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
161 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
162 NSLog(@"Got direct messages for %@:\r%@", connectionIdentifier, messages);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
163 }
164
165
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
166 - (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
167 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
168 NSLog(@"Got user info for %@:\r%@", connectionIdentifier, userInfo);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
169 }
170
171
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
172 - (void)miscInfoReceived:(NSArray *)miscInfo forRequest:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
173 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
174 NSLog(@"Got misc info for %@:\r%@", connectionIdentifier, miscInfo);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
175 }
176
8784e62 @tarasis Added initial support for the Social Graph API requests.
tarasis authored
177
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
178 - (void)searchResultsReceived:(NSArray *)searchResults forRequest:(NSString *)connectionIdentifier
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
179 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
180 NSLog(@"Got search results for %@:\r%@", connectionIdentifier, searchResults);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
181 }
182
183
8784e62 @tarasis Added initial support for the Social Graph API requests.
tarasis authored
184 - (void)socialGraphInfoReceived:(NSArray *)socialGraphInfo forRequest:(NSString *)connectionIdentifier
185 {
186 NSLog(@"Got social graph results for %@:\r%@", connectionIdentifier, socialGraphInfo);
187 }
188
be2b3e9 @catsby Added first of user/lists API methods.
catsby authored
189 - (void)userListsReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier
190 {
191 NSLog(@"Got user lists for %@:\r%@", connectionIdentifier, userInfo);
192 }
8784e62 @tarasis Added initial support for the Social Graph API requests.
tarasis authored
193
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
194 - (void)imageReceived:(NSImage *)image forRequest:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
195 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
196 NSLog(@"Got an image for %@: %@", connectionIdentifier, image);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
197
198 // Save image to the Desktop.
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
199 NSString *path = [[NSString stringWithFormat:@"~/Desktop/%@.tiff", connectionIdentifier] stringByExpandingTildeInPath];
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
200 [[image TIFFRepresentation] writeToFile:path atomically:NO];
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
201 }
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
202
c8ba147 Removed -getFollowedTimelineFor:* methods since they are no longer suppo...
Craig Hockenberry authored
203 - (void)connectionFinished:(NSString *)connectionIdentifier
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
204 {
c8ba147 Removed -getFollowedTimelineFor:* methods since they are no longer suppo...
Craig Hockenberry authored
205 NSLog(@"Connection finished %@", connectionIdentifier);
206
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
207 if ([twitterEngine numberOfConnections] == 0)
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
208 {
209 [NSApp terminate:self];
210 }
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
211 }
212
c5be05d @stevestreza Added support for OAuth and an XAuth login API
stevestreza authored
213 - (void)accessTokenReceived:(OAToken *)aToken forRequest:(NSString *)connectionIdentifier
214 {
215 NSLog(@"Access token received! %@",aToken);
216
217 token = [aToken retain];
218 [self runTests];
219 }
220
9463f27 @stevestreza Architectural support for TouchJSON
stevestreza authored
221 #if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
fd65d2c Added delegate callback for each parsed object.
Craig Hockenberry authored
222
223 - (void)receivedObject:(NSDictionary *)dictionary forRequest:(NSString *)connectionIdentifier
224 {
225 NSLog(@"Got an object for %@: %@", connectionIdentifier, dictionary);
226 }
227
228 #endif
229
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
230 @end
Something went wrong with that request. Please try again.