Skip to content
This repository
Newer
Older
100644 186 lines (137 sloc) 7.697 kb
96b20531 »
2008-08-09 MGTwitterEngine re-import.
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
12 @implementation AppController
13
14
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
15 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
96b20531 »
2008-08-09 MGTwitterEngine re-import.
16 {
17 // Put your Twitter username and password here:
18 NSString *username = @"";
19 NSString *password = @"";
20
21 // Make sure you entered your login details before running this code... ;)
22 if ([username isEqualToString:@""] || [password isEqualToString:@""]) {
23 NSLog(@"You forgot to specify your username/password in AppController.m!");
24 [NSApp terminate:self];
25 }
26
27 // Create a TwitterEngine and set our login details.
28 twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self];
29 [twitterEngine setUsername:username password:password];
30
66f80fe4 » Craig Hockenberry
2009-01-22 Added documentation and sample code for delivery options.
31 // Configure how the delegate methods are called to deliver results. See MGTwitterEngineDelegate.h for more info
32 //[twitterEngine setDeliveryOptions:MGTwitterEngineDeliveryIndividualResultsOption];
33
96b20531 »
2008-08-09 MGTwitterEngine re-import.
34 // Get updates from people the authenticated user follows.
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
35 //NSLog(@"getFollowedTimelineFor: connectionIdentifier = %@", [twitterEngine getFollowedTimelineFor:nil since:nil startingAtPage:0]);
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
36
37 // Other types of information available from the API:
38
39 #define TESTING_ID 1131604824
40 #define TESTING_PRIMARY_USER @"gnitset"
41 #define TESTING_SECONDARY_USER @"chockenberry"
42 #define TESTING_MESSAGE_ID 52182684
43
44 // Status methods:
45
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
46 NSLog(@"getPublicTimelineSinceID: connectionIdentifier = %@", [twitterEngine getPublicTimelineSinceID:0]);
47 //NSLog(@"getUserTimelineFor: connectionIdentifier = %@", [twitterEngine getUserTimelineFor:TESTING_SECONDARY_USER sinceID:0 startingAtPage:0 count:20]);
48 //NSLog(@"getUpdate: connectionIdentifier = %@", [twitterEngine getUpdate:TESTING_ID]);
49 //NSLog(@"sendUpdate: connectionIdentifier = %@", [twitterEngine sendUpdate:[@"This is a test on " stringByAppendingString:[[NSDate date] description]]]);
50 //NSLog(@"getRepliesStartingAtPage: connectionIdentifier = %@", [twitterEngine getRepliesStartingAtPage:0]);
51 //NSLog(@"deleteUpdate: connectionIdentifier = %@", [twitterEngine deleteUpdate:TESTING_ID]);
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
52
53 // User methods:
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
54 //NSLog(@"getRecentlyUpdatedFriendsFor: connectionIdentifier = %@", [twitterEngine getRecentlyUpdatedFriendsFor:nil startingAtPage:0]);
55 //NSLog(@"getFollowersIncludingCurrentStatus: connectionIdentifier = %@", [twitterEngine getFollowersIncludingCurrentStatus:YES]);
56 //NSLog(@"getUserInformationFor: connectionIdentifier = %@", [twitterEngine getUserInformationFor:TESTING_PRIMARY_USER]);
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
57
58 // Direct Message methods:
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
59 //NSLog(@"getDirectMessagesSinceID: connectionIdentifier = %@", [twitterEngine getDirectMessagesSinceID:0 startingAtPage:0]);
60 //NSLog(@"getSentDirectMessagesSinceID: connectionIdentifier = %@", [twitterEngine getSentDirectMessagesSinceID:0 startingAtPage:0]);
61 //NSLog(@"sendDirectMessage: connectionIdentifier = %@", [twitterEngine sendDirectMessage:[@"This is a test on " stringByAppendingString:[[NSDate date] description]] to:TESTING_SECONDARY_USER]);
62 //NSLog(@"deleteDirectMessage: connectionIdentifier = %@", [twitterEngine deleteDirectMessage:TESTING_MESSAGE_ID]);
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
63
64
65 // Friendship methods:
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
66 //NSLog(@"enableUpdatesFor: connectionIdentifier = %@", [twitterEngine enableUpdatesFor:TESTING_SECONDARY_USER]);
67 //NSLog(@"disableUpdatesFor: connectionIdentifier = %@", [twitterEngine disableUpdatesFor:TESTING_SECONDARY_USER]);
68 //NSLog(@"isUser:receivingUpdatesFor: connectionIdentifier = %@", [twitterEngine isUser:TESTING_SECONDARY_USER receivingUpdatesFor:TESTING_PRIMARY_USER]);
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
69
70
71 // Account methods:
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
72 //NSLog(@"checkUserCredentials: connectionIdentifier = %@", [twitterEngine checkUserCredentials]);
73 //NSLog(@"endUserSession: connectionIdentifier = %@", [twitterEngine endUserSession]);
74 //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"]);
75 //NSLog(@"setNotificationsDeliveryMethod: connectionIdentifier = %@", [twitterEngine setNotificationsDeliveryMethod:@"none"]);
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
76 // TODO: Add: account/update_profile_colors
77 // TODO: Add: account/update_profile_image
78 // TODO: Add: account/update_profile_background_image
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
79 //NSLog(@"getRateLimitStatus: connectionIdentifier = %@", [twitterEngine getRateLimitStatus]);
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
80 // TODO: Add: account/update_profile
81
82 // Favorite methods:
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
83 //NSLog(@"getFavoriteUpdatesFor: connectionIdentifier = %@", [twitterEngine getFavoriteUpdatesFor:nil startingAtPage:0]);
84 //NSLog(@"markUpdate: connectionIdentifier = %@", [twitterEngine markUpdate:TESTING_ID asFavorite:YES]);
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
85
86 // Notification methods
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
87 //NSLog(@"enableNotificationsFor: connectionIdentifier = %@", [twitterEngine enableNotificationsFor:TESTING_SECONDARY_USER]);
88 //NSLog(@"disableNotificationsFor: connectionIdentifier = %@", [twitterEngine disableNotificationsFor:TESTING_SECONDARY_USER]);
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
89
90 // Block methods
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
91 //NSLog(@"block: connectionIdentifier = %@", [twitterEngine block:TESTING_SECONDARY_USER]);
92 //NSLog(@"unblock: connectionIdentifier = %@", [twitterEngine unblock:TESTING_SECONDARY_USER]);
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
93
94 // Help methods:
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
95 //NSLog(@"testService: connectionIdentifier = %@", [twitterEngine testService]);
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
96
97 #if YAJL_AVAILABLE
98 // Search method
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
99 //NSLog(@"getSearchResultsForQuery: connectionIdentifier = %@", [twitterEngine getSearchResultsForQuery:TESTING_PRIMARY_USER sinceID:0 startingAtPage:1 count:20]);
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
100
101 // Trends method
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
102 //NSLog(@"getTrends: connectionIdentifier = %@", [twitterEngine getTrends]);
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
103 #endif
96b20531 »
2008-08-09 MGTwitterEngine re-import.
104 }
105
106 - (void)dealloc
107 {
108 [twitterEngine release];
109 [super dealloc];
110 }
111
112
113 #pragma mark MGTwitterEngineDelegate methods
114
115
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
116 - (void)requestSucceeded:(NSString *)connectionIdentifier
96b20531 »
2008-08-09 MGTwitterEngine re-import.
117 {
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
118 NSLog(@"Request succeeded for connectionIdentifier = %@", connectionIdentifier);
96b20531 »
2008-08-09 MGTwitterEngine re-import.
119 }
120
121
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
122 - (void)requestFailed:(NSString *)connectionIdentifier withError:(NSError *)error
96b20531 »
2008-08-09 MGTwitterEngine re-import.
123 {
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
124 NSLog(@"Request failed for connectionIdentifier = %@, error = %@ (%@)",
125 connectionIdentifier,
96b20531 »
2008-08-09 MGTwitterEngine re-import.
126 [error localizedDescription],
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
127 [error userInfo]);
96b20531 »
2008-08-09 MGTwitterEngine re-import.
128 }
129
130
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
131 - (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier
96b20531 »
2008-08-09 MGTwitterEngine re-import.
132 {
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
133 NSLog(@"Got statuses for %@:\r%@", connectionIdentifier, statuses);
96b20531 »
2008-08-09 MGTwitterEngine re-import.
134 }
135
136
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
137 - (void)directMessagesReceived:(NSArray *)messages forRequest:(NSString *)connectionIdentifier
96b20531 »
2008-08-09 MGTwitterEngine re-import.
138 {
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
139 NSLog(@"Got direct messages for %@:\r%@", connectionIdentifier, messages);
96b20531 »
2008-08-09 MGTwitterEngine re-import.
140 }
141
142
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
143 - (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier
96b20531 »
2008-08-09 MGTwitterEngine re-import.
144 {
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
145 NSLog(@"Got user info for %@:\r%@", connectionIdentifier, userInfo);
96b20531 »
2008-08-09 MGTwitterEngine re-import.
146 }
147
148
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
149 - (void)miscInfoReceived:(NSArray *)miscInfo forRequest:(NSString *)connectionIdentifier
96b20531 »
2008-08-09 MGTwitterEngine re-import.
150 {
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
151 NSLog(@"Got misc info for %@:\r%@", connectionIdentifier, miscInfo);
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
152 }
153
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
154 - (void)searchResultsReceived:(NSArray *)searchResults forRequest:(NSString *)connectionIdentifier
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
155 {
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
156 NSLog(@"Got search results for %@:\r%@", connectionIdentifier, searchResults);
96b20531 »
2008-08-09 MGTwitterEngine re-import.
157 }
158
159
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
160 - (void)imageReceived:(NSImage *)image forRequest:(NSString *)connectionIdentifier
96b20531 »
2008-08-09 MGTwitterEngine re-import.
161 {
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
162 NSLog(@"Got an image for %@: %@", connectionIdentifier, image);
96b20531 »
2008-08-09 MGTwitterEngine re-import.
163
164 // Save image to the Desktop.
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
165 NSString *path = [[NSString stringWithFormat:@"~/Desktop/%@.tiff", connectionIdentifier] stringByExpandingTildeInPath];
96b20531 »
2008-08-09 MGTwitterEngine re-import.
166 [[image TIFFRepresentation] writeToFile:path atomically:NO];
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
167 }
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
168
1f947673 » Craig Hockenberry
2009-01-21 Added new delegate method that is called whenever a connection is fin…
169 - (void)connectionFinished
170 {
171 if ([twitterEngine numberOfConnections] == 0)
5f8fb9c7 » Craig Hockenberry
2009-01-21 Code and documentation cleanup. Added many more tests/examples to the…
172 {
173 [NSApp terminate:self];
174 }
96b20531 »
2008-08-09 MGTwitterEngine re-import.
175 }
176
fd65d2ce » Craig Hockenberry
2009-01-21 Added delegate callback for each parsed object.
177 #if YAJL_AVAILABLE
178
179 - (void)receivedObject:(NSDictionary *)dictionary forRequest:(NSString *)connectionIdentifier
180 {
181 NSLog(@"Got an object for %@: %@", connectionIdentifier, dictionary);
182 }
183
184 #endif
185
96b20531 »
2008-08-09 MGTwitterEngine re-import.
186 @end
Something went wrong with that request. Please try again.