Skip to content
Browse files

moving twitter to is own FTShareTwitter

  • Loading branch information...
1 parent f1c4bea commit 3053cf43a55941d5c683e6b9cbdd5fc48464eae9 @cescofry cescofry committed Dec 6, 2011
View
11 FTShareView.xcodeproj/project.pbxproj
@@ -90,6 +90,7 @@
689529D3144EE15400074F22 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 689529D2144EE15400074F22 /* SystemConfiguration.framework */; };
689529D6144EE1B100074F22 /* AnyViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 689529D5144EE1B100074F22 /* AnyViewController.m */; };
689529E7144EF3D600074F22 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 689529E6144EF3D600074F22 /* QuartzCore.framework */; };
+ A599D88D148E31BB00359F21 /* FTShareTwitter.m in Sources */ = {isa = PBXBuildFile; fileRef = A599D88C148E31BA00359F21 /* FTShareTwitter.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -278,6 +279,8 @@
689529D4144EE1B100074F22 /* AnyViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnyViewController.h; sourceTree = "<group>"; };
689529D5144EE1B100074F22 /* AnyViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnyViewController.m; sourceTree = "<group>"; };
689529E6144EF3D600074F22 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
+ A599D88B148E31BA00359F21 /* FTShareTwitter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FTShareTwitter.h; sourceTree = "<group>"; };
+ A599D88C148E31BA00359F21 /* FTShareTwitter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FTShareTwitter.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -318,7 +321,7 @@
children = (
689528F1144EE0C200074F22 /* ThirdParty */,
689527E9144ED91C00074F22 /* classes */,
- 689527B2144ED89A00074F22 /* FTShareView */,
+ 689527B2144ED89A00074F22 /* Controllers */,
689527CA144ED89A00074F22 /* FTShareViewTests */,
689527AB144ED89A00074F22 /* Frameworks */,
689527A9144ED89A00074F22 /* Products */,
@@ -353,7 +356,7 @@
name = Frameworks;
sourceTree = "<group>";
};
- 689527B2144ED89A00074F22 /* FTShareView */ = {
+ 689527B2144ED89A00074F22 /* Controllers */ = {
isa = PBXGroup;
children = (
689527BB144ED89A00074F22 /* FTAppDelegate.h */,
@@ -362,6 +365,7 @@
689529D5144EE1B100074F22 /* AnyViewController.m */,
689527B3144ED89A00074F22 /* Supporting Files */,
);
+ name = Controllers;
path = FTShareView;
sourceTree = "<group>";
};
@@ -403,6 +407,8 @@
689527EB144ED91C00074F22 /* FTShare.m */,
689527EC144ED91C00074F22 /* FTShareDataObjects.h */,
689527ED144ED91C00074F22 /* FTShareDataObjects.m */,
+ A599D88B148E31BA00359F21 /* FTShareTwitter.h */,
+ A599D88C148E31BA00359F21 /* FTShareTwitter.m */,
);
name = classes;
path = FTShareView/classes;
@@ -818,6 +824,7 @@
689529C7144EE0C200074F22 /* SA_OAuthTwitterController.m in Sources */,
689529C8144EE0C200074F22 /* SA_OAuthTwitterEngine.m in Sources */,
689529D6144EE1B100074F22 /* AnyViewController.m in Sources */,
+ A599D88D148E31BB00359F21 /* FTShareTwitter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
4 FTShareView/Config.h
@@ -11,8 +11,8 @@
#warning Enter twitter and Facebook keys!
-#define kIKTwitterConsumerKey @"yourTwitterConsumerKey"
-#define kIKTwiiterPasscode @"yourTwitterPasscode"
+#define kIKTwitterConsumerKey @"J3lGExzjOc3gi9fv5oMgA" //@"yourTwitterConsumerKey"
+#define kIKTwiiterPasscode @"wkOKutYnXXpNnHZJvOfIRMo1sXoGZDFwHgpGuk4tY" //@"yourTwitterPasscode"
#define kIKFacebookAppID @"yourFacebookAppID"
View
28 FTShareView/classes/FTShare.h
@@ -17,8 +17,8 @@
#import <MessageUI/MessageUI.h>
#import "FTShareDataObjects.h"
#import "FBConnect.h"
-#import "SA_OAuthTwitterEngine.h"
-#import "SA_OAuthTwitterController.h"
+
+#import "FTShareTwitter.h"
enum {
@@ -28,27 +28,25 @@ enum {
};
typedef NSUInteger FTShareOptions;
-@protocol FTShareTwitterDelegate;
@protocol FTShareFacebookDelegate;
@protocol FTShareMailDelegate;
-@interface FTShare : NSObject <MFMailComposeViewControllerDelegate, SA_OAuthTwitterControllerDelegate, SA_OAuthTwitterEngineDelegate, FBRequestDelegate, FBSessionDelegate, FBDialogDelegate, MFMailComposeViewControllerDelegate, UIActionSheetDelegate> {
+@interface FTShare : NSObject <MFMailComposeViewControllerDelegate, FBRequestDelegate, FBSessionDelegate, FBDialogDelegate, MFMailComposeViewControllerDelegate, UIActionSheetDelegate> {
+
+ FTShareTwitter *_twitter;
Facebook *_facebook;
- SA_OAuthTwitterEngine *_twitter;
- id <FTShareTwitterDelegate> _twitterDelegate;
id <FTShareFacebookDelegate> _facebookDelegate;
id <FTShareMailDelegate> _mailDelegate;
id _referencedController;
+
FTShareFacebookData *_facebookParams;
FTShareFacebookGetData *_facebookGetParams;
- FTShareTwitterData *_twitterParams;
+
}
@property (nonatomic, retain) Facebook *facebook;
-@property (nonatomic, retain) SA_OAuthTwitterEngine *twitter;
-@property (nonatomic, assign) id<FTShareTwitterDelegate> twitterDelegate;
@property (nonatomic, assign) id<FTShareFacebookDelegate> facebookDelegate;
@property (nonatomic, assign) id<FTShareMailDelegate> mailDelegate;
@@ -76,18 +74,6 @@ typedef NSUInteger FTShareOptions;
@end
-@protocol FTShareTwitterDelegate <NSObject>
-
-@optional
-
-- (FTShareTwitterData *)twitterData;
-- (void)twitterLoginDialogController:(UIViewController *)controller;
-- (void)twitterDidLogin:(NSError *)error;
-- (void)twitterDidPost:(NSError *)error;
-
-@end
-
-
@protocol FTShareFacebookDelegate <NSObject>
@optional
View
111 FTShareView/classes/FTShare.m
@@ -11,8 +11,6 @@
@implementation FTShare
@synthesize facebook = _facebook;
-@synthesize twitter = _twitter;
-@synthesize twitterDelegate = _twitterDelegate;
@synthesize facebookDelegate = _facebookDelegate;
@synthesize mailDelegate = _mailDelegate;
@@ -30,8 +28,8 @@ - (id)initWithReferencedController:(id)controller
if (self) {
// Initialization code here.
[self setReferencedController:controller];
+ _twitter = [[FTShareTwitter alloc] init];
_twitterParams = nil;
- _twitterDelegate = nil;
_facebookParams = nil;
_facebookGetParams = nil;
@@ -46,8 +44,6 @@ - (id)initWithReferencedController:(id)controller
- (void)dealloc {
[_facebook release], _facebook = nil;
- [_twitter release], _twitter = nil;
- _twitterDelegate = nil;
_facebookDelegate = nil;
_mailDelegate = nil;
_referencedController = nil;
@@ -97,108 +93,10 @@ - (void)showActionSheetWithtitle:(NSString *)title andOptions:(FTShareOptions)op
*
*/
-#pragma mark --
-#pragma mark Twitter
-
-// setting up twitter engine
- (void)setUpTwitterWithConsumerKey:(NSString *)consumerKey secret:(NSString *)secret andDelegate:(id<FTShareTwitterDelegate>)delegate {
- _twitter = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
- self.twitterDelegate = delegate;
- self.twitter.consumerKey = consumerKey;
- self.twitter.consumerSecret = secret;
- [self.twitter clearAccessToken];
- self.twitterParams = nil;
-}
-
-- (void)shareViaTwitter:(FTShareTwitterData *)data {
- self.twitterParams = data;
- if(![self.twitter isAuthorized]){
- UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:self.twitter delegate:self];
-
- if (controller && self.referencedController){
- [controller setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
- [(UIViewController *)self.referencedController presentModalViewController:controller animated:YES];
- }
- }
- else {
- if (![self.twitterParams isRequestValid]) return;
- [self.twitter sendUpdate:self.twitterParams.message];
- }
-}
-
-#pragma mark SA_OAuthTwitterEngineDelegate
-
-- (void) storeCachedTwitterOAuthData: (NSString *) data forUsername: (NSString *) username {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
-
- [defaults setObject: data forKey: @"twitterAuthData"];
- [defaults synchronize];
-}
-
-- (void)clearCachedTwitterOAuthData {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
-
- [defaults setObject: nil forKey: @"twitterAuthData"];
- [defaults synchronize];
-}
-
-- (NSString *) cachedTwitterOAuthDataForUsername: (NSString *) username {
- return [[NSUserDefaults standardUserDefaults] objectForKey: @"twitterAuthData"];
+ [_twitter setUpTwitterWithConsumerKey:consumerKey secret:secret referencedController:_referencedController andDelegate:delegate];
}
-#pragma mark TwitterEngineDelegate
-- (void) requestSucceeded: (NSString *) requestIdentifier {
- NSLog(@"Request %@ succeeded", requestIdentifier);
- if ([self.twitterDelegate respondsToSelector:@selector(twitterDidPost:)]) {
- [self.twitterDelegate twitterDidPost:nil];
- }
-
- self.twitter = nil;
- self.twitterDelegate = nil;
- self.twitterDelegate = nil;
-}
-
-- (void) requestFailed: (NSString *) requestIdentifier withError: (NSError *) error {
- NSLog(@"Request %@ failed with error: %@", requestIdentifier, error);
- if ([self.twitterDelegate respondsToSelector:@selector(twitterDidPost:)]) {
- [self.twitterDelegate twitterDidPost:error];
- }
-
- self.twitter = nil;
- self.twitterDelegate = nil;
- self.twitterDelegate = nil;
-}
-
-#pragma mark Twitter login
-
-- (void)OAuthTwitterController:(SA_OAuthTwitterController *)controller authenticatedWithUsername:(NSString *)username {
- if ([self.twitterDelegate respondsToSelector:@selector(twitterDidLogin:)]) {
- [self.twitterDelegate twitterDidLogin:nil];
- }
- [self shareViaTwitter:self.twitterParams];
-}
-
-- (void)OAuthTwitterControllerFailed:(SA_OAuthTwitterController *)controller {
- NSError *error = [NSError errorWithDomain:@"com.fuerteint.FTShare" code:400 userInfo:[NSDictionary dictionaryWithObject:@"Couldn't share with twitter" forKey:@"description"]];
- if ([self.twitterDelegate respondsToSelector:@selector(twitterDidLogin:)]) {
- [self.twitterDelegate twitterDidLogin:error];
- }
-
- self.twitter = nil;
- self.twitterDelegate = nil;
- self.twitterDelegate = nil;
-}
-
-- (void)OAuthTwitterControllerCanceled:(SA_OAuthTwitterController *)controller {
- NSError *error = [NSError errorWithDomain:@"com.fuerteint.FTShare" code:400 userInfo:[NSDictionary dictionaryWithObject:@"Twitter Controller Canceled" forKey:@"description"]];
- if ([self.twitterDelegate respondsToSelector:@selector(twitterDidLogin:)]) {
- [self.twitterDelegate twitterDidLogin:error];
- }
-
- self.twitter = nil;
- self.twitterDelegate = nil;
- self.twitterDelegate = nil;
-}
/**
*
@@ -423,10 +321,7 @@ - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger
}
else if ([btnText isEqualToString:@"Twitter"]) {
//implement Twitter
- if (self.twitterDelegate && [self.twitterDelegate respondsToSelector:@selector(twitterData)]) {
- FTShareTwitterData *data = [self.twitterDelegate twitterData];
- [self shareViaTwitter:data];
- }
+ [_twitter shareViaTwitter:nil];
}
}
View
10 FTShareView/classes/FTShareDataObjects.h
@@ -9,17 +9,7 @@
#import <Foundation/Foundation.h>
#import "UIImage+Resize.h"
-//Use http://developers.facebook.com/docs/reference/dialogs/feed/ to see how to use those parameters
-@interface FTShareTwitterData : NSObject {
- NSString *_message;
-}
-
-@property (nonatomic, retain) NSString *message;
-
-- (BOOL)isRequestValid;
-
-@end
@interface FTShareFacebookData : NSObject {
NSString *_message;
View
19 FTShareView/classes/FTShareDataObjects.m
@@ -10,25 +10,6 @@
#pragma mark Twitter Data Structure
-@implementation FTShareTwitterData
-
-@synthesize message = _message;
-
-- (BOOL)isRequestValid {
- BOOL valid = (self.message && [self.message length] > 0);
- if (!valid) NSLog(@"Twitter request seams not valid");
- return valid;
-}
-
-- (void)dealloc {
-
- [_message release], _message = nil;
- [super dealloc];
-}
-
-@end
-
-
#pragma mark Facebook Data Structure
@implementation FTShareFacebookData
View
50 FTShareView/classes/FTShareTwitter.h
@@ -0,0 +1,50 @@
+//
+// FTShareTwitter.h
+// FTShareView
+//
+// Created by cescofry on 06/12/2011.
+// Copyright (c) 2011 Fuerte International. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "SA_OAuthTwitterEngine.h"
+#import "SA_OAuthTwitterController.h"
+
+
+//Use http://developers.facebook.com/docs/reference/dialogs/feed/ to see how to use those parameters
+
+@interface FTShareTwitterData : NSObject {
+ NSString *_message;
+}
+
+@property (nonatomic, retain) NSString *message;
+
+- (BOOL)isRequestValid;
+
+@end
+
+
+@protocol FTShareTwitterDelegate;
+@interface FTShareTwitter : NSObject <SA_OAuthTwitterControllerDelegate, SA_OAuthTwitterEngineDelegate> {
+ SA_OAuthTwitterEngine *_twitter;
+ id <FTShareTwitterDelegate> _twitterDelegate;
+ FTShareTwitterData *_twitterParams;
+ id _referencedController;
+}
+
+@property (nonatomic, assign) id<FTShareTwitterDelegate> twitterDelegate;
+
+- (void)setUpTwitterWithConsumerKey:(NSString *)consumerKey secret:(NSString *)secret referencedController:(id)referencedController andDelegate:(id<FTShareTwitterDelegate>)delegate;
+- (void)shareViaTwitter:(FTShareTwitterData *)data;
+@end
+
+@protocol FTShareTwitterDelegate <NSObject>
+
+@optional
+
+- (FTShareTwitterData *)twitterData;
+- (void)twitterLoginDialogController:(UIViewController *)controller;
+- (void)twitterDidLogin:(NSError *)error;
+- (void)twitterDidPost:(NSError *)error;
+
+@end
View
160 FTShareView/classes/FTShareTwitter.m
@@ -0,0 +1,160 @@
+//
+// FTShareTwitter.m
+// FTShareView
+//
+// Created by cescofry on 06/12/2011.
+// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "FTShareTwitter.h"
+
+@implementation FTShareTwitterData
+
+@synthesize message = _message;
+
+- (BOOL)isRequestValid {
+ BOOL valid = (self.message && [self.message length] > 0);
+ if (!valid) NSLog(@"Twitter request seams not valid");
+ return valid;
+}
+
+- (void)dealloc {
+
+ [_message release], _message = nil;
+ [super dealloc];
+}
+
+@end
+
+
+
+
+@implementation FTShareTwitter
+
+@synthesize twitterDelegate = _twitterDelegate;
+
+- (id)init {
+ self = [super init];
+ if (self) {
+ _twitterDelegate = nil;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ _twitterDelegate = nil;
+ [super dealloc];
+}
+
+
+
+// setting up twitter engine
+- (void)setUpTwitterWithConsumerKey:(NSString *)consumerKey secret:(NSString *)secret referencedController:(id)referencedController andDelegate:(id<FTShareTwitterDelegate>)delegate {
+ _twitter = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
+ _referencedController = referencedController;
+ self.twitterDelegate = delegate;
+ _twitter.consumerKey = consumerKey;
+ _twitter.consumerSecret = secret;
+ [_twitter clearAccessToken];
+ _twitterParams = nil;
+}
+
+- (void)shareViaTwitter:(FTShareTwitterData *)data {
+ if (!data) {
+ if (self.twitterDelegate && [self.twitterDelegate respondsToSelector:@selector(twitterData)]) {
+ data = [self.twitterDelegate twitterData];
+ }
+ else {
+ [NSException raise:@"Twitter cannot post empy data" format:nil];
+ }
+ }
+ _twitterParams = data;
+ if(![_twitter isAuthorized]){
+ UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_twitter delegate:self];
+
+ if (controller && _referencedController){
+ [controller setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
+ [(UIViewController *)_referencedController presentModalViewController:controller animated:YES];
+ }
+ }
+ else {
+ if (![_twitterParams isRequestValid]) return;
+ [_twitter sendUpdate:_twitterParams.message];
+ }
+}
+
+#pragma mark SA_OAuthTwitterEngineDelegate
+
+- (void) storeCachedTwitterOAuthData: (NSString *) data forUsername: (NSString *) username {
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+
+ [defaults setObject: data forKey: @"twitterAuthData"];
+ [defaults synchronize];
+}
+
+- (void)clearCachedTwitterOAuthData {
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+
+ [defaults setObject: nil forKey: @"twitterAuthData"];
+ [defaults synchronize];
+}
+
+- (NSString *) cachedTwitterOAuthDataForUsername: (NSString *) username {
+ return [[NSUserDefaults standardUserDefaults] objectForKey: @"twitterAuthData"];
+}
+
+#pragma mark TwitterEngineDelegate
+- (void) requestSucceeded: (NSString *) requestIdentifier {
+ NSLog(@"Request %@ succeeded", requestIdentifier);
+ if ([self.twitterDelegate respondsToSelector:@selector(twitterDidPost:)]) {
+ [self.twitterDelegate twitterDidPost:nil];
+ }
+
+ _twitter = nil;
+ self.twitterDelegate = nil;
+ self.twitterDelegate = nil;
+}
+
+- (void) requestFailed: (NSString *) requestIdentifier withError: (NSError *) error {
+ NSLog(@"Request %@ failed with error: %@", requestIdentifier, error);
+ if ([self.twitterDelegate respondsToSelector:@selector(twitterDidPost:)]) {
+ [self.twitterDelegate twitterDidPost:error];
+ }
+
+ _twitter = nil;
+ self.twitterDelegate = nil;
+ self.twitterDelegate = nil;
+}
+
+#pragma mark Twitter login
+
+- (void)OAuthTwitterController:(SA_OAuthTwitterController *)controller authenticatedWithUsername:(NSString *)username {
+ if ([self.twitterDelegate respondsToSelector:@selector(twitterDidLogin:)]) {
+ [self.twitterDelegate twitterDidLogin:nil];
+ }
+ [self shareViaTwitter:_twitterParams];
+}
+
+- (void)OAuthTwitterControllerFailed:(SA_OAuthTwitterController *)controller {
+ NSError *error = [NSError errorWithDomain:@"com.fuerteint.FTShare" code:400 userInfo:[NSDictionary dictionaryWithObject:@"Couldn't share with twitter" forKey:@"description"]];
+ if ([self.twitterDelegate respondsToSelector:@selector(twitterDidLogin:)]) {
+ [self.twitterDelegate twitterDidLogin:error];
+ }
+
+ _twitter = nil;
+ self.twitterDelegate = nil;
+ self.twitterDelegate = nil;
+}
+
+- (void)OAuthTwitterControllerCanceled:(SA_OAuthTwitterController *)controller {
+ NSError *error = [NSError errorWithDomain:@"com.fuerteint.FTShare" code:400 userInfo:[NSDictionary dictionaryWithObject:@"Twitter Controller Canceled" forKey:@"description"]];
+ if ([self.twitterDelegate respondsToSelector:@selector(twitterDidLogin:)]) {
+ [self.twitterDelegate twitterDidLogin:error];
+ }
+
+ _twitter = nil;
+ self.twitterDelegate = nil;
+ self.twitterDelegate = nil;
+}
+
+@end

0 comments on commit 3053cf4

Please sign in to comment.
Something went wrong with that request. Please try again.