Skip to content

Commit

Permalink
Foursquare work in progress. Grabbing the token works, now need to bu…
Browse files Browse the repository at this point in the history
…ild the UI.
  • Loading branch information
jaanus committed Dec 2, 2011
1 parent e478a43 commit af7e2ca
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 47 deletions.
13 changes: 0 additions & 13 deletions OAuth/Guts/OAuth4sq.h

This file was deleted.

13 changes: 0 additions & 13 deletions OAuth/Guts/OAuth4sq.m

This file was deleted.

2 changes: 1 addition & 1 deletion OAuth/User Interface/FoursquareLoginPopup.h
Expand Up @@ -11,7 +11,7 @@

@class OAuth;

@interface FoursquareLoginPopup : UIViewController {
@interface FoursquareLoginPopup : UIViewController <UIWebViewDelegate> {
UIWebView *webView;
}

Expand Down
41 changes: 40 additions & 1 deletion OAuth/User Interface/FoursquareLoginPopup.m
Expand Up @@ -8,6 +8,7 @@

#import "FoursquareLoginPopup.h"
#import "OAuthConsumerCredentials.h"
#import "OAuth.h"

@implementation FoursquareLoginPopup

Expand Down Expand Up @@ -63,9 +64,10 @@ - (void)viewDidLoad
CGRect appFrame = [UIScreen mainScreen].applicationFrame;
webView = [[[UIWebView alloc] initWithFrame:CGRectMake(0,0,appFrame.size.width,appFrame.size.height)] autorelease];
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
webView.delegate = self;
[self.view addSubview:webView];

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://foursquare.com/oauth2/authenticate?client_id=%@&response_type=code&redirect_uri=%@", OAUTH_FOURSQUARE_CONSUMER_KEY, @"oob"]]]];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://foursquare.com/oauth2/authenticate?client_id=%@&response_type=token&redirect_uri=%@", OAUTH_FOURSQUARE_CONSUMER_KEY, @"plainoauth://handleFoursquareLogin"]]]];

}

Expand All @@ -90,4 +92,41 @@ - (void)cancel {
[self.delegate oAuthLoginPopupDidCancel:self];
}

#pragma mark -
#pragma mark UIWebViewDelegate

- (BOOL)webView:(UIWebView *)webview shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(@"webview should load request: %@", request);

NSString *URLString = [[request URL] absoluteString];

if ([URLString rangeOfString:@"access_token="].location != NSNotFound) {


NSString *accessToken = [[URLString componentsSeparatedByString:@"="] lastObject];

NSLog(@"yowza, got token: %@ from url %@", accessToken, URLString);

oAuth.oauth_token = accessToken;
oAuth.oauth_token_authorized = YES;
[oAuth save];
[self.delegate oAuthLoginPopupDidAuthorize:self];
}


return YES;
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
NSLog(@"did start load");
}

- (void)webViewDidFinishLoad:(UIWebView *)webview {
NSLog(@"did finish load url: %@", webview.request.URL);
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
NSLog(@"did fail with error: %@", error);
}

@end
10 changes: 2 additions & 8 deletions PlainOAuth.xcodeproj/project.pbxproj
Expand Up @@ -53,7 +53,6 @@
EA85B123140ADCDA00F687B1 /* NSString+URLEncoding.m in Sources */ = {isa = PBXBuildFile; fileRef = EA0EB06A11D472A8006E5BEE /* NSString+URLEncoding.m */; };
EA8C57B01483552900E96D9F /* Master.m in Sources */ = {isa = PBXBuildFile; fileRef = EA8C57AE1483552900E96D9F /* Master.m */; };
EA8C57B11483552900E96D9F /* Master.xib in Resources */ = {isa = PBXBuildFile; fileRef = EA8C57AF1483552900E96D9F /* Master.xib */; };
EA8C57B9148360C000E96D9F /* OAuth4sq.m in Sources */ = {isa = PBXBuildFile; fileRef = EA8C57B8148360C000E96D9F /* OAuth4sq.m */; };
EA8C57BC148368F100E96D9F /* FoursquareLoginPopup.m in Sources */ = {isa = PBXBuildFile; fileRef = EA8C57BB148368F100E96D9F /* FoursquareLoginPopup.m */; };
EA94F339140AD7DC00EFAF02 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA94F338140AD7DC00EFAF02 /* SenTestingKit.framework */; };
EA94F33A140AD7DC00EFAF02 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
Expand Down Expand Up @@ -96,7 +95,7 @@
EA0EB04011D472A8006E5BEE /* TwitterLoginPopup.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = TwitterLoginPopup.xib; sourceTree = "<group>"; };
EA0EB04111D472A8006E5BEE /* TwitterWebViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TwitterWebViewController.h; sourceTree = "<group>"; };
EA0EB04211D472A8006E5BEE /* TwitterWebViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TwitterWebViewController.m; sourceTree = "<group>"; };
EA0EB04411D472A8006E5BEE /* OAuthLoginPopupDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; path = OAuthLoginPopupDelegate.h; sourceTree = "<group>"; };
EA0EB04411D472A8006E5BEE /* OAuthLoginPopupDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OAuthLoginPopupDelegate.h; sourceTree = "<group>"; };
EA0EB04611D472A8006E5BEE /* OAuthTwitterCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OAuthTwitterCallbacks.h; sourceTree = "<group>"; };
EA0EB06011D472A8006E5BEE /* OAHMAC_SHA1SignatureProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OAHMAC_SHA1SignatureProvider.h; sourceTree = "<group>"; };
EA0EB06111D472A8006E5BEE /* OAHMAC_SHA1SignatureProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OAHMAC_SHA1SignatureProvider.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -136,8 +135,6 @@
EA8C57AD1483552900E96D9F /* Master.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Master.h; path = Shared/Master.h; sourceTree = "<group>"; };
EA8C57AE1483552900E96D9F /* Master.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Master.m; path = Shared/Master.m; sourceTree = "<group>"; };
EA8C57AF1483552900E96D9F /* Master.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = Master.xib; path = Shared/Master.xib; sourceTree = "<group>"; };
EA8C57B7148360C000E96D9F /* OAuth4sq.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OAuth4sq.h; sourceTree = "<group>"; };
EA8C57B8148360C000E96D9F /* OAuth4sq.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OAuth4sq.m; sourceTree = "<group>"; };
EA8C57BA148368F100E96D9F /* FoursquareLoginPopup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FoursquareLoginPopup.h; sourceTree = "<group>"; };
EA8C57BB148368F100E96D9F /* FoursquareLoginPopup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FoursquareLoginPopup.m; sourceTree = "<group>"; };
EA94F337140AD7DC00EFAF02 /* PlainOAuthUnitTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PlainOAuthUnitTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -153,7 +150,7 @@
EACBA7E814836BE500512B5A /* FoursquareController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FoursquareController.h; path = Shared/FoursquareController.h; sourceTree = "<group>"; };
EACBA7E914836BE500512B5A /* FoursquareController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FoursquareController.m; path = Shared/FoursquareController.m; sourceTree = "<group>"; };
EACBA7EA14836BE500512B5A /* FoursquareController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = FoursquareController.xib; path = Shared/FoursquareController.xib; sourceTree = "<group>"; };
EACBA7EE14836C7600512B5A /* TwitterLoginUiFeedback.h */ = {isa = PBXFileReference; fileEncoding = 4; path = TwitterLoginUiFeedback.h; sourceTree = "<group>"; };
EACBA7EE14836C7600512B5A /* TwitterLoginUiFeedback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TwitterLoginUiFeedback.h; sourceTree = "<group>"; };
EACE237911E047A20083EB38 /* UploadMedia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UploadMedia.h; path = Shared/UploadMedia.h; sourceTree = "<group>"; };
EACE237A11E047A20083EB38 /* UploadMedia.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UploadMedia.m; path = Shared/UploadMedia.m; sourceTree = "<group>"; };
EACE237B11E047A20083EB38 /* UploadMedia.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = UploadMedia.xib; path = Shared/UploadMedia.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -317,8 +314,6 @@
EA0EB06A11D472A8006E5BEE /* NSString+URLEncoding.m */,
EA0EB06B11D472A8006E5BEE /* OAuth.h */,
EA0EB06C11D472A8006E5BEE /* OAuth.m */,
EA8C57B7148360C000E96D9F /* OAuth4sq.h */,
EA8C57B8148360C000E96D9F /* OAuth4sq.m */,
EAA077051470C70C00B03C87 /* OAuthTwitter.h */,
EAA077061470C70C00B03C87 /* OAuthTwitter.m */,
);
Expand Down Expand Up @@ -556,7 +551,6 @@
EACE238511E048620083EB38 /* TwitterController.m in Sources */,
EAA077071470C70C00B03C87 /* OAuthTwitter.m in Sources */,
EA8C57B01483552900E96D9F /* Master.m in Sources */,
EA8C57B9148360C000E96D9F /* OAuth4sq.m in Sources */,
EA8C57BC148368F100E96D9F /* FoursquareLoginPopup.m in Sources */,
EACBA7EB14836BE500512B5A /* FoursquareController.m in Sources */,
);
Expand Down
4 changes: 2 additions & 2 deletions Shared/FourSquareController.h
Expand Up @@ -9,12 +9,12 @@
#import <UIKit/UIKit.h>
#import "OAuthLoginPopupDelegate.h"

@class OAuth4sq, FoursquareLoginPopup;
@class OAuth, FoursquareLoginPopup;

@interface FoursquareController : UIViewController <oAuthLoginPopupDelegate> {
FoursquareLoginPopup *loginPopup;
}

@property (retain, nonatomic) OAuth4sq *oAuth4sq;
@property (retain, nonatomic) OAuth *oAuth4sq;

@end
15 changes: 10 additions & 5 deletions Shared/FourSquareController.m
Expand Up @@ -7,7 +7,7 @@
//

#import "FoursquareController.h"
#import "OAuth4sq.h"
#import "OAuth.h"
#import "FoursquareLoginPopup.h"

@interface FoursquareController (PrivateMethods)
Expand Down Expand Up @@ -101,10 +101,15 @@ - (void)login {

// UIWebView *fourSquareLoginWebview = [[UIWebView alloc] init

if (!loginPopup) {
loginPopup = [[FoursquareLoginPopup alloc] init];
loginPopup.delegate = self;
if (loginPopup) {
[loginPopup release];
loginPopup = nil;
}

loginPopup = [[FoursquareLoginPopup alloc] init];
loginPopup.oAuth = oAuth4sq;
loginPopup.delegate = self;

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginPopup];
[self presentModalViewController:nav animated:YES];
[nav release];
Expand All @@ -130,7 +135,7 @@ - (void)oAuthLoginPopupDidCancel:(UIViewController *)popup {
- (void)oAuthLoginPopupDidAuthorize:(UIViewController *)popup {
[self dismissModalViewControllerAnimated:YES];
[loginPopup release]; loginPopup = nil;

NSLog(@"oh hai, got the token: %@", oAuth4sq.oauth_token);
}

@end
4 changes: 2 additions & 2 deletions Shared/Master.h
Expand Up @@ -8,11 +8,11 @@

#import <UIKit/UIKit.h>

@class OAuthTwitter, OAuth4sq, TwitterController, FoursquareController;
@class OAuthTwitter, OAuth, TwitterController, FoursquareController;

@interface Master : UIViewController <UINavigationControllerDelegate> {
OAuthTwitter *oAuthTwitter;
OAuth4sq *oAuth4sq;
OAuth *oAuth4sq;
TwitterController *twitterController;
FoursquareController *foursquareController;
}
Expand Down
4 changes: 2 additions & 2 deletions Shared/Master.m
Expand Up @@ -11,7 +11,7 @@
#import "OAuthConsumerCredentials.h"
#import "TwitterController.h"
#import "FoursquareController.h"
#import "OAuth4sq.h"
#import "OAuth.h"

@implementation Master
@synthesize twitterAuthStatus;
Expand All @@ -26,7 +26,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
oAuthTwitter = [[OAuthTwitter alloc] initWithConsumerKey:OAUTH_TWITTER_CONSUMER_KEY andConsumerSecret:OAUTH_TWITTER_CONSUMER_SECRET];
[oAuthTwitter load];

oAuth4sq = [[OAuth4sq alloc] initWithConsumerKey:OAUTH_FOURSQUARE_CONSUMER_KEY andConsumerSecret:OAUTH_FOURSQUARE_CONSUMER_SECRET];
oAuth4sq = [[OAuth alloc] initWithConsumerKey:OAUTH_FOURSQUARE_CONSUMER_KEY andConsumerSecret:OAUTH_FOURSQUARE_CONSUMER_SECRET];
oAuth4sq.save_prefix = @"PlainOAuth4sq";
[oAuth4sq load];

Expand Down

0 comments on commit af7e2ca

Please sign in to comment.