Skip to content

Commit

Permalink
Adds Pocket support to the UIActivityVC
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachOrr committed Jun 29, 2013
1 parent 92947fb commit 554f8d1
Show file tree
Hide file tree
Showing 22 changed files with 2,492 additions and 41 deletions.

This file was deleted.

15 changes: 15 additions & 0 deletions Hacker News/Constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Constants.h
// Hacker News
//
// Created by Zach Orr on 6/29/13.
// Copyright (c) 2013 Maximilian Mackh. All rights reserved.
//

#ifndef Hacker_News_Constants_h
#define Hacker_News_Constants_h

#define kPocketConsumerKeyiPhone @""
#define kPocketConsumerKeyiPad @""

#endif
11 changes: 11 additions & 0 deletions Hacker News/Hacker News-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.getpocket.sdk</string>
<key>CFBundleURLSchemes</key>
<array>
<string>pocketappXXXX</string>
</array>
</dict>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
27 changes: 27 additions & 0 deletions Hacker News/MAMAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//

#import "MAMAppDelegate.h"
#import "PocketAPI.h"
#import "Constants.h"

@implementation MAMAppDelegate

Expand All @@ -16,9 +18,34 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
int cacheSizeDisk = 100*1024*1024;
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"hncache"];
[NSURLCache setSharedURLCache:sharedCache];

NSString *pocketConsumerKey = @"";
if ([(NSString*)[UIDevice currentDevice].model isEqualToString:@"iPad"])
{
pocketConsumerKey = kPocketConsumerKeyiPad;
}
else
{
pocketConsumerKey = kPocketConsumerKeyiPhone;
}
[[PocketAPI sharedAPI] setConsumerKey:pocketConsumerKey];

return YES;
}

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if([[PocketAPI sharedAPI] handleOpenURL:url])
{
return YES;
}
else
{
return NO;
}

}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
[[NSURLCache sharedURLCache] removeAllCachedResponses];
Expand Down
6 changes: 4 additions & 2 deletions Hacker News/MAMReaderViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "NSString+Additions.h"
#import <QuartzCore/QuartzCore.h>
#import "TUSafariActivity.h"
#import "PocketAPIActivity.h"

typedef NS_ENUM(NSInteger, StoryTransitionType)
{
Expand Down Expand Up @@ -248,8 +249,9 @@ - (IBAction)tabButtonTapped:(id)sender
case 4:
{
NSURL *URL = [NSURL URLWithString:self.story.link];
TUSafariActivity *activity = [[TUSafariActivity alloc] init];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[URL] applicationActivities:@[activity]];
TUSafariActivity *safariActivity = [[TUSafariActivity alloc] init];
PocketAPIActivity *pocketActivity = [[PocketAPIActivity alloc] init];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[URL] applicationActivities:@[safariActivity, pocketActivity]];
[activityViewController setExcludedActivityTypes:@[UIActivityTypePostToWeibo]];

if ([MAMHNController isPad])
Expand Down
Binary file added Hacker News/PocketSDK/.DS_Store
Binary file not shown.
67 changes: 67 additions & 0 deletions Hacker News/PocketSDK/PocketAPI+NSOperation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// PocketAPI.h
// PocketSDK
//
// Created by James Yopp on 2012/08/21.
// Copyright (c) 2012 Read It Later, Inc.
//
// 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.
//


// Advanced use if you use your own NSOperationQueues for handling network traffic.
// If you don't need tight control over network requests, just use the simple API.
// Note: May not behave predictably if recoverable errors are encountered.

@interface PocketAPI (NSOperations)

-(NSOperation *)saveOperationWithURL:(NSURL *)url
delegate:(id<PocketAPIDelegate>)delegate;

-(NSOperation *)saveOperationWithURL:(NSURL *)url
title:(NSString *)title
delegate:(id<PocketAPIDelegate>)delegate;

-(NSOperation *)saveOperationWithURL:(NSURL *)url
title:(NSString *)title
tweetID:(NSString *)tweetID
delegate:(id<PocketAPIDelegate>)delegate;

-(NSOperation *)methodOperationWithAPIMethod:(NSString *)APIMethod
forHTTPMethod:(PocketAPIHTTPMethod)HTTPMethod
arguments:(NSDictionary *)arguments
delegate:(id<PocketAPIDelegate>)delegate;

#if NS_BLOCKS_AVAILABLE
-(NSOperation *)saveOperationWithURL:(NSURL *)url
handler:(PocketAPISaveHandler)handler;

