Skip to content
Permalink
Browse files

Release 0.9.3

commit 3ba6d0b4102d79bd029b32411fc6c5af672fb4ef
Author: Joe Keenan <joe@flyingdiver.com>
Date:   Mon Sep 2 22:57:53 2013 -0400

    Twitter Direct Message Commands

    Working as intended.  Might need tweaks based on user feedback.
    Fixed error message for unknown DM command
    Removed to-do list from project

commit 16f608b5fd4d10641e99da9208782fd9e139ca6b
Author: Joe Keenan <joe@flyingdiver.com>
Date:   Mon Sep 2 22:01:40 2013 -0400

    0.9.3 Fixes

    Renamed userdefaults for SMTP config
    Fixed SUFeedURL to point to the right server
    Fixed FeedBackURL to point to the right server
  • Loading branch information...
FlyingDiver committed Sep 4, 2013
1 parent 872a359 commit 609961ff80e512e7768e5dd1bc23e39e31bf0283
Showing with 41 additions and 79 deletions.
  1. +14 −53 MiniTwitter.m
  2. +2 −2 PreferencesController.m
  3. +4 −4 StokerX-Info.plist
  4. +0 −2 StokerX.xcodeproj/project.pbxproj
  5. +21 −8 StokerXAppDelegate.m
  6. +0 −10 To-Do.rtf
@@ -48,7 +48,7 @@ - (void) awakeFromNib

// Twitter has a limit of 15 DM queries per 15 minutes (avg 60 sec), so do them slower than that

[NSTimer scheduledTimerWithTimeInterval: 90 target:self selector:@selector(getDirectMessages:) userInfo: nil repeats:YES];
[NSTimer scheduledTimerWithTimeInterval: 75 target:self selector:@selector(getDirectMessages:) userInfo: nil repeats:YES];
}

[self updateUI];
@@ -324,15 +324,21 @@ - (void) getDirectMessages:(NSTimer *) theTimer
[[NSUserDefaults standardUserDefaults] setObject: self.directMessageSinceId forKey: @"DirectMessageSinceId"];

NSNumber *senderID = [[results objectAtIndex: msgNum] objectForKey: @"sender_id"];
NSNumber *senderName = [[results objectAtIndex: msgNum] objectForKey: @"sender_screen_name"];
NSString *message = [[results objectAtIndex: msgNum] objectForKey: @"text"];

// Get a list of my friends (the users I'm following)
// Process message, and acknowledge it to sender
[[NSNotificationCenter defaultCenter] postNotificationName: MiniTwitter_DirectMessage object: message];

NSString *query = [[NSString stringWithFormat: @"https://api.twitter.com/1.1/friends/ids.json?screen_name=%@", self.twitterHandle]
stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: query]];
NSString *replyMessage = [NSString stringWithFormat: @"Message received: \"%@\".", message];
NSString *encodedText = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef) replyMessage, NULL,(CFStringRef) @"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8);
NSString *body = [NSString stringWithFormat: @"text=%@&user_id=%@", encodedText, senderID];

NSString *query = [@"https://api.twitter.com/1.1/direct_messages/new.json" stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:query]];

[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: [body dataUsingEncoding:NSUTF8StringEncoding]];
[myAuth authorizeRequest: request];

