-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTwitterAction.m
62 lines (49 loc) · 1.87 KB
/
TwitterAction.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// TwitterAction.m
// Twitter
//
// Created by Joshua Holt on 12/23/09.
#import "TwitterAction.h"
#import "JSON.h"
#import "ASI.h"
#import <QSCore/QSTextProxy.h>
#import <QSCore/QSNotifyMediator.h>
void TwitterNotify(NSString *message)
{
QSShowNotifierWithAttributes(
[NSDictionary dictionaryWithObjectsAndKeys:@"Quick Silver Twitter",
QSNotifierTitle, message, QSNotifierText,
[QSResourceManager imageNamed:@"QSTwitter2"],QSNotifierIcon,nil]);
}
@implementation TwitterAction
- (QSObject *)performActionOnObject:(QSObject *)dObject{
NSString *userName = [[NSUserDefaults standardUserDefaults] valueForKey:@"QSTwitterUserName"];
NSString *password = [[NSUserDefaults standardUserDefaults] valueForKey:@"QSTwitterUserPassword"];
if (!userName && !password) {
TwitterNotify(@"Please Set up your account in the preference pane.");
}else{
// The Update message sent from Quicksilver's text input
NSString *updateMessage;
updateMessage = [NSString stringWithFormat:@"%@",[dObject stringValue]];
// The update URL
NSURL *updateURL = [NSURL URLWithString:
[NSString stringWithFormat:@"http://twitter.com/statuses/update.json"]];
// The update request
ASIFormDataRequest *updateRequest = [ASIFormDataRequest requestWithURL:updateURL];
[updateRequest setUsername:@"yourusername"];
[updateRequest setPassword:@"yourpassword"];
[updateRequest setPostValue:[NSString stringWithFormat:@"%@", [dObject stringValue]] forKey:@"status"];
[updateRequest start];
// The response error (if any)
NSError *responseError = [updateRequest error];
if (!responseError) {
// The response string
NSString *response = [updateRequest responseString];
TwitterNotify(response);
} else {
TwitterNotify([responseError localizedDescription]);
}
}
return nil;
}
@end