Skip to content

Commit

Permalink
ORSTwitterEngine: Updated and refactored some more (inc. API geolocat…
Browse files Browse the repository at this point in the history
…ion and retweet methods)
  • Loading branch information
nicktoumpelis committed Aug 21, 2009
1 parent 9b9cbec commit 2dd502e
Show file tree
Hide file tree
Showing 41 changed files with 11,427 additions and 9,913 deletions.
17,673 changes: 9,546 additions & 8,127 deletions Canary.xcodeproj/genesis.pbxuser

Large diffs are not rendered by default.

1,031 changes: 462 additions & 569 deletions Canary.xcodeproj/genesis.perspectivev3

Large diffs are not rendered by default.

50 changes: 28 additions & 22 deletions Canary.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Classes/Controller/ORSCanaryController+Growl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
- (NSString *) senderIdentifier:(NSXMLNode *)node;
- (NSString *) recipientIdentifier:(NSXMLNode *)node;
- (void) postStatusUpdatesReceived:(NSNotification *)note;
- (void) postRepliesReceived:(NSNotification *)note;
- (void) postMentionsReceived:(NSNotification *)note;
- (void) postDMsReceived:(NSNotification *)note;
- (void) postDMsReceived:(NSNotification *)note
afterID:(NSString *)messageID;
Expand Down
24 changes: 12 additions & 12 deletions Classes/Controller/ORSCanaryController+Growl.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,34 +90,34 @@ - (void) postStatusUpdatesReceived:(NSNotification *)note {
}
}

// Posts notifications that replies have been received
- (void) postRepliesReceived:(NSNotification *)note {
NSMutableArray *newReplies = [[NSMutableArray alloc] init];
// Posts notifications that mentions have been received
- (void) postMentionsReceived:(NSNotification *)note {
NSMutableArray *newMentions = [[NSMutableArray alloc] init];
for (NSXMLNode *node in (NSArray *)note.object) {
if ([node.ID substringFromIndex:3].intValue >
[[preferences statusIDSinceLastExecution] substringFromIndex:3].intValue) {
[newReplies addObject:node];
[newMentions addObject:node];
}
}
if (newReplies.count > 10) {
[GrowlApplicationBridge notifyWithTitle:@"Replies Received"
description:[NSString stringWithFormat:@"%i replies received",
if (newMentions.count > 10) {
[GrowlApplicationBridge notifyWithTitle:@"Mentions Received"
description:[NSString stringWithFormat:@"%i mentions received",
((NSArray *)note.object).count]
notificationName:@"Replies Received"
notificationName:@"Mentions Received"
iconData:nil
priority:1
isSticky:NO
clickContext:@""];
} else {
for (NSXMLNode *node in newReplies) {
for (NSXMLNode *node in newMentions) {
NSMutableDictionary *contextDict = [NSMutableDictionary new];
[contextDict setObject:@"Replies" forKey:@"Timeline"];
[contextDict setObject:@"Mentions" forKey:@"Timeline"];
[contextDict setObject:node.ID forKey:@"ID"];
NSData *iconData = [[NSData alloc] initWithContentsOfURL:[NSURL
URLWithString:node.userProfileImageURL]];
[GrowlApplicationBridge notifyWithTitle:[self userIdentifier:node]
description:[NSString replaceHTMLEntities:node.text]
notificationName:@"Replies Received"
notificationName:@"Mentions Received"
iconData:iconData
priority:1
isSticky:NO
Expand Down Expand Up @@ -288,7 +288,7 @@ - (void) growlNotificationWasClicked:(id)clickContext {
NSString *timeline = [contextDict objectForKey:@"Timeline"];
if (![statusID isEqualToString:@""]) {
if ([timeline isEqualToString:@"Friends"] ||
[timeline isEqualToString:@"Replies"]) {
[timeline isEqualToString:@"Mentions"]) {
for (NSXMLNode *node in [statusArrayController arrangedObjects]) {
if ([node.ID isEqualToString:statusID]) {
[statusArrayController setSelectedObjects:[NSArray
Expand Down
5 changes: 3 additions & 2 deletions Classes/Controller/ORSCanaryController.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#import "ORSTwitterEngine+Favorite.h"
#import "ORSTwitterEngine+Account.h"
#import "ORSTwitterEngine+Friendship.h"
#import "ORSTwitterEngine+Timeline.h"

@interface ORSCanaryController : NSWindowController < GrowlApplicationBridgeDelegate > {
// Fundamentals
Expand Down Expand Up @@ -164,7 +165,7 @@
- (IBAction) retypePreviousUpdate:sender;
- (IBAction) changeSegmentedControlTimeline:sender;
- (IBAction) friendsTimelineMenuItemClicked:sender;
- (IBAction) repliesTimelineMenuItemClicked:sender;
- (IBAction) mentionsTimelineMenuItemClicked:sender;
- (IBAction) messagesTimelineMenuItemClicked:sender;
- (IBAction) favoritesTimelineMenuItemClicked:sender;
- (void) scrollToTop;
Expand All @@ -180,7 +181,7 @@
- (void) getFriendsTimeline;
- (void) getUserTimeline;
- (void) getPublicTimeline;
- (void) getReplies;
- (void) getMentions;
- (void) getFavorites;
- (void) getReceivedMessages;
- (void) getSentMessages;
Expand Down
67 changes: 40 additions & 27 deletions Classes/Controller/ORSCanaryController.m
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,11 @@ - (IBAction) changeSegmentedControlTimeline:sender {
[self getFriendsTimeline];
[self.window setTitle:@"Canary: Friends"];
} else if (timelineControl.selectedSegment == 1) {
if ([cacheManager.repliesStatusCache count] > 0) {
self.statuses = cacheManager.repliesStatusCache;
if ([cacheManager.mentionsStatusCache count] > 0) {
self.statuses = cacheManager.mentionsStatusCache;
}
[self getReplies];
[self.window setTitle:@"Canary: Replies"];
[self getMentions];
[self.window setTitle:@"Canary: Mentions"];
} else if (timelineControl.selectedSegment == 2) {
if ([[cacheManager receivedMessagesCache] count] > 0) {
self.receivedDirectMessages = cacheManager.receivedMessagesCache;
Expand All @@ -395,7 +395,7 @@ - (IBAction) friendsTimelineMenuItemClicked:sender {
[self changeSegmentedControlTimeline:timelineSegControl];
}

- (IBAction) repliesTimelineMenuItemClicked:sender {
- (IBAction) mentionsTimelineMenuItemClicked:sender {
[timelineSegControl setSelectedSegment:1];
[self changeSegmentedControlTimeline:timelineSegControl];
}
Expand Down Expand Up @@ -438,7 +438,7 @@ - (void) updateTimer {
repeats:YES];
} else if (timelineSegControl.selectedSegment == 1) {
refreshTimer = [NSTimer scheduledTimerWithTimeInterval:refreshPeriod
target:self selector:@selector(getReplies) userInfo:nil
target:self selector:@selector(getMentions) userInfo:nil
repeats:YES];
} else if (timelineSegControl.selectedSegment == 3) {
refreshTimer = [NSTimer scheduledTimerWithTimeInterval:refreshPeriod
Expand Down Expand Up @@ -518,7 +518,7 @@ - (void) setStatusesAsynchronously:(NSNotification *)note {
firstFollowingTimelineRun = NO;
} else if (timelineSegControl.selectedSegment == 1) {
self.statuses = [cacheManager
setStatusesForTimelineCache:ORSRepliesTimelineCacheType
setStatusesForTimelineCache:ORSMentionsTimelineCacheType
withNotification:note];
[mainTimelineCollectionView unbind:@"content"];
[mainTimelineCollectionView unbind:@"selectionIndexes"];
Expand All @@ -532,7 +532,7 @@ - (void) setStatusesAsynchronously:(NSNotification *)note {
withKeyPath:@"selectionIndexes"
options:nil];
[mainTimelineCollectionView setItemPrototype:statusTimelineCollectionViewItem];
[self performSelectorInBackground:@selector(postRepliesReceived:)
[self performSelectorInBackground:@selector(postMentionsReceived:)
withObject:note];
} else if (timelineSegControl.selectedSegment == 3) {
self.statuses = [cacheManager
Expand Down Expand Up @@ -709,10 +709,10 @@ - (void) getFriendsTimeline {
if (twitterEngine.sessionUserID) {
[self showAnimatedStatusBarMessage:@"Downloading from Twitter..."];
if (cacheManager.firstFollowingCall) {
[twitterEngine getFriendsTimeline];
[twitterEngine friendsTimeline];
} else {
[twitterEngine
getFriendsTimelineSinceStatus:cacheManager.lastFollowingStatusID];
friendsTimelineSinceStatus:cacheManager.lastFollowingStatusID];
}
}
}
Expand All @@ -722,10 +722,10 @@ - (void) getUserTimeline {
if (twitterEngine.sessionUserID) {
[self showAnimatedStatusBarMessage:@"Downloading from Twitter..."];
if (cacheManager.firstArchiveCall) {
[twitterEngine getUserTimelineForUser:twitterEngine.sessionUserID];
[twitterEngine userTimelineForUserWithID:twitterEngine.sessionUserID];
} else {
[twitterEngine
getUserTimelineSinceStatus:cacheManager.lastArchiveStatusID];
userTimelineSinceStatus:cacheManager.lastArchiveStatusID];
}
}
}
Expand All @@ -735,23 +735,23 @@ - (void) getPublicTimeline {
if (twitterEngine.sessionUserID) {
[self showAnimatedStatusBarMessage:@"Downloading from Twitter..."];
if (cacheManager.firstPublicCall) {
[twitterEngine getPublicTimeline];
[twitterEngine publicTimeline];
} else {
[twitterEngine
getPublicTimelineSinceStatus:cacheManager.lastPublicStatusID];
publicTimelineSinceStatus:cacheManager.lastPublicStatusID];
}
}
}

// Gets the replies
- (void) getReplies {
// Gets the mentions
- (void) getMentions {
if (twitterEngine.sessionUserID) {
[self showAnimatedStatusBarMessage:@"Downloading from Twitter..."];
if (cacheManager.firstRepliesCall) {
[twitterEngine getReplies];
if (cacheManager.firstMentionsCall) {
[twitterEngine mentions];
} else {
[twitterEngine
getRepliesSinceStatus:cacheManager.lastReplyStatusID];
mentionsSinceStatus:cacheManager.lastMentionStatusID];
}
}
}
Expand All @@ -764,7 +764,7 @@ - (void) getFavorites {
[twitterEngine favoritesForUser:twitterEngine.sessionUserID];
} else {
[twitterEngine
favoritesSinceStatusWithID:cacheManager.lastFavoriteStatusID];
favoritesSinceStatus:cacheManager.lastFavoriteStatusID];
}
}
}
Expand All @@ -774,10 +774,10 @@ - (void) getReceivedMessages {
if (twitterEngine.sessionUserID) {
[self showAnimatedStatusBarMessage:@"Downloading from Twitter..."];
if (cacheManager.firstReceivedMessagesCall) {
[twitterEngine getReceivedDMs];
[twitterEngine receivedDMs];
} else {
[twitterEngine
getReceivedDMsSinceDM:cacheManager.lastReceivedMessageID];
receivedDMsSinceDMWithID:cacheManager.lastReceivedMessageID];
}
}
}
Expand All @@ -787,9 +787,9 @@ - (void) getSentMessages {
if (twitterEngine.sessionUserID) {
[self showAnimatedStatusBarMessage:@"Downloading from Twitter..."];
if (cacheManager.firstSentMessagesCall) {
[twitterEngine getSentDMs];
[twitterEngine sentDMs];
} else {
[twitterEngine getSentDMsSinceDM:cacheManager.lastSentMessageID];
[twitterEngine sentDMsSinceDMWithID:cacheManager.lastSentMessageID];
}
}
}
Expand Down Expand Up @@ -866,6 +866,18 @@ - (void) retweetStatus:(NSString *)statusText
[self insertStringTokenInNewStatusTextField:message];
}

- (void) retweetStatus:(NSString *)identifier {
if (twitterEngine.sessionUserID) {
[twitterEngine retweetStatus:identifier];
[self showStatusBarMessage:@"Retweet sent"
withImageNamed:@"comments"];
messageDurationTimer = [NSTimer
scheduledTimerWithTimeInterval:60
target:self selector:@selector(hideStatusBar)
userInfo:nil repeats:NO];
}
}

// Updates the new status text field and other related components when the
// user types or selects stuff in the text field
- (void) updateNewStatusTextField {
Expand Down Expand Up @@ -1450,6 +1462,7 @@ - (IBAction) invokeActionOnUser:sender {
} else if ([[sender titleOfSelectedItem] isEqualToString:@"Retweet this"]) {
[self retweetStatus:[(NSXMLNode *)[sender toolTip] text]
fromUserWithID:userScreenName];
//[self retweetStatus:[(NSXMLNode *)[sender toolTip] ID]];
}
}

Expand Down Expand Up @@ -2132,7 +2145,7 @@ - (void) speechRecognizer:(NSSpeechRecognizer *)sender
// Add user with given ID from friends list (following)
- (void) createFriendshipWithUser:(NSString *)userID {
if (twitterEngine.sessionUserID) {
[twitterEngine makeFriendUserWithID:userID];
[twitterEngine befriendUserWithID:userID];
NSString *msg = [NSString stringWithFormat:@"Following %@",
userID];
[self showStatusBarMessage:msg
Expand All @@ -2147,7 +2160,7 @@ - (void) createFriendshipWithUser:(NSString *)userID {
// Remove user with given ID from friends list (following)
- (void) destroyFriendshipWithUser:(NSString *)userID {
if (twitterEngine.sessionUserID) {
[twitterEngine destroyFriendshipWithUser:userID];
[twitterEngine unfriendUserWithID:userID];
NSString *msg = [NSString stringWithFormat:@"No longer following %@",
userID];
[self showStatusBarMessage:msg
Expand Down Expand Up @@ -2197,7 +2210,7 @@ - (void) unblockUserWithID:(NSString *)userID {
// Favorite the selected status
- (void) favoriteStatusWithID:(NSString *)statusID {
if (twitterEngine.sessionUserID) {
[twitterEngine blindFavoriteStatusWithID:statusID];
[twitterEngine blindFavoriteStatus:statusID];
[self showStatusBarMessage:@"A new favorite has been added"
withImageNamed:@"fave_star"];
messageDurationTimer = [NSTimer
Expand Down
2 changes: 1 addition & 1 deletion Classes/Model/Twitter Engine/NSColor+Hexadecimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

@interface NSColor ( NSColorHexadecimalValue )

- (NSString *) hexadecimalValueOfAnNSColor;
- (NSString *) hexadecimalValue;

@end
2 changes: 1 addition & 1 deletion Classes/Model/Twitter Engine/NSColor+Hexadecimal.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@implementation NSColor ( NSColorHexadecimalValue )

- (NSString *) hexadecimalValueOfAnNSColor {
- (NSString *) hexadecimalValue {
float redFloatValue, greenFloatValue, blueFloatValue;
NSInteger redIntValue, greenIntValue, blueIntValue;
NSString *redHexValue, *greenHexValue, *blueHexValue;
Expand Down
10 changes: 5 additions & 5 deletions Classes/Model/Twitter Engine/ORSSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@
- (NSData *) uploadImageFile:(NSString *)filename
toTwitterPath:(NSString *)path
synchronously:(BOOL)synchr;
- (NSXMLDocument *) getXMLDocumentFromData:(NSData *)data;
- (NSXMLNode *) getNodeFromData:(NSData *)userData;
- (NSArray *) getAllStatusesFromData:(NSData *)statuses;
- (NSXMLDocument *) xmlDocumentFromData:(NSData *)data;
- (NSXMLNode *) nodeFromData:(NSData *)userData;
- (NSArray *) statusesFromData:(NSData *)statuses;
- (NSArray *) usersFromData:(NSData *)data;
- (NSArray *) savedSearchesFromData:(NSData *)data;
- (NSArray *) IDsFromData:(NSData *)data;
- (NSArray *) getAllDMsFromData:(NSData *)directMessages;
- (NSArray *) idsFromData:(NSData *)data;
- (NSArray *) dmsFromData:(NSData *)directMessages;

// NSURLConnection delegates for asynchronous connections
- (void) connection:(NSURLConnection *)connection
Expand Down
Loading

0 comments on commit 2dd502e

Please sign in to comment.