Permalink
Browse files

Added methods get user information, direct message and icon, default …

…images
  • Loading branch information...
1 parent d69ea52 commit d1af135bad05fd3eb8c57726797903f8ff0893ec @lucascorrea committed Mar 2, 2012
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -37,6 +37,10 @@
F99448EE14FFF99F0017A5D8 /* SA_OAuthTwitterController.m in Sources */ = {isa = PBXBuildFile; fileRef = F99448D914FFF99F0017A5D8 /* SA_OAuthTwitterController.m */; };
F99448EF14FFF99F0017A5D8 /* SA_OAuthTwitterEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = F99448DB14FFF99F0017A5D8 /* SA_OAuthTwitterEngine.m */; };
F99448F014FFF99F0017A5D8 /* twitter_load.png in Resources */ = {isa = PBXBuildFile; fileRef = F99448DC14FFF99F0017A5D8 /* twitter_load.png */; };
+ F99448F5150119510017A5D8 /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = F99448F4150119500017A5D8 /* icon.png */; };
+ F99448F71501195D0017A5D8 /* icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F99448F61501195B0017A5D8 /* icon@2x.png */; };
+ F9A4ACC9150142C500D73407 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F9A4ACC8150142C500D73407 /* Default@2x.png */; };
+ F9A4ACCC150142CC00D73407 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = F9A4ACCB150142CC00D73407 /* Default.png */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -111,6 +115,10 @@
F99448DA14FFF99F0017A5D8 /* SA_OAuthTwitterEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SA_OAuthTwitterEngine.h; sourceTree = "<group>"; };
F99448DB14FFF99F0017A5D8 /* SA_OAuthTwitterEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SA_OAuthTwitterEngine.m; sourceTree = "<group>"; };
F99448DC14FFF99F0017A5D8 /* twitter_load.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = twitter_load.png; sourceTree = "<group>"; };
+ F99448F4150119500017A5D8 /* icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon.png; sourceTree = "<group>"; };
+ F99448F61501195B0017A5D8 /* icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon@2x.png"; sourceTree = "<group>"; };
+ F9A4ACC8150142C500D73407 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = "<group>"; };
+ F9A4ACCB150142CC00D73407 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -132,6 +140,10 @@
F99446DE14FEF6370017A5D8 = {
isa = PBXGroup;
children = (
+ F9A4ACCB150142CC00D73407 /* Default.png */,
+ F9A4ACC8150142C500D73407 /* Default@2x.png */,
+ F99448F61501195B0017A5D8 /* icon@2x.png */,
+ F99448F4150119500017A5D8 /* icon.png */,
F99446F314FEF6370017A5D8 /* SCTwitter */,
F994471114FEFB840017A5D8 /* Other Sources */,
);
@@ -359,6 +371,10 @@
F99448DD14FFF99F0017A5D8 /* jQueryInject.txt in Resources */,
F99448DE14FFF99F0017A5D8 /* jQueryInjectLandscape.txt in Resources */,
F99448F014FFF99F0017A5D8 /* twitter_load.png in Resources */,
+ F99448F5150119510017A5D8 /* icon.png in Resources */,
+ F99448F71501195D0017A5D8 /* icon@2x.png in Resources */,
+ F9A4ACC9150142C500D73407 /* Default@2x.png in Resources */,
+ F9A4ACCC150142CC00D73407 /* Default.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -512,6 +528,7 @@
F994470914FEF6370017A5D8 /* Release */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
@@ -9,7 +9,25 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFiles</key>
- <array/>
+ <array>
+ <string>icon@2x copy.png</string>
+ <string>icon.png</string>
+ <string>icon@2x.png</string>
+ </array>
+ <key>CFBundleIcons</key>
+ <dict>
+ <key>CFBundlePrimaryIcon</key>
+ <dict>
+ <key>CFBundleIconFiles</key>
+ <array>
+ <string>icon@2x copy.png</string>
+ <string>icon.png</string>
+ <string>icon@2x.png</string>
+ </array>
+ <key>UIPrerenderedIcon</key>
+ <true/>
+ </dict>
+ </dict>
<key>CFBundleIdentifier</key>
<string>com.siriuscode.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
@@ -28,10 +46,14 @@
<true/>
<key>UIMainStoryboardFile</key>
<string>MainStoryboard</string>
+ <key>UIPrerenderedIcon</key>
+ <true/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
+ <key>UIStatusBarStyle</key>
+ <string>UIStatusBarStyleBlackOpaque</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
@@ -36,19 +36,27 @@
typedef void(^SCTwitterCallback)(BOOL success);
typedef void(^SCTwitterStatusCallback)(BOOL success, id result);
+typedef void(^SCTwitterUserCallback)(BOOL success, id result);
+typedef void(^SCTwitterDirectCallback)(BOOL success, id result);
+
@interface SCTwitter : NSObject <SA_OAuthTwitterEngineDelegate, SA_OAuthTwitterControllerDelegate>{
SA_OAuthTwitterEngine *_engine;
UIViewController *_viewController;
}
@property (nonatomic, copy) SCTwitterCallback loginCallback;
@property (nonatomic, copy) SCTwitterStatusCallback statusCallback;
+@property (nonatomic, copy) SCTwitterUserCallback userCallback;
+@property (nonatomic, copy) SCTwitterDirectCallback directCallback;
+ (SCTwitter *)shared;
+ (void)loginViewControler:(UIViewController *)aViewController callback:(void (^)(BOOL success))aCallback;
+ (void)logoutCallback:(void(^)(BOOL success))aCallback;
+ (void)postWithMessage:(NSString *)message callback:(void (^)(BOOL success, id result))aCallback;
+ (void)getPublicTimelineWithCallback:(void (^)(BOOL success, id result))aCallback;
+ (void)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sinceID startingAtPage:(int)page count:(int)count callback:(void (^)(BOOL success, id result))aCallback;
++ (void)getUserInformationCallback:(void (^)(BOOL success, id result))aCallback;
++ (void)getUserInformationFor:(NSString *)username callback:(void (^)(BOOL success, id result))aCallback;
++ (void)directMessage:(NSString *)message to:(NSString *)username callback:(void (^)(BOOL success, id result))aCallback;
@end
@@ -33,6 +33,8 @@ - (void)logoutCallback:(void (^)(BOOL success))aCallback;
- (void)postWithMessage:(NSString *)message callback:(void (^)(BOOL success, id result))aCallback;
- (void)getPublicTimelineWithCallback:(void (^)(BOOL success, id result))aCallback;
- (void)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sinceID startingAtPage:(int)page count:(int)count callback:(void (^)(BOOL success, id result))aCallback;
+- (void)getUserInformationFor:(NSString *)username callback:(void (^)(BOOL success, id result))aCallback;
+- (void)directMessage:(NSString *)message to:(NSString *)username callback:(void (^)(BOOL success, id result))aCallback;
- (BOOL)isSessionValid;
@end
@@ -43,7 +45,8 @@ @implementation SCTwitter
@synthesize loginCallback;
@synthesize statusCallback;
-
+@synthesize userCallback;
+@synthesize directCallback;
#pragma mark -
#pragma mark Singleton
@@ -109,6 +112,20 @@ + (void)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sinceID s
[[SCTwitter shared] getUserTimelineFor:username sinceID:sinceID startingAtPage:page count:count callback:aCallback];
}
++ (void)getUserInformationCallback:(void (^)(BOOL success, id result))aCallback
+{
+ [[SCTwitter shared] getUserInformationFor:nil callback:aCallback];
+}
+
++ (void)getUserInformationFor:(NSString *)username callback:(void (^)(BOOL success, id result))aCallback
+{
+ [[SCTwitter shared] getUserInformationFor:username callback:aCallback];
+}
+
++ (void)directMessage:(NSString *)message to:(NSString *)username callback:(void (^)(BOOL success, id result))aCallback
+{
+ [[SCTwitter shared] directMessage:message to:username callback:aCallback];
+}
#pragma mark -
@@ -198,7 +215,46 @@ - (void)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sinceID s
}
}
+- (void)getUserInformationFor:(NSString *)username callback:(void (^)(BOOL success, id result))aCallback
+{
+ if (![self isSessionValid]) {
+
+ // Call the login callback if we have one
+ if (aCallback) {
+ aCallback(NO, @"Error");
+ }
+
+ }else{
+
+ if (username == nil) {
+ username = _engine.username;
+ }
+
+ self.userCallback = aCallback;
+ [_engine getUserInformationFor:username];
+ }
+}
+- (void)directMessage:(NSString *)message to:(NSString *)username callback:(void (^)(BOOL success, id result))aCallback
+{
+ if (![self isSessionValid]) {
+
+ // Call the login callback if we have one
+ if (aCallback) {
+ aCallback(NO, @"Error");
+ }
+
+ }else{
+
+ if (username == nil) {
+ aCallback(NO, @"No username");
+ return;
+ }
+
+ self.directCallback = aCallback;
+ [_engine sendDirectMessage:message to:username];
+ }
+}
#pragma mark -
#pragma mark - SA_OAuthTwitterControllerDelegate methods
@@ -208,6 +264,7 @@ - (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authen
// Call the login callback
if (self.loginCallback) {
self.loginCallback(YES);
+ self.loginCallback = nil;
}
}
@@ -249,13 +306,38 @@ - (void)requestFailed:(NSString *)connectionIdentifier withError:(NSError *)erro
{
if (self.statusCallback) {
self.statusCallback(NO, error);
- }
+ self.statusCallback = nil;
+ }
+
+ if (self.userCallback) {
+ self.userCallback(NO, error);
+ self.userCallback = nil;
+ }
}
- (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier
{
if (self.statusCallback) {
self.statusCallback(YES, statuses);
+ self.statusCallback = nil;
+ }
+}
+
+
+- (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier
+{
+ if (self.userCallback) {
+ self.userCallback(YES, userInfo);
+ self.userCallback = nil;
+ }
+}
+
+
+- (void)directMessagesReceived:(NSArray *)messages forRequest:(NSString *)connectionIdentifier
+{
+ if (self.directCallback) {
+ self.directCallback(YES, messages);
+ self.directCallback = nil;
}
}
@@ -9,10 +9,15 @@
#import <UIKit/UIKit.h>
@interface SCTwitterViewController : UIViewController
+
+@property (retain, nonatomic) IBOutlet UITextField *messageText;
+
- (IBAction)loginButtonAction:(id)sender;
- (IBAction)logoutButtonAction:(id)sender;
- (IBAction)postBackgroundButtonAction:(id)sender;
- (IBAction)publicTimelineButtonAction:(id)sender;
- (IBAction)userTimelineButtonAction:(id)sender;
+- (IBAction)userInformationButtonAction:(id)sender;
+- (IBAction)directMessageButtonAction:(id)sender;
@end
@@ -10,6 +10,7 @@
#import "SCTwitter.h"
@implementation SCTwitterViewController
+@synthesize messageText;
- (void)didReceiveMemoryWarning
{
@@ -37,6 +38,7 @@ - (void)viewDidLoad
- (void)viewDidUnload
{
+ [self setMessageText:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
@@ -94,7 +96,7 @@ - (IBAction)postBackgroundButtonAction:(id)sender
{
loadingView.hidden = NO;
- [SCTwitter postWithMessage:@"Test in SCTwitter Framework #sctwitter #ios #iphone" callback:^(BOOL success, id result) {
+ [SCTwitter postWithMessage:messageText.text callback:^(BOOL success, id result) {
loadingView.hidden = YES;
NSLog(@"Message send - %i \n%@", success, result);
}];
@@ -126,4 +128,36 @@ - (IBAction)userTimelineButtonAction:(id)sender
}];
}
+- (IBAction)userInformationButtonAction:(id)sender
+{
+ loadingView.hidden = NO;
+
+ [SCTwitter getUserInformationCallback:^(BOOL success, id result) {
+ loadingView.hidden = YES;
+ if (success) {
+ //Return array NSDictonary
+ NSLog(@"%@", result);
+ }
+ }];
+}
+
+- (IBAction)directMessageButtonAction:(id)sender
+{
+ loadingView.hidden = NO;
+
+ [SCTwitter directMessage:messageText.text to:nil callback:^(BOOL success, id result) {
+
+ loadingView.hidden = YES;
+ if (success) {
+ //Return array NSDictonary
+ NSLog(@"%@", result);
+ }
+ }];
+}
+
+- (void)dealloc {
+ [messageText release];
+ [super dealloc];
+}
+
@end
Oops, something went wrong.

0 comments on commit d1af135

Please sign in to comment.