-(NSOperation *)saveOperationWithURL:(NSURL *)url
title:(NSString *)title
handler:(PocketAPISaveHandler)handler;

-(NSOperation *)saveOperationWithURL:(NSURL *)url
title:(NSString *)title
tweetID:(NSString *)tweetID
handler:(PocketAPISaveHandler)handler;

-(NSOperation *)methodOperationWithAPIMethod:(NSString *)APIMethod
forHTTPMethod:(PocketAPIHTTPMethod)HTTPMethod
arguments:(NSDictionary *)arguments
handler:(PocketAPIResponseHandler)handler;
#endif

@end
118 changes: 118 additions & 0 deletions Hacker News/PocketSDK/PocketAPI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//
// PocketAPI.h
// PocketSDK
//
// Created by Steve Streza on 5/29/12.
// Copyright (c) 2012 Read It Later, Inc.
//
// 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.
//

/**
* The PocketAPI class represents a singleton for saving stuff to a user's Pocket list.
* To begin, you will need to obtain an API token from https://getpocket.com/api/ and set it
* on the PocketAPI singleton at some point at the beginning of your application's lifecycle.
*
* APIs are presented in one of four ways, but all behave fundamentally the same. Their differences
* are presented for flexibility for your app. You can use:
*
* - a delegate-based API
* - a block-based API
* - an NSOperation based on a delegate (for advanced uses)
* - an NSOperation based on a block (for advanced uses)
*
* All delegates and blocks are called on the main thread, so you can safely update UI from there.
*
* You can find more information on these in PocketAPITypes.h
*
* These classes are not implemented as ARC, but will interoperate with ARC. You will need to add the
* -fno-objc-arc compiler flag to each of the files in the SDK.
*/

#import <Foundation/Foundation.h>
#import "PocketAPITypes.h"

@class PocketAPILogin;

@interface PocketAPI : NSObject {
NSString *consumerKey;
NSString *URLScheme;
NSOperationQueue *operationQueue;

PocketAPILogin *currentLogin;
NSString *userAgent;
}

@property (nonatomic, retain) NSString *consumerKey;
@property (nonatomic, retain) NSString *URLScheme; // if you do not set this, it is derived from your consumer key

@property (nonatomic, copy, readonly) NSString *username;
@property (nonatomic, assign, readonly, getter=isLoggedIn) BOOL loggedIn;

@property (nonatomic, retain) NSOperationQueue *operationQueue;

+(PocketAPI *)sharedAPI;
+(BOOL)hasPocketAppInstalled;
+(NSString *)pocketAppURLScheme;

-(void)setConsumerKey:(NSString *)consumerKey;

-(NSUInteger)appID;

// Simple API
-(void)loginWithDelegate:(id<PocketAPIDelegate>)delegate;

-(void)saveURL:(NSURL *)url
delegate:(id<PocketAPIDelegate>)delegate;
-(void)saveURL:(NSURL *)url
withTitle:(NSString *)title
delegate:(id<PocketAPIDelegate>)delegate;
-(void)saveURL:(NSURL *)url
withTitle:(NSString *)title
tweetID:(NSString *)tweetID
delegate:(id<PocketAPIDelegate>)delegate;

-(void)callAPIMethod:(NSString *)apiMethod
withHTTPMethod:(PocketAPIHTTPMethod)HTTPMethod
arguments:(NSDictionary *)arguments
delegate:(id<PocketAPIDelegate>)delegate;

#if NS_BLOCKS_AVAILABLE
-(void)loginWithHandler:(PocketAPILoginHandler)handler;

-(void)saveURL:(NSURL *)url
handler:(PocketAPISaveHandler)handler;
-(void)saveURL:(NSURL *)url
withTitle:(NSString *)title
handler:(PocketAPISaveHandler)handler;
-(void)saveURL:(NSURL *)url
withTitle:(NSString *)title
tweetID:(NSString *)tweetID
handler:(PocketAPISaveHandler)handler;

-(void)callAPIMethod:(NSString *)apiMethod
withHTTPMethod:(PocketAPIHTTPMethod)HTTPMethod
arguments:(NSDictionary *)arguments
handler:(PocketAPIResponseHandler)handler;
#endif

-(void)logout;

-(BOOL)handleOpenURL:(NSURL *)url;

@end

extern NSString *PocketAPITweetID(unsigned long long tweetID);
Loading

0 comments on commit 554f8d1

Please sign in to comment.