|
| 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