Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 201 lines (147 sloc) 8.487 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…
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 su…
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 su…
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 su…
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…
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 su…
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 fin…
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…
Craig Hockenberry authored
50
51 // User methods:
1f94767 Added new delegate method that is called whenever a connection is fin…
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]);
8784e62 @tarasis Added initial support for the Social Graph API requests.
tarasis authored
55 //NSLog(@"getFriendIDsFor: connectionIdentifier = %@", [twitterEngine getFriendIDsFor:@"duemoko" startingFromCursor:-1]);
56 //NSLog(@"getFollowerIDsFor: connectionIdentifier = %@", [twitterEngine getFollowerIDsFor:username startingFromCursor:-1]);
57
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the…
Craig Hockenberry authored
58 // Direct Message methods:
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
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]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the…
Craig Hockenberry authored
63
64
65 // Friendship methods:
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
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]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the…
Craig Hockenberry authored
69
70
71 // Account methods:
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
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"]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the…
Craig Hockenberry authored
76 // TODO: Add: account/update_profile_colors
77 // TODO: Add: account/update_profile_image
78 // TODO: Add: account/update_profile_background_image
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
79 //NSLog(@"getRateLimitStatus: connectionIdentifier = %@", [twitterEngine getRateLimitStatus]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the…
Craig Hockenberry authored
80 // TODO: Add: account/update_profile
81
82 // Favorite methods:
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
83 //NSLog(@"getFavoriteUpdatesFor: connectionIdentifier = %@", [twitterEngine getFavoriteUpdatesFor:nil startingAtPage:0]);
84 //NSLog(@"markUpdate: connectionIdentifier = %@", [twitterEngine markUpdate:TESTING_ID asFavorite:YES]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the…
Craig Hockenberry authored
85
86 // Notification methods
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
87 //NSLog(@"enableNotificationsFor: connectionIdentifier = %@", [twitterEngine enableNotificationsFor:TESTING_SECONDARY_USER]);
88 //NSLog(@"disableNotificationsFor: connectionIdentifier = %@", [twitterEngine disableNotificationsFor:TESTING_SECONDARY_USER]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the…
Craig Hockenberry authored
89
90 // Block methods
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
91 //NSLog(@"block: connectionIdentifier = %@", [twitterEngine block:TESTING_SECONDARY_USER]);
92 //NSLog(@"unblock: connectionIdentifier = %@", [twitterEngine unblock:TESTING_SECONDARY_USER]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the…
Craig Hockenberry authored
93
94 // Help methods:
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
95 //NSLog(@"testService: connectionIdentifier = %@", [twitterEngine testService]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the…
Craig Hockenberry authored
96
97 #if YAJL_AVAILABLE
98 // Search method
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
99 //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…
Craig Hockenberry authored
100
101 // Trends method
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
102 //NSLog(@"getTrends: connectionIdentifier = %@", [twitterEngine getTrends]);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the…
Craig Hockenberry authored
103 #endif
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
104 }
105
106 - (void)dealloc
107 {
108 [twitterEngine release];
109 [super dealloc];
110 }
111
112
113 #pragma mark MGTwitterEngineDelegate methods
114
115
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
116 - (void)requestSucceeded:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
117 {
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
118 NSLog(@"Request succeeded for connectionIdentifier = %@", connectionIdentifier);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
119 }
120
121
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
122 - (void)requestFailed:(NSString *)connectionIdentifier withError:(NSError *)error
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
123 {
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
124 NSLog(@"Request failed for connectionIdentifier = %@, error = %@ (%@)",
125 connectionIdentifier,
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
126 [error localizedDescription],
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the…
Craig Hockenberry authored
127 [error userInfo]);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
128 }
129
130
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
131 - (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
132 {
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
133 NSLog(@"Got statuses for %@:\r%@", connectionIdentifier, statuses);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
134 }
135
136
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
137 - (void)directMessagesReceived:(NSArray *)messages forRequest:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
138 {
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
139 NSLog(@"Got direct messages for %@:\r%@", connectionIdentifier, messages);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
140 }
141
142
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
143 - (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
144 {
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
145 NSLog(@"Got user info for %@:\r%@", connectionIdentifier, userInfo);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
146 }
147
148
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
149 - (void)miscInfoReceived:(NSArray *)miscInfo forRequest:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
150 {
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
151 NSLog(@"Got misc info for %@:\r%@", connectionIdentifier, miscInfo);
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the…
Craig Hockenberry authored
152 }
153
8784e62 @tarasis Added initial support for the Social Graph API requests.
tarasis authored
154
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
155 - (void)searchResultsReceived:(NSArray *)searchResults forRequest:(NSString *)connectionIdentifier
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the…
Craig Hockenberry authored
156 {
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
157 NSLog(@"Got search results for %@:\r%@", connectionIdentifier, searchResults);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
158 }
159
160
8784e62 @tarasis Added initial support for the Social Graph API requests.
tarasis authored
161 - (void)socialGraphInfoReceived:(NSArray *)socialGraphInfo forRequest:(NSString *)connectionIdentifier
162 {
163 NSLog(@"Got social graph results for %@:\r%@", connectionIdentifier, socialGraphInfo);
164
165 // NSLog(@"IDs: %@", [socialGraphInfo valueForKey:@"ids"]);
166 // NSLog(@"previous_cursor: %@", [socialGraphInfo valueForKey:@"previous_cursor"]);
167 // NSLog(@"next_cursor: %@", [socialGraphInfo valueForKey:@"next_cursor"]);
168 // NSLog(@"source_api_request_type: %@", [socialGraphInfo valueForKey:@"source_api_request_type"]);
169 }
170
171
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
172 - (void)imageReceived:(NSImage *)image forRequest:(NSString *)connectionIdentifier
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
173 {
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
174 NSLog(@"Got an image for %@: %@", connectionIdentifier, image);
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
175
176 // Save image to the Desktop.
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
177 NSString *path = [[NSString stringWithFormat:@"~/Desktop/%@.tiff", connectionIdentifier] stringByExpandingTildeInPath];
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
178 [[image TIFFRepresentation] writeToFile:path atomically:NO];
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
179 }
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the…
Craig Hockenberry authored
180
c8ba147 Removed -getFollowedTimelineFor:* methods since they are no longer su…
Craig Hockenberry authored
181 - (void)connectionFinished:(NSString *)connectionIdentifier
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
182 {
c8ba147 Removed -getFollowedTimelineFor:* methods since they are no longer su…
Craig Hockenberry authored
183 NSLog(@"Connection finished %@", connectionIdentifier);
184
1f94767 Added new delegate method that is called whenever a connection is fin…
Craig Hockenberry authored
185 if ([twitterEngine numberOfConnections] == 0)
5f8fb9c Code and documentation cleanup. Added many more tests/examples to the…
Craig Hockenberry authored
186 {
187 [NSApp terminate:self];
188 }
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
189 }
190
fd65d2c Added delegate callback for each parsed object.
Craig Hockenberry authored
191 #if YAJL_AVAILABLE
192
193 - (void)receivedObject:(NSDictionary *)dictionary forRequest:(NSString *)connectionIdentifier
194 {
195 NSLog(@"Got an object for %@: %@", connectionIdentifier, dictionary);
196 }
197
198 #endif
199
96b2053 @mattgemmell MGTwitterEngine re-import.
authored
200 @end
Something went wrong with that request. Please try again.