Skip to content

Commit bc7446d

Browse files
committed
Pocket integration
1 parent 8c5fa4f commit bc7446d

16 files changed

Lines changed: 2320 additions & 7 deletions

File tree

‎PocketSDK/PocketAPI+NSOperation.h‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// PocketAPI.h
3+
// PocketSDK
4+
//
5+
// Created by James Yopp on 2012/08/21.
6+
// Copyright (c) 2012 Read It Later, Inc.
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
9+
// software and associated documentation files (the "Software"), to deal in the Software
10+
// without restriction, including without limitation the rights to use, copy, modify,
11+
// merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
12+
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in all copies or
15+
// substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
18+
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
//
23+
24+
25+
// Advanced use if you use your own NSOperationQueues for handling network traffic.
26+
// If you don't need tight control over network requests, just use the simple API.
27+
// Note: May not behave predictably if recoverable errors are encountered.
28+
29+
@interface PocketAPI (NSOperations)
30+
31+
-(NSOperation *)saveOperationWithURL:(NSURL *)url
32+
delegate:(id<PocketAPIDelegate>)delegate;
33+
34+
-(NSOperation *)saveOperationWithURL:(NSURL *)url
35+
title:(NSString *)title
36+
delegate:(id<PocketAPIDelegate>)delegate;
37+
38+
-(NSOperation *)saveOperationWithURL:(NSURL *)url
39+
title:(NSString *)title
40+
tweetID:(NSString *)tweetID
41+
delegate:(id<PocketAPIDelegate>)delegate;
42+
43+
-(NSOperation *)methodOperationWithAPIMethod:(NSString *)APIMethod
44+
forHTTPMethod:(PocketAPIHTTPMethod)HTTPMethod
45+
arguments:(NSDictionary *)arguments
46+
delegate:(id<PocketAPIDelegate>)delegate;
47+
48+
#if NS_BLOCKS_AVAILABLE
49+
-(NSOperation *)saveOperationWithURL:(NSURL *)url
50+
handler:(PocketAPISaveHandler)handler;
51+
52+
-(NSOperation *)saveOperationWithURL:(NSURL *)url
53+
title:(NSString *)title
54+
handler:(PocketAPISaveHandler)handler;
55+
56+
-(NSOperation *)saveOperationWithURL:(NSURL *)url
57+
title:(NSString *)title
58+
tweetID:(NSString *)tweetID
59+
handler:(PocketAPISaveHandler)handler;
60+
61+
-(NSOperation *)methodOperationWithAPIMethod:(NSString *)APIMethod
62+
forHTTPMethod:(PocketAPIHTTPMethod)HTTPMethod
63+
arguments:(NSDictionary *)arguments
64+
handler:(PocketAPIResponseHandler)handler;
65+
#endif
66+
67+
@end

‎PocketSDK/PocketAPI.h‎

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//
2+
// PocketAPI.h
3+
// PocketSDK
4+
//
5+
// Created by Steve Streza on 5/29/12.
6+
// Copyright (c) 2012 Read It Later, Inc.
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
9+
// software and associated documentation files (the "Software"), to deal in the Software
10+
// without restriction, including without limitation the rights to use, copy, modify,
11+
// merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
12+
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in all copies or
15+
// substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
18+
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
//
23+
24+
/**
25+
* The PocketAPI class represents a singleton for saving stuff to a user's Pocket list.
26+
* To begin, you will need to obtain an API token from https://getpocket.com/api/ and set it
27+
* on the PocketAPI singleton at some point at the beginning of your application's lifecycle.
28+
*
29+
* APIs are presented in one of four ways, but all behave fundamentally the same. Their differences
30+
* are presented for flexibility for your app. You can use:
31+
*
32+
* - a delegate-based API
33+
* - a block-based API
34+
* - an NSOperation based on a delegate (for advanced uses)
35+
* - an NSOperation based on a block (for advanced uses)
36+
*
37+
* All delegates and blocks are called on the main thread, so you can safely update UI from there.
38+
*
39+
* You can find more information on these in PocketAPITypes.h
40+
*
41+
* These classes are not implemented as ARC, but will interoperate with ARC. You will need to add the
42+
* -fno-objc-arc compiler flag to each of the files in the SDK.
43+
*/
44+
45+
#import <Foundation/Foundation.h>
46+
#import "PocketAPITypes.h"
47+
48+
@class PocketAPILogin;
49+
50+
@interface PocketAPI : NSObject {
51+
NSString *consumerKey;
52+
NSString *URLScheme;
53+
NSOperationQueue *operationQueue;
54+
55+
PocketAPILogin *currentLogin;
56+
NSString *userAgent;
57+
}
58+
59+
@property (nonatomic, retain) NSString *consumerKey;
60+
@property (nonatomic, retain) NSString *URLScheme; // if you do not set this, it is derived from your consumer key
61+
62+
@property (nonatomic, copy, readonly) NSString *username;
63+
@property (nonatomic, assign, readonly, getter=isLoggedIn) BOOL loggedIn;
64+
65+
@property (nonatomic, retain) NSOperationQueue *operationQueue;
66+
67+
+(PocketAPI *)sharedAPI;
68+
+(BOOL)hasPocketAppInstalled;
69+
+(NSString *)pocketAppURLScheme;
70+
71+
-(void)setConsumerKey:(NSString *)consumerKey;
72+
73+
-(NSUInteger)appID;
74+
75+
// Simple API
76+
-(void)loginWithDelegate:(id<PocketAPIDelegate>)delegate;
77+
78+
-(void)saveURL:(NSURL *)url
79+
delegate:(id<PocketAPIDelegate>)delegate;
80+
-(void)saveURL:(NSURL *)url
81+
withTitle:(NSString *)title
82+
delegate:(id<PocketAPIDelegate>)delegate;
83+
-(void)saveURL:(NSURL *)url
84+
withTitle:(NSString *)title
85+
tweetID:(NSString *)tweetID
86+
delegate:(id<PocketAPIDelegate>)delegate;
87+
88+
-(void)callAPIMethod:(NSString *)apiMethod
89+
withHTTPMethod:(PocketAPIHTTPMethod)HTTPMethod
90+
arguments:(NSDictionary *)arguments
91+
delegate:(id<PocketAPIDelegate>)delegate;
92+
93+
#if NS_BLOCKS_AVAILABLE
94+
-(void)loginWithHandler:(PocketAPILoginHandler)handler;
95+
96+
-(void)saveURL:(NSURL *)url
97+
handler:(PocketAPISaveHandler)handler;
98+
-(void)saveURL:(NSURL *)url
99+
withTitle:(NSString *)title
100+
handler:(PocketAPISaveHandler)handler;
101+
-(void)saveURL:(NSURL *)url
102+
withTitle:(NSString *)title
103+
tweetID:(NSString *)tweetID
104+
handler:(PocketAPISaveHandler)handler;
105+
106+
-(void)callAPIMethod:(NSString *)apiMethod
107+
withHTTPMethod:(PocketAPIHTTPMethod)HTTPMethod
108+
arguments:(NSDictionary *)arguments
109+
handler:(PocketAPIResponseHandler)handler;
110+
#endif
111+
112+
-(void)logout;
113+
114+
-(BOOL)handleOpenURL:(NSURL *)url;
115+
116+
@end
117+
118+
extern NSString *PocketAPITweetID(unsigned long long tweetID);

0 commit comments

Comments
 (0)