Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

a lesson learned in ARC auto-releasing

  • Loading branch information...
commit 6d4250fce443e4683c576e910c5549d64237e68a 1 parent 1d34c7e
@orta authored
View
16 Puttio/Networking/NetworkConstants.h
@@ -1,16 +0,0 @@
-//
-// NetworkConstants.h
-// Puttio
-//
-// Created by orta therox on 25/03/2012.
-// Copyright (c) 2012 ortatherox.com. All rights reserved.
-//
-
-extern NSString *const PTCallbackOriginal;
-extern NSString *const PTCallbackModified;
-
-extern NSString *const PTRootURL;
-extern NSString *const PTFormatOauthTokenURL;
-extern NSString *const PTFormatOauthLoginURL;
-extern NSString *const PTFormatOauthURL;
-extern NSString *const PTSettingsURL;
View
17 Puttio/Networking/NetworkConstants.m
@@ -1,17 +0,0 @@
-//
-// NetworkConstants.m
-// Puttio
-//
-// Created by orta therox on 25/03/2012.
-// Copyright (c) 2012 ortatherox.com. All rights reserved.
-//
-
-NSString *const PTCallbackOriginal = @"puttio://callback";
-NSString *const PTCallbackModified = @"puttio://callback/%3Fcode";
-
-NSString *const PTRootURL = @"https://put.io/";
-
-NSString *const PTFormatOauthTokenURL = @"https://api.put.io/v2/oauth2/access_token?client_id=%@&client_secret=%@&grant_type=%@&redirect_uri=%@&code=%@";
-NSString *const PTFormatOauthLoginURL = @"https://api.put.io/v2/oauth2/authenticate?client_id=%@&response_type=code&redirect_uri=%@";
-NSString *const PTFormatOauthURL = @"https://api.put.io/v2/oauth2/authenticate?client_id=%@&response_type=code&redirect_uri=%@";
-NSString *const PTSettingsURL = @"https://put.io/account/settings";
View
2  Puttio/Networking/OAuthViewController.h
@@ -21,7 +21,7 @@
@property (weak, nonatomic) IBOutlet UITextField *passwordTextfield;
@property (weak, nonatomic) IBOutlet UILabel *warningLabel;
@property (weak, nonatomic) IBOutlet UIView *loginViewWrapper;
-@property (weak, nonatomic) IBOutlet PutIOOAuthHelper *authHelper;
+@property (strong, nonatomic) IBOutlet PutIOOAuthHelper *authHelper;
- (IBAction)loginPressed:(id)sender;
View
23 Puttio/Networking/OAuthViewController.m
@@ -10,22 +10,6 @@
#import "OAuthViewController.h"
#import "PutIOOAuthHelper.h"
-// http://put.io/v2/docs/#authentication
-
-// The order of this is
-
-// Login in via website in webkit
-// Redirect to the OAuth dialog
-// Make a request to the OAuth authenticate URL ( getAccessTokenFromOauthCode )
-// Load Accounts page and parse out the tokens
-// Then call delegate method.
-
-@interface OAuthViewController ()
-- (void)loadAuthPage;
-- (void)loadAccountSettingsPage;
-- (void)getAccessTokenFromOauthCode:(NSString *)code;
-@end
-
@implementation OAuthViewController
@synthesize usernameTextfield, passwordTextfield;
@synthesize warningLabel;
@@ -65,14 +49,17 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
}
- (IBAction)loginPressed:(id)sender {
- #warning untested
[authHelper loginWithUsername:usernameTextfield.text andPassword:passwordTextfield.text];
}
-- (void)OAuthHelperDidLogin:(PutIOOAuthHelper *)helper {
+- (void)authHelperDidLogin:(PutIOOAuthHelper *)helper {
if([delegate respondsToSelector:@selector(authorizationDidFinishWithController:)]){
[delegate authorizationDidFinishWithController:self];
}
}
+- (void)authHelperLoginFailedWithDesription:(NSString *)errorDescription {
+ self.warningLabel.text = errorDescription;
+}
+
@end
View
4 Puttio/Networking/PutIOOAuthHelper.h
@@ -11,8 +11,8 @@
@class PutIOOAuthHelper;
@protocol PutIOOAuthHelperDelegate <NSObject>
-- (void)OAuthHelperDidLogin:(PutIOOAuthHelper *)helper;
-- (void)OAuthHelperLoginFailedWithDesription:(NSString *)errorDescription;
+- (void)authHelperDidLogin:(PutIOOAuthHelper *)helper;
+- (void)authHelperLoginFailedWithDesription:(NSString *)errorDescription;
@end
View
20 Puttio/Networking/PutIOOAuthHelper.m
@@ -11,13 +11,27 @@
#import "AFNetworking.h"
#import "PutIONetworkConstants.h"
+// http://put.io/v2/docs/#authentication
+
+// The order of this is
+
+// Login in via website in webkit
+// Redirect to the OAuth dialog
+// Make a request to the OAuth authenticate URL ( getAccessTokenFromOauthCode )
+// Load Accounts page and parse out the tokens
+// Then call delegate method.
+
@implementation PutIOOAuthHelper
@synthesize webView, delegate;
- (void)loginWithUsername:(NSString *)username andPassword:(NSString *)password {
+ webView.delegate = self;
+
[self loadAuthPage];
+ NSLog(@"%@ %s\n%@", NSStringFromSelector(_cmd), __FILE__, self);
+
NSString *setUsername = [NSString stringWithFormat:@"document.getElementsByTagName('input')[0].value = '%@'", username];
[webView stringByEvaluatingJavaScriptFromString:setUsername];
@@ -98,11 +112,11 @@ - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
if (error.code == 102) {
// no-op as the puttio:// url causes both errors 101/102
}else if (error.code == -1009) {
- [self.delegate OAuthHelperLoginFailedWithDesription:@"Your iPad is currently offline."];
+ [self.delegate authHelperLoginFailedWithDesription:@"Your iPad is currently offline."];
}else {
// actually unexpected
NSString *error = [NSString stringWithFormat:@"WebView not acting as expected %@", error];
- [self.delegate OAuthHelperLoginFailedWithDesription:error];
+ [self.delegate authHelperLoginFailedWithDesription:error];
}
}
}
@@ -110,7 +124,7 @@ - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
if([aWebView.request.URL.absoluteString isEqualToString:PTSettingsURL]){
[self parseForV1Tokens];
- [self.delegate OAuthHelperDidLogin:self];
+ [self.delegate authHelperDidLogin:self];
}
}
View
6 Puttio/en.lproj/MainStoryboard.storyboard
@@ -429,7 +429,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<connections>
- <outlet property="delegate" destination="gND-ap-Oq0" id="SaG-fq-xD7"/>
+ <outlet property="delegate" destination="kuB-Ee-JBF" id="KC9-uR-IRO"/>
</connections>
</webView>
<view contentMode="scaleToFill" id="RTs-9t-64d">
@@ -511,16 +511,16 @@ Message</string>
<outlet property="passwordTextfield" destination="7qr-I8-ulE" id="UeA-O1-aYA"/>
<outlet property="usernameTextfield" destination="eU6-zT-B2t" id="Jac-y1-Suk"/>
<outlet property="warningLabel" destination="P60-EY-4Xo" id="Kw1-bf-PYa"/>
- <outlet property="webView" destination="vzR-Xs-Iu9" id="rin-xf-Y80"/>
</connections>
</viewController>
<customObject id="kuB-Ee-JBF" customClass="PutIOOAuthHelper">
<connections>
<outlet property="delegate" destination="gND-ap-Oq0" id="01f-hb-rfi"/>
+ <outlet property="webView" destination="vzR-Xs-Iu9" id="ymS-Nw-OXY"/>
</connections>
</customObject>
</objects>
- <point key="canvasLocation" x="-3426" y="454"/>
+ <point key="canvasLocation" x="-3424" y="457"/>
</scene>
</scenes>
<classes>
Please sign in to comment.
Something went wrong with that request. Please try again.