GTMHTTPFetcher* myFetcher = [GTMHTTPFetcher fetcherWithRequest:request];
@@ -342,48 +348,9 @@ - (void) getDirectMessages:(NSTimer *) theTimer
{
[self reportError: error fromQuery: query];
}
else
{
NSDictionary *results = [[[[NSString alloc] initWithData: retrievedData encoding:NSUTF8StringEncoding] autorelease] JSONValue];

// check that sender is in the friends list
for (NSNumber *userID in [results objectForKey: @"ids"])
{
if ([userID isEqualTo: senderID])
{
// Process message, and acknowledge it to sender
[[NSNotificationCenter defaultCenter] postNotificationName: MiniTwitter_DirectMessage object: message];

NSString *replyMessage = [NSString stringWithFormat: @"Thank you %@ for your message \"%@\".\nI'll think about it.", senderName, message];
NSString *encodedText = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef) replyMessage, NULL,(CFStringRef) @"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8);
NSString *body = [NSString stringWithFormat: @"text=%@&user_id=%@", encodedText, senderID];

NSString *query = [@"https://api.twitter.com/1.1/direct_messages/new.json" stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:query]];

[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: [body dataUsingEncoding:NSUTF8StringEncoding]];
[myAuth authorizeRequest: request];

GTMHTTPFetcher* myFetcher = [GTMHTTPFetcher fetcherWithRequest:request];
[myFetcher beginFetchWithCompletionHandler:^(NSData *retrievedData, NSError *error)
{
if (error != nil)
{
[self reportError: error fromQuery: query];
}
}];

return;
}

}
// Only get here if user not found. This should not happen per Twitter Direct Message policy
NSLog(@"MiniTwitter getDirectMessages error got Direct Message from unknown user: %@ (%@)", senderName, senderID);

}
}];

return;
}
}
}];
@@ -394,12 +361,6 @@ - (void) reportError: (NSError *) error fromQuery: (NSString *) query
if ((error.code == self.lastError.code) && ([error.domain isEqualTo: self.lastError.domain]) && ([error.userInfo isEqualTo: self.lastError.userInfo]))
{
self.lastErrorCount++;

// if (self.lastErrorCount >= 10)
// {
// NSLog(@"MiniTwitter API error: last error repeated %d times", lastErrorCount);
// self.lastErrorCount = 0;
// }
}
else
{
@@ -20,8 +20,8 @@
NSString * const kEmailAddressKey = @"EmailAddress";
NSString * const kSMTPServerKey = @"SMTPServer";
NSString * const kSMTPPortKey = @"SMTPPort";
NSString * const kConnectionTypeKey = @"ConnectionType";
NSString * const kAuthTypeKey = @"AuthType";
NSString * const kConnectionTypeKey = @"SMTPConnectionType";
NSString * const kAuthTypeKey = @"SMTPAuthType";

NSString * const kStokerSMTPLogin = @"StokerX: SMTP";

@@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>CFBuildDate</key>
<string>Mon Sep 2 21:00:11 EDT 2013</string>
<string>Tue Sep 3 21:43:29 EDT 2013</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
@@ -34,11 +34,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.9.2</string>
<string>0.9.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>480</string>
<string>493</string>
<key>FRFeedbackReporter.addressbookEmail </key>
<string>YES</string>
<key>FRFeedbackReporter.sendDetailsIsOptional</key>
@@ -54,7 +54,7 @@
<key>NSPrincipalClass</key>
<string>FRExceptionReportingApplication</string>
<key>SUFeedURL</key>
<string>http://www.flyingdiver.com/${PRODUCT_NAME}/profileInfo.php</string>
<string>http://www.stokerx.com/${PRODUCT_NAME}/profileInfo.php</string>
<key>SUPublicDSAKeyFile</key>
<string>dsa_pub.pem</string>
<key>UTExportedTypeDeclarations</key>
@@ -169,7 +169,6 @@
C9B9BE8417CAAAC600B87DEB /* Growl.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Growl.framework; path = ../Frameworks/Growl.framework; sourceTree = "<group>"; };
C9BE1F1812E4C345007FAEC5 /* LVColorWellCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LVColorWellCell.h; path = Color/LVColorWellCell.h; sourceTree = "<group>"; };
C9BE1F1912E4C345007FAEC5 /* LVColorWellCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LVColorWellCell.m; path = Color/LVColorWellCell.m; sourceTree = "<group>"; };
C9C83DE41412B2C300AB8261 /* To-Do.rtf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.rtf; path = "To-Do.rtf"; sourceTree = "<group>"; };
C9CC35131402A33900A6227A /* CorePlot.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CorePlot.framework; path = ../Frameworks/CorePlot.framework; sourceTree = "<group>"; };
C9CC35171402A34C00A6227A /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sparkle.framework; path = ../Frameworks/Sparkle.framework; sourceTree = "<group>"; };
C9D5550A13FEDD4F0066BB27 /* ScriptingBridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ScriptingBridge.framework; path = System/Library/Frameworks/ScriptingBridge.framework; sourceTree = SDKROOT; };
@@ -301,7 +300,6 @@
080E96DDFE201D6D7F000001 /* Classes */,
29B97315FDCFA39411CA2CEA /* Other Sources */,
29B97317FDCFA39411CA2CEA /* Resources */,
C9C83DE41412B2C300AB8261 /* To-Do.rtf */,
29B97323FDCFA39411CA2CEA /* Frameworks */,
19C28FACFE9D520D11CA2CBB /* Products */,
);
@@ -12,10 +12,9 @@ @implementation StokerXAppDelegate

