diff options
| -rw-r--r-- | Providers/QSDeliciousAPIProvider.h | 4 | ||||
| -rw-r--r-- | Providers/QSDeliciousAPIProvider.m | 41 | ||||
| -rw-r--r-- | README.markdown | 12 | ||||
| -rw-r--r-- | Types/SocialSite.h | 2 | ||||
| -rw-r--r-- | Types/SocialSite.m | 6 |
5 files changed, 40 insertions, 25 deletions
diff --git a/Providers/QSDeliciousAPIProvider.h b/Providers/QSDeliciousAPIProvider.h index 08a0534..7979812 100644 --- a/Providers/QSDeliciousAPIProvider.h +++ b/Providers/QSDeliciousAPIProvider.h @@ -16,7 +16,7 @@ // Subclasses can override these methods - (NSString *)apiURLForSite:(SocialSite)site andHost:(NSString *)host; - (NSURL *)requestURLForSite:(SocialSite)site username:(NSString *)username password:(NSString *)password host:(NSString *)host; -- (NSData *)cachedBookmarkDataForSite:(SocialSite)site username:(NSString *)username; -- (void)cacheBookmarkData:(NSData *)data forSite:(SocialSite)site username:(NSString *)username; +- (NSData *)cachedBookmarkDataForSite:(SocialSite)site username:(NSString *)username host:(NSString *)host; +- (void)cacheBookmarkData:(NSData *)data forSite:(SocialSite)site username:(NSString *)username host:(NSString *)host; @end diff --git a/Providers/QSDeliciousAPIProvider.m b/Providers/QSDeliciousAPIProvider.m index 31b283d..0c37a43 100644 --- a/Providers/QSDeliciousAPIProvider.m +++ b/Providers/QSDeliciousAPIProvider.m @@ -47,38 +47,45 @@ } - (NSURL *)requestURLForSite:(SocialSite)site username:(NSString *)username password:(NSString *)password host:(NSString *)host { - NSString *apiURL = [self apiURLForSite:site andHost: host]; + NSString *apiURL = [self apiURLForSite:site andHost: host]; if (!apiURL) return nil; NSString *urlString; if ([self usesAuthToken:site]) { // Pinboard and pinboard compatible sites require an // auth token rather than a password. - urlString = [NSString stringWithFormat:@"%@/posts/all?auth_token=%@:%@", apiURL, username, password]; + urlString = [NSString stringWithFormat:@"%@/posts/all?auth_token=%@", apiURL, password]; } else { urlString = [NSString stringWithFormat:@"https://%@:%@@%@/posts/all?", username, password, apiURL]; } return [NSURL URLWithString:urlString]; } -- (NSData *)cachedBookmarkDataForSite:(SocialSite)site username:(NSString *)username { - NSString *siteURL = [SocialSiteHelper siteURLForSite:site]; - NSString *cachePath = [QSApplicationSupportSubPath([NSString stringWithFormat:@"Caches/%@/", siteURL], NO) stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.xml", username]]; - return [NSData dataWithContentsOfFile:cachePath]; +# pragma mark - Cache + +- (NSString *)cachePathForSite:(SocialSite)site username:(NSString *)username host:(NSString *)host create:(BOOL) create { + + NSString *siteURL = [SocialSiteHelper cacheKeyForSite:site]; + NSString *safeHost = [[host componentsSeparatedByCharactersInSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]] componentsJoinedByString:@"-"]; + return [QSApplicationSupportSubPath([NSString stringWithFormat:@"Caches/%@/", siteURL], create) stringByAppendingPathComponent:[NSString stringWithFormat:@"%@-%@.xml", safeHost, username]]; +} + + +- (NSData *)cachedBookmarkDataForSite:(SocialSite)site username:(NSString *)username host:(NSString *)host { + NSString *cachePath = [self cachePathForSite: site username: username host: host create: NO]; + return [NSData dataWithContentsOfFile:cachePath]; } -- (void)cacheBookmarkData:(NSData *)data forSite:(SocialSite)site username:(NSString *)username { - NSString *siteURL = [SocialSiteHelper siteURLForSite:site]; - NSString *safeURL = [[siteURL componentsSeparatedByCharactersInSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]] componentsJoinedByString:@"-"]; - NSString *cachePath = [QSApplicationSupportSubPath([NSString stringWithFormat:@"Caches/%@/", safeURL], YES) stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.xml", username]]; +- (void)cacheBookmarkData:(NSData *)data forSite:(SocialSite)site username:(NSString *)username host:(NSString *)host { + NSString *cachePath = [self cachePathForSite: site username: username host: host create: YES]; [data writeToFile:cachePath atomically:NO]; } - (NSArray *)fetchBookmarksForSite:(SocialSite)site username:(NSString *)username password:(NSString *)password identifier:(NSString *)identifier host:(NSString *)host includeTags:(BOOL)includeTags { // Try cached data first - NSData *data = [self cachedBookmarkDataForSite:site username:username]; - + NSData *data = [self cachedBookmarkDataForSite:site username:username host:host]; + // If no cached data, fetch from API if (![data length]) { NSURL *requestURL = [self requestURLForSite:site username:username password:password host:host]; @@ -87,7 +94,7 @@ NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:requestURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; - [theRequest setHTTPMethod:@"POST"]; + [theRequest setHTTPMethod:@"GET"]; [theRequest setValue:@"text/xml" forHTTPHeaderField:@"Content-type"]; [theRequest setValue:@"Quicksilver (Blacktree,MacOSX)" forHTTPHeaderField:@"User-Agent"]; @@ -100,11 +107,9 @@ } // Cache the data - [self cacheBookmarkData:data forSite:site username:username]; + [self cacheBookmarkData:data forSite:site username:username host:host]; } - NSLog(@"WE ARE READY TO PARSE"); - // Parse XML data NSXMLParser *postParser = [[NSXMLParser alloc] initWithData:data]; [postParser setDelegate:self]; @@ -112,8 +117,6 @@ self.posts = [NSMutableArray arrayWithCapacity:1]; [postParser parse]; - NSLog(@"STILL READY: %ld", [self.posts count]); - NSMutableArray *objects = [NSMutableArray arrayWithCapacity:1]; NSMutableSet *tagSet = [NSMutableSet set]; @@ -155,7 +158,7 @@ } - (NSArray *)fetchBookmarksForTag:(NSString *)tag site:(SocialSite)site username:(NSString *)username password:(NSString *)password host:(NSString *)host { - NSData *data = [self cachedBookmarkDataForSite:site username:username]; + NSData *data = [self cachedBookmarkDataForSite:site username:username host:host]; if (!data) return @[]; NSXMLParser *postParser = [[NSXMLParser alloc] initWithData:data]; diff --git a/README.markdown b/README.markdown index c22d609..5a08e8e 100644 --- a/README.markdown +++ b/README.markdown @@ -58,4 +58,14 @@ By downloading and/or using this software you agree to the following terms of us limitations under the License. -Which basically means: whatever you do, I can't be held accountable if something breaks.
\ No newline at end of file +Which basically means: whatever you do, I can't be held accountable if something breaks. + +Supported Services +----------- + +This plugin supports Delicious compatible services (eg. Linkhut), and Linkding. It's important to note that delicious compatible systems aren't all compatible in the same way, so you might need to make some adjustments: + + +- For every self-hsoted service, make sure to include the protocol (eg. https://). +- For delicious compatible items, include everything before `/v1`. So if it's `https://api.ln.ht/v1` you just include `https://api.ln.ht`. But if it's `https://myservice.com/api/v1` then you should include `https://myservice.com/api` with no trailing slash. +- For delicious compatible items, check what they expect for the `auth_token` field and use that as your password. For example, in pinboard it's `username:token`, while in linkhut it's just `token`. diff --git a/Types/SocialSite.h b/Types/SocialSite.h index 130bc40..43155c7 100644 --- a/Types/SocialSite.h +++ b/Types/SocialSite.h @@ -18,7 +18,7 @@ typedef NS_ENUM(NSInteger, SocialSite) { @interface SocialSiteHelper : NSObject + (NSString *)displayNameForSite:(SocialSite)site; -+ (NSString *)siteURLForSite:(SocialSite)site; ++ (NSString *)cacheKeyForSite:(SocialSite)site; + (BOOL)hasVariableHost:(SocialSite)site; @end diff --git a/Types/SocialSite.m b/Types/SocialSite.m index b73533f..369f86d 100644 --- a/Types/SocialSite.m +++ b/Types/SocialSite.m @@ -24,7 +24,8 @@ } } -+ (NSString *)siteURLForSite:(SocialSite)site { +// This is used for caching key ++ (NSString *)cacheKeyForSite:(SocialSite)site { switch (site) { case SocialSiteDelicious: return @"del.icio.us"; @@ -33,8 +34,9 @@ case SocialSitePinboard: return @"pinboard.in"; case SocialSiteSelfHostedDeliciousCompatible: + return @"self-hosted-delicious"; case SocialSiteLinkding: - return @""; // Will be provided by user as host + return @"linkding"; default: return nil; } |