Skip to content

Commit

Permalink
Merged changed from oauth branch
Browse files Browse the repository at this point in the history
  • Loading branch information
stevestreza committed May 2, 2010
2 parents 5337498 + 5cd8eba commit dbf437d
Show file tree
Hide file tree
Showing 9 changed files with 558 additions and 72 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
*.pbxuser
*.perspectivev3
build
yajl
OAuthConsumer
7 changes: 7 additions & 0 deletions AppController.h
Expand Up @@ -9,8 +9,15 @@
#import <Cocoa/Cocoa.h>
#import "MGTwitterEngine.h"

@class OAToken;

@interface AppController : NSObject <MGTwitterEngineDelegate> {
MGTwitterEngine *twitterEngine;

OAToken *token;
}

// this gets called when the OAuth token is received
-(void)runTests;

@end
37 changes: 27 additions & 10 deletions AppController.m
Expand Up @@ -8,7 +8,6 @@

#import "AppController.h"


@implementation AppController


Expand All @@ -17,17 +16,27 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
// Put your Twitter username and password here:
NSString *username = nil;
NSString *password = nil;


NSString *consumerKey = nil;
NSString *consumerSecret = nil;

// Most API calls require a name and password to be set...
if (! username || ! password) {
NSLog(@"You forgot to specify your username/password in AppController.m, things might not work!");
if (! username || ! password || !consumerKey || !consumerSecret) {
NSLog(@"You forgot to specify your username/password/key/secret in AppController.m, things might not work!");
NSLog(@"And if things are mysteriously working without the username/password, it's because NSURLConnection is using a session cookie from another connection.");
}

// Create a TwitterEngine and set our login details.
twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self];
[twitterEngine setUsername:username password:password];

[twitterEngine setUsesSecureConnection:NO];
[twitterEngine setConsumerKey:consumerKey secret:consumerSecret];

[twitterEngine getXAuthAccessTokenForUsername:username password:password];
}

-(void)runTests{
[twitterEngine setAccessToken:token];

// Configure how the delegate methods are called to deliver results. See MGTwitterEngineDelegate.h for more info
//[twitterEngine setDeliveryOptions:MGTwitterEngineDeliveryIndividualResultsOption];

Expand All @@ -42,11 +51,11 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
#define TESTING_MESSAGE_ID 52182684

// Status methods:
// NSLog(@"getHomeTimelineFor: connectionIdentifier = %@", [twitterEngine getHomeTimelineSinceID:0 startingAtPage:0 count:20]);
//NSLog(@"getUserTimelineFor: connectionIdentifier = %@", [twitterEngine getUserTimelineFor:TESTING_SECONDARY_USER sinceID:0 startingAtPage:0 count:3]);
//NSLog(@"getUpdate: connectionIdentifier = %@", [twitterEngine getUpdate:TESTING_ID]);
NSLog(@"getHomeTimelineFor: connectionIdentifier = %@", [twitterEngine getHomeTimelineSinceID:0 startingAtPage:0 count:20]);
NSLog(@"getUserTimelineFor: connectionIdentifier = %@", [twitterEngine getUserTimelineFor:TESTING_SECONDARY_USER sinceID:0 startingAtPage:0 count:3]);
NSLog(@"getUpdate: connectionIdentifier = %@", [twitterEngine getUpdate:TESTING_ID]);
//NSLog(@"sendUpdate: connectionIdentifier = %@", [twitterEngine sendUpdate:[@"This is a test on " stringByAppendingString:[[NSDate date] description]]]);
//NSLog(@"getRepliesStartingAtPage: connectionIdentifier = %@", [twitterEngine getRepliesStartingAtPage:0]);
NSLog(@"getRepliesStartingAtPage: connectionIdentifier = %@", [twitterEngine getRepliesStartingAtPage:0]);
//NSLog(@"deleteUpdate: connectionIdentifier = %@", [twitterEngine deleteUpdate:TESTING_ID]);

// User methods:
Expand Down Expand Up @@ -186,6 +195,14 @@ - (void)connectionFinished:(NSString *)connectionIdentifier
}
}

- (void)accessTokenReceived:(OAToken *)aToken forRequest:(NSString *)connectionIdentifier
{
NSLog(@"Access token received! %@",aToken);

token = [aToken retain];
[self runTests];
}

#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE

- (void)receivedObject:(NSDictionary *)dictionary forRequest:(NSString *)connectionIdentifier
Expand Down
42 changes: 37 additions & 5 deletions MGTwitterEngine.h
Expand Up @@ -11,12 +11,12 @@
#import "MGTwitterEngineDelegate.h"
#import "MGTwitterParserDelegate.h"

#import "OAToken.h"


@interface MGTwitterEngine : NSObject <MGTwitterParserDelegate>
{
__weak NSObject <MGTwitterEngineDelegate> *_delegate;
NSString *_username;
NSString *_password;
NSMutableDictionary *_connections; // MGTwitterHTTPURLConnection objects
NSString *_clientName;
NSString *_clientVersion;
Expand All @@ -31,6 +31,15 @@
#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
MGTwitterEngineDeliveryOptions _deliveryOptions;
#endif

// OAuth
NSString *_consumerKey;
NSString *_consumerSecret;
OAToken *_accessToken;

// basic auth - deprecated
NSString *_username;
NSString *_password;
}

#pragma mark Class management
Expand All @@ -41,9 +50,6 @@

// Configuration and Accessors
+ (NSString *)version; // returns the version of MGTwitterEngine
- (NSString *)username;
- (NSString *)password;
- (void)setUsername:(NSString *)username password:(NSString *)password;
- (NSString *)clientName; // see README.txt for info on clientName/Version/URL/SourceToken
- (NSString *)clientVersion;
- (NSString *)clientURL;
Expand Down Expand Up @@ -220,3 +226,29 @@
#endif

@end

@interface MGTwitterEngine (BasicAuth)

- (NSString *)username DEPRECATED_ATTRIBUTE;
- (NSString *)password DEPRECATED_ATTRIBUTE;
- (void)setUsername:(NSString *)username password:(NSString *)password DEPRECATED_ATTRIBUTE;

@end

@interface MGTwitterEngine (OAuth)

- (void)setConsumerKey:(NSString *)key secret:(NSString *)secret;
- (NSString *)consumerKey;
- (NSString *)consumerSecret;

- (void)setAccessToken: (OAToken *)token;
- (OAToken *)accessToken;

// XAuth login - NOTE: You MUST email Twitter with your application's OAuth key/secret to
// get OAuth access. This will not work if you don't do this.
- (NSString *)getXAuthAccessTokenForUsername:(NSString *)username
password:(NSString *)password;

@end


0 comments on commit dbf437d

Please sign in to comment.