@synthesize mainWindow, mainView, notesWindow, notesView, startTime, endTime, graph, pushController, tweetController, preferencesController, loggingActive;

#define MINUTES 60.0
#define MINUTES 60.0
#define TIME_RANGE_START 20 * MINUTES
#define PLOT_INTERVAL_START 5 * MINUTES
#define GRAPH_UPDATE_INTERVAL 5.0

#pragma mark -
#pragma mark Application startup and Delegate Methods
@@ -258,20 +257,34 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
- (void) receiveTwitterDirectMessage: (NSNotification *) notification
{
NSMutableArray *tokenList = [self parseDirectMessage: [notification object]];
NSLog(@"StokerXAppDelegate receiveTwitterDirectMessage: %@", tokenList);

if ([[tokenList objectAtIndex: 0] caseInsensitiveCompare: @"status"] == NSOrderedSame)
{
[tweetController sendTweet: @"StokerX status:\n"];
NSMutableString *response = [NSMutableString stringWithString: @"StokerX status:"];
for (int i = 0; i < [theStoker numberOfSensors]; i++)
{
[response appendFormat: @"\n%@ = %@", [theStoker nameForSensor: i], [theStoker tempForSensor: i]];
}
[tweetController sendTweet: response];
}
else if ([[tokenList objectAtIndex: 0] caseInsensitiveCompare: @"set"] == NSOrderedSame)
{
[tweetController sendTweet: [NSString stringWithFormat: @"Set command received, sensor = \"%@\", temperature = %@",
[tokenList objectAtIndex: 1], [tokenList objectAtIndex: 2]]];
NSString *sensor = [NSString stringWithString: [tokenList objectAtIndex: 1]];
NSString *temp = [NSString stringWithString: [tokenList objectAtIndex: 2]];

[tweetController sendTweet: [NSString stringWithFormat: @"Temperature for sensor \"%@\" set to %@", sensor, temp]];
for (int i = 0; i < [theStoker numberOfSensors]; i++)
{
if ([sensor caseInsensitiveCompare: [theStoker nameForSensor: i]] == NSOrderedSame)
{
[theStoker setTarget: [NSNumber numberWithInt: [temp integerValue]] forSensorID: [theStoker idForSensor: i]];
break;
}
}
}
else
{
[tweetController sendTweet: [NSString stringWithFormat: @"Unknown Direct Message command received: %@", [notification object]]];
[tweetController sendTweet: [NSString stringWithFormat: @"Unknown Direct Message received: %@", [tokenList objectAtIndex: 0]]];
}
}

@@ -794,7 +807,7 @@ - (void)webView:(WebView *) printView didFinishLoadForFrame:(WebFrame *)frame

- (NSString *) targetUrlForFeedbackReport
{
return @"http://www.flyingdiver.com/submitfeedback.php";
return @"http://www.stokerx.com/submitfeedback.php";
}

#pragma mark -

This file was deleted.

Oops, something went wrong.

0 comments on commit 609961f

Please sign in to comment.
You can’t perform that action at this time.