forked from rsieiro/RSOAuthEngine
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This demo shows how to use RSOAuthEngine with xAuth to add a bookmark to Instapaper.
- Loading branch information
Showing
16 changed files
with
2,533 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
InstapaperDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// AppDelegate.h | ||
// InstapaperDemo | ||
// | ||
// Created by Rodrigo Sieiro on 12/13/11. | ||
// Copyright (c) 2011 Rodrigo Sieiro <rsieiro@sharpcube.com>. All rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@class ViewController; | ||
|
||
@interface AppDelegate : UIResponder <UIApplicationDelegate> | ||
|
||
@property (strong, nonatomic) UIWindow *window; | ||
@property (strong, nonatomic) ViewController *viewController; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// AppDelegate.m | ||
// InstapaperDemo | ||
// | ||
// Created by Rodrigo Sieiro on 12/13/11. | ||
// Copyright (c) 2011 Rodrigo Sieiro <rsieiro@sharpcube.com>. All rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import "AppDelegate.h" | ||
#import "ViewController.h" | ||
|
||
@implementation AppDelegate | ||
|
||
@synthesize window = _window; | ||
@synthesize viewController = _viewController; | ||
|
||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | ||
{ | ||
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | ||
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; | ||
self.window.rootViewController = self.viewController; | ||
[self.window makeKeyAndVisible]; | ||
return YES; | ||
} | ||
|
||
- (void)applicationWillResignActive:(UIApplication *)application | ||
{ | ||
/* | ||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. | ||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. | ||
*/ | ||
} | ||
|
||
- (void)applicationDidEnterBackground:(UIApplication *)application | ||
{ | ||
/* | ||
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. | ||
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. | ||
*/ | ||
} | ||
|
||
- (void)applicationWillEnterForeground:(UIApplication *)application | ||
{ | ||
/* | ||
Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. | ||
*/ | ||
} | ||
|
||
- (void)applicationDidBecomeActive:(UIApplication *)application | ||
{ | ||
/* | ||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. | ||
*/ | ||
} | ||
|
||
- (void)applicationWillTerminate:(UIApplication *)application | ||
{ | ||
/* | ||
Called when the application is about to terminate. | ||
Save data if appropriate. | ||
See also applicationDidEnterBackground:. | ||
*/ | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// AuthViewController.h | ||
// InstapaperDemo | ||
// | ||
// Created by Rodrigo Sieiro on 07/02/12. | ||
// Copyright (c) 2012 Rodrigo Sieiro <rsieiro@sharpcube.com>. All rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@protocol AuthViewControllerDelegate; | ||
|
||
@interface AuthViewController : UIViewController <UITextFieldDelegate> | ||
|
||
@property (assign, nonatomic) id <AuthViewControllerDelegate> delegate; | ||
@property (unsafe_unretained, nonatomic) IBOutlet UITextField *usernameField; | ||
@property (unsafe_unretained, nonatomic) IBOutlet UITextField *passwordField; | ||
|
||
- (IBAction)authenticate:(id)sender; | ||
- (IBAction)cancelAuthentication:(id)sender; | ||
|
||
@end | ||
|
||
@protocol AuthViewControllerDelegate <NSObject> | ||
|
||
- (void)cancelAuthentication; | ||
- (void)authenticateWithUsername:(NSString *)username password:(NSString *)password; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// | ||
// AuthViewController.m | ||
// InstapaperDemo | ||
// | ||
// Created by Rodrigo Sieiro on 07/02/12. | ||
// Copyright (c) 2012 Rodrigo Sieiro <rsieiro@sharpcube.com>. All rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import "AuthViewController.h" | ||
|
||
@implementation AuthViewController | ||
|
||
@synthesize delegate = _delegate; | ||
@synthesize usernameField = _usernameField; | ||
@synthesize passwordField = _passwordField; | ||
|
||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil | ||
{ | ||
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | ||
return self; | ||
} | ||
|
||
#pragma mark - View lifecycle | ||
|
||
- (void)viewDidLoad | ||
{ | ||
[super viewDidLoad]; | ||
|
||
[self.usernameField becomeFirstResponder]; | ||
} | ||
|
||
- (void)viewDidUnload | ||
{ | ||
[self setUsernameField:nil]; | ||
[self setPasswordField:nil]; | ||
[super viewDidUnload]; | ||
} | ||
|
||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation | ||
{ | ||
return (interfaceOrientation == UIInterfaceOrientationPortrait); | ||
} | ||
|
||
#pragma mark - UITextField Delegate Methods | ||
|
||
- (BOOL)textFieldShouldReturn:(UITextField *)textField | ||
{ | ||
if (textField == self.usernameField) { | ||
[self.passwordField becomeFirstResponder]; | ||
} else if (textField == self.passwordField) { | ||
[self authenticate:nil]; | ||
} | ||
|
||
return YES; | ||
} | ||
|
||
#pragma mark - Custom Methods | ||
|
||
- (IBAction)authenticate:(id)sender | ||
{ | ||
if (self.delegate) [self.delegate authenticateWithUsername:self.usernameField.text | ||
password:self.passwordField.text]; | ||
} | ||
|
||
- (IBAction)cancelAuthentication:(id)sender | ||
{ | ||
if (self.delegate) [self.delegate cancelAuthentication]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// RSInstapaperEngine.h | ||
// RSOAuthEngine | ||
// | ||
// Created by Rodrigo Sieiro on 12/8/11. | ||
// Copyright (c) 2011 Rodrigo Sieiro <rsieiro@sharpcube.com>. All rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import "RSOAuthEngine.h" | ||
|
||
@protocol RSInstapaperEngineDelegate; | ||
|
||
typedef void (^RSInstapaperEngineCompletionBlock)(NSError *error); | ||
|
||
@interface RSInstapaperEngine : RSOAuthEngine | ||
{ | ||
RSInstapaperEngineCompletionBlock _oAuthCompletionBlock; | ||
NSString *_screenName; | ||
} | ||
|
||
@property (assign) id <RSInstapaperEngineDelegate> delegate; | ||
@property (readonly) NSString *screenName; | ||
|
||
- (id)initWithDelegate:(id <RSInstapaperEngineDelegate>)delegate; | ||
- (void)authenticateWithCompletionBlock:(RSInstapaperEngineCompletionBlock)completionBlock; | ||
- (void)authenticateWithUsername:(NSString *)username password:(NSString *)password; | ||
- (void)cancelAuthentication; | ||
- (void)forgetStoredToken; | ||
|
||
- (void)bookmarkURL:(NSString *)url | ||
title:(NSString *)title | ||
description:(NSString *)description | ||
completionBlock:(RSInstapaperEngineCompletionBlock)completionBlock; | ||
|
||
@end | ||
|
||
@protocol RSInstapaperEngineDelegate <NSObject> | ||
|
||
- (void)instapaperEngineNeedsAuthentication:(RSInstapaperEngine *)engine; | ||
- (void)instapaperEngine:(RSInstapaperEngine *)engine statusUpdate:(NSString *)message; | ||
|
||
@end |
Oops, something went wrong.