Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 187 lines (137 sloc) 7.703 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
12 @implementation AppController
13
14
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
15 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
16 {
17 // Put your Twitter username and password here:
c8ba147 Removed -getFollowedTimelineFor:* methods since they are no longer suppo...
Craig Hockenberry authored
18 NSString *username = nil;
19 NSString *password = nil;
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
20
c8ba147 Removed -getFollowedTimelineFor:* methods since they are no longer suppo...
Craig Hockenberry authored
21 // Most API calls require a name and password to be set...
22 if (! username || ! password) {
23 NSLog(@"You forgot to specify your username/password in AppController.m, things might not work!");
24 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
25 }
26
27 // Create a TwitterEngine and set our login details.
28 twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self];
29 [twitterEngine setUsername:username password:password];
30
66f80fe Added documentation and sample code for delivery options.
Craig Hockenberry authored
31 // Configure how the delegate methods are called to deliver results. See MGTwitterEngineDelegate.h for more info
32 //[twitterEngine setDeliveryOptions:MGTwitterEngineDeliveryIndividualResultsOption];
c8ba147 Removed -getFollowedTimelineFor:* methods since they are no longer suppo...
Craig Hockenberry authored
33
34 // Get the public timeline
35 NSLog(@"getPublicTimelineSinceID: connectionIdentifier = %@", [twitterEngine getPublicTimeline]);
36
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
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:
c8ba147 Removed -getFollowedTimelineFor:* methods since they are no longer suppo...
Craig Hockenberry authored
45 //NSLog(@"getUserTimelineFor: connectionIdentifier = %@", [twitterEngine getUserTimelineFor:TESTING_SECONDARY_USER sinceID:0 startingAtPage:0 count:3]);
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
46 //NSLog(@"getUpdate: connectionIdentifier = %@", [twitterEngine getUpdate:TESTING_ID]);
47 //NSLog(@"sendUpdate: connectionIdentifier = %@", [twitterEngine sendUpdate:[@"This is a test on " stringByAppendingString:[[NSDate date] description]]]);
48 //NSLog(@"getRepliesStartingAtPage: connectionIdentifier = %@", [twitterEngine getRepliesStartingAtPage:0]);
49 //NSLog(@"deleteUpdate: connectionIdentifier = %@", [twitterEngine deleteUpdate:TESTING_ID]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
50
51 // User methods:
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
52 //NSLog(@"getRecentlyUpdatedFriendsFor: connectionIdentifier = %@", [twitterEngine getRecentlyUpdatedFriendsFor:nil startingAtPage:0]);
53 //NSLog(@"getFollowersIncludingCurrentStatus: connectionIdentifier = %@", [twitterEngine getFollowersIncludingCurrentStatus:YES]);
54 //NSLog(@"getUserInformationFor: connectionIdentifier = %@", [twitterEngine getUserInformationFor:TESTING_PRIMARY_USER]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
55
56 // Direct Message methods:
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
57 //NSLog(@"getDirectMessagesSinceID: connectionIdentifier = %@", [twitterEngine getDirectMessagesSinceID:0 startingAtPage:0]);
58 //NSLog(@"getSentDirectMessagesSinceID: connectionIdentifier = %@", [twitterEngine getSentDirectMessagesSinceID:0 startingAtPage:0]);
59 //NSLog(@"sendDirectMessage: connectionIdentifier = %@", [twitterEngine sendDirectMessage:[@"This is a test on " stringByAppendingString:[[NSDate date] description]] to:TESTING_SECONDARY_USER]);
60 //NSLog(@"deleteDirectMessage: connectionIdentifier = %@", [twitterEngine deleteDirectMessage:TESTING_MESSAGE_ID]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
61
62
63 // Friendship methods:
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
64 //NSLog(@"enableUpdatesFor: connectionIdentifier = %@", [twitterEngine enableUpdatesFor:TESTING_SECONDARY_USER]);
65 //NSLog(@"disableUpdatesFor: connectionIdentifier = %@", [twitterEngine disableUpdatesFor:TESTING_SECONDARY_USER]);
66 //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
67
68
69 // Account methods:
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
70 //NSLog(@"checkUserCredentials: connectionIdentifier = %@", [twitterEngine checkUserCredentials]);
71 //NSLog(@"endUserSession: connectionIdentifier = %@", [twitterEngine endUserSession]);
72 //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"]);
73 //NSLog(@"setNotificationsDeliveryMethod: connectionIdentifier = %@", [twitterEngine setNotificationsDeliveryMethod:@"none"]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
74 // TODO: Add: account/update_profile_colors
75 // TODO: Add: account/update_profile_image
76 // TODO: Add: account/update_profile_background_image
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
77 //NSLog(@"getRateLimitStatus: connectionIdentifier = %@", [twitterEngine getRateLimitStatus]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
78 // TODO: Add: account/update_profile
79
80 // Favorite methods:
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
81 //NSLog(@"getFavoriteUpdatesFor: connectionIdentifier = %@", [twitterEngine getFavoriteUpdatesFor:nil startingAtPage:0]);
82 //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
83
84 // Notification methods
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
85 //NSLog(@"enableNotificationsFor: connectionIdentifier = %@", [twitterEngine enableNotificationsFor:TESTING_SECONDARY_USER]);
86 //NSLog(@"disableNotificationsFor: connectionIdentifier = %@", [twitterEngine disableNotificationsFor:TESTING_SECONDARY_USER]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
87
88 // Block methods
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
89 //NSLog(@"block: connectionIdentifier = %@", [twitterEngine block:TESTING_SECONDARY_USER]);
90 //NSLog(@"unblock: connectionIdentifier = %@", [twitterEngine unblock:TESTING_SECONDARY_USER]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
91
92 // Help methods:
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
93 //NSLog(@"testService: connectionIdentifier = %@", [twitterEngine testService]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
94
95 #if YAJL_AVAILABLE
96 // Search method
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
97 //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
98
99 // Trends method
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
100 //NSLog(@"getTrends: connectionIdentifier = %@", [twitterEngine getTrends]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
101 #endif
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
102 }
103
104 - (void)dealloc
105 {
106 [twitterEngine release];
107 [super dealloc];
108 }
109
110
111 #pragma mark MGTwitterEngineDelegate methods
112
113
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
114 - (void)requestSucceeded:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
115 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
116 NSLog(@"Request succeeded for connectionIdentifier = %@", connectionIdentifier);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
117 }
118
119
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
120 - (void)requestFailed:(NSString *)connectionIdentifier withError:(NSError *)error
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
121 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
122 NSLog(@"Request failed for connectionIdentifier = %@, error = %@ (%@)",
123 connectionIdentifier,
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
124 [error localizedDescription],
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
125 [error userInfo]);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
126 }
127
128
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
129 - (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
130 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
131 NSLog(@"Got statuses for %@:\r%@", connectionIdentifier, statuses);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
132 }
133
134
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
135 - (void)directMessagesReceived:(NSArray *)messages forRequest:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
136 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
137 NSLog(@"Got direct messages for %@:\r%@", connectionIdentifier, messages);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
138 }
139
140
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
141 - (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
142 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
143 NSLog(@"Got user info for %@:\r%@", connectionIdentifier, userInfo);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
144 }
145
146
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
147 - (void)miscInfoReceived:(NSArray *)miscInfo forRequest:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
148 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
149 NSLog(@"Got misc info for %@:\r%@", connectionIdentifier, miscInfo);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
150 }
151
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
152 - (void)searchResultsReceived:(NSArray *)searchResults forRequest:(NSString *)connectionIdentifier
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
153 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
154 NSLog(@"Got search results for %@:\r%@", connectionIdentifier, searchResults);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
155 }
156
157
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
158 - (void)imageReceived:(NSImage *)image forRequest:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
159 {
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
160 NSLog(@"Got an image for %@: %@", connectionIdentifier, image);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
161
162 // Save image to the Desktop.
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
163 NSString *path = [[NSString stringWithFormat:@"~/Desktop/%@.tiff", connectionIdentifier] stringByExpandingTildeInPath];
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
164 [[image TIFFRepresentation] writeToFile:path atomically:NO];
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
165 }
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
166
c8ba147 Removed -getFollowedTimelineFor:* methods since they are no longer suppo...
Craig Hockenberry authored
167 - (void)connectionFinished:(NSString *)connectionIdentifier
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
168 {
c8ba147 Removed -getFollowedTimelineFor:* methods since they are no longer suppo...
Craig Hockenberry authored
169 NSLog(@"Connection finished %@", connectionIdentifier);
170
1f94767 Added new delegate method that is called whenever a connection is finish...
Craig Hockenberry authored
171 if ([twitterEngine numberOfConnections] == 0)
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the ap...
Craig Hockenberry authored
172 {
173 [NSApp terminate:self];
174 }
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
175 }
176
fd65d2c Added delegate callback for each parsed object.
Craig Hockenberry authored
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
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
186 @end
Something went wrong with that request. Please try again.