Created
October 1, 2015 19:00
-
-
Save rdougan/aefbe206c48e9dde1f51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// RKLink+Imgur.h | |
// | |
// Created by Robert Dougan on 01/10/15. | |
// Copyright © 2015 Robert Dougan. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
#import "RKLink.h" | |
@interface RKLink (Imgur) | |
- (BOOL)isImgurImage; | |
- (BOOL)isImgurAlbum; | |
- (NSURL *)imgurImageURL; | |
- (NSURL *)imgurThumbnailURL; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// RKLink+Imgur.m | |
// | |
// Created by Robert Dougan on 01/10/15. | |
// Copyright © 2015 Robert Dougan. All rights reserved. | |
// | |
#import "RKLink+Imgur.h" | |
#import <RedditKit/RedditKit.h> | |
@implementation RKLink (Imgur) | |
- (BOOL)isImgurImage | |
{ | |
if (self.URL == nil) { | |
return NO; | |
} | |
if (![self.URL.host containsString:@"imgur.com"]) { | |
return NO; | |
} | |
if (self.URL.pathComponents.count > 2 && [[self.URL.pathComponents objectAtIndex:1] isEqualToString:@"a"]) { | |
return NO; | |
} | |
return YES; | |
} | |
- (NSURL *)imgurImageURL | |
{ | |
if (![self isImgurImage]) { | |
return nil; | |
} | |
NSString *imageId = self.URL.pathComponents.lastObject; | |
if (imageId == nil) { | |
return nil; | |
} | |
if ([imageId containsString:@".gifv"]) { | |
return [NSURL URLWithString:[self.URL.absoluteString stringByReplacingOccurrencesOfString:@".gifv" withString:@".gif"]]; | |
} | |
return [NSURL URLWithString:[NSString stringWithFormat:@"http://imgur.com/%@.jpg", imageId]]; | |
} | |
- (NSURL *)imgurThumbnailURL | |
{ | |
if (![self isImgurImage]) { | |
return nil; | |
} | |
NSString *imageId = self.URL.pathComponents.lastObject; | |
if (imageId == nil) { | |
return nil; | |
} | |
if ([imageId containsString:@".gif"]) { | |
imageId = [imageId stringByReplacingOccurrencesOfString:@".gif" withString:@"t.gif"]; | |
} | |
else { | |
imageId = [imageId stringByAppendingString:@"t.jpg"]; | |
} | |
return [NSURL URLWithString:[NSString stringWithFormat:@"http://imgur.com/%@", imageId]]; | |
} | |
- (BOOL)isImgurAlbum | |
{ | |
if (self.URL == nil) { | |
return NO; | |
} | |
if (![self.URL.host isEqualToString:@"imgur.com"]) { | |
return NO; | |
} | |
if (self.URL.pathComponents.count < 3 || ![[self.URL.pathComponents objectAtIndex:1] isEqualToString:@"a"]) { | |
return NO; | |
} | |
return YES; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment