Skip to content

Commit

Permalink
New Instapaper Demo
Browse files Browse the repository at this point in the history
This demo shows how to use RSOAuthEngine with xAuth to add a bookmark to Instapaper.
  • Loading branch information
rsieiro committed Feb 8, 2012
1 parent f74eb68 commit e69989c
Show file tree
Hide file tree
Showing 16 changed files with 2,533 additions and 0 deletions.
430 changes: 430 additions & 0 deletions InstapaperDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions InstapaperDemo/AppDelegate.h
@@ -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
82 changes: 82 additions & 0 deletions InstapaperDemo/AppDelegate.m
@@ -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
46 changes: 46 additions & 0 deletions InstapaperDemo/AuthViewController.h
@@ -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
87 changes: 87 additions & 0 deletions InstapaperDemo/AuthViewController.m
@@ -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
59 changes: 59 additions & 0 deletions InstapaperDemo/Instapaper/RSInstapaperEngine.h
@@ -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

0 comments on commit e69989c

Please sign in to comment.