Skip to content

Commit

Permalink
Converted iVars to properties.
Browse files Browse the repository at this point in the history
Converted `cancel` to use `AFHTTPSessionManager` instead of operation.
Added initial support for `RSS media`.
Added instance methods for parsing to `RSSParser`.
  • Loading branch information
JRG-Developer committed Apr 2, 2014
1 parent 3b6f174 commit 0197081
Show file tree
Hide file tree
Showing 12 changed files with 309 additions and 120 deletions.
10 changes: 7 additions & 3 deletions RSSParser/RSSItem.h
Expand Up @@ -9,7 +9,6 @@
#import <UIKit/UIKit.h>

@interface RSSItem : NSObject <NSCoding>

@property (strong,nonatomic) NSString *title;
@property (strong,nonatomic) NSString *itemDescription;
@property (strong,nonatomic) NSString *content;
Expand All @@ -21,7 +20,12 @@
@property (strong,nonatomic) NSString *author;
@property (strong,nonatomic) NSString *guid;

-(NSArray *)imagesFromItemDescription;
-(NSArray *)imagesFromContent;
@property (strong,nonatomic) NSString *mediaTitle;
@property (strong,nonatomic) NSString *mediaDescription;
@property (strong,nonatomic) NSArray *mediaCredits;
@property (strong,nonatomic) NSArray *mediaThumbnails;

- (NSArray *)imagesFromItemDescription;
- (NSArray *)imagesFromContent;

@end
12 changes: 6 additions & 6 deletions RSSParser/RSSItem.m
Expand Up @@ -10,13 +10,13 @@

@interface RSSItem (Private)

-(NSArray *)imagesFromHTMLString:(NSString *)htmlstr;
- (NSArray *)imagesFromHTMLString:(NSString *)htmlstr;

@end

@implementation RSSItem

-(NSArray *)imagesFromItemDescription
- (NSArray *)imagesFromItemDescription
{
if (self.itemDescription) {
return [self imagesFromHTMLString:self.itemDescription];
Expand All @@ -25,7 +25,7 @@ -(NSArray *)imagesFromItemDescription
return nil;
}

-(NSArray *)imagesFromContent
- (NSArray *)imagesFromContent
{
if (self.content) {
return [self imagesFromHTMLString:self.content];
Expand All @@ -36,7 +36,7 @@ -(NSArray *)imagesFromContent

#pragma mark - retrieve images from html string using regexp (private methode)

-(NSArray *)imagesFromHTMLString:(NSString *)htmlstr
- (NSArray *)imagesFromHTMLString:(NSString *)htmlstr
{
NSMutableArray *imagesURLStringArray = [[NSMutableArray alloc] init];

Expand All @@ -59,7 +59,7 @@ -(NSArray *)imagesFromHTMLString:(NSString *)htmlstr

#pragma mark - NSCoding

- (id)initWithCoder:(NSCoder *)aDecoder
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super init]) {
_title = [aDecoder decodeObjectForKey:@"title"];
Expand Down Expand Up @@ -90,7 +90,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder
[aCoder encodeObject:self.guid forKey:@"guid"];
}

#pragma mark -
#pragma mark - NSObject protocol

- (BOOL)isEqual:(RSSItem *)object
{
Expand Down
14 changes: 14 additions & 0 deletions RSSParser/RSSMediaCredit.h
@@ -0,0 +1,14 @@
//
// RSSMediaCredit.h
// Pods
//
// Created by Joshua on 4/2/14.
//
//

#import <Foundation/Foundation.h>

@interface RSSMediaCredit : NSObject <NSCoding>
@property (strong,nonatomic) NSString *role;
@property (strong,nonatomic) NSString *value;
@end
31 changes: 31 additions & 0 deletions RSSParser/RSSMediaCredit.m
@@ -0,0 +1,31 @@
//
// RSSMediaCredit.m
// Pods
//
// Created by Joshua on 4/2/14.
//
//

#import "RSSMediaCredit.h"

@implementation RSSMediaCredit

#pragma mark - NSCoding

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super init]) {
_role = [aDecoder decodeObjectForKey:@"role"];
_value = [aDecoder decodeObjectForKey:@"value"];
}

return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.role forKey:@"role"];
[aCoder encodeObject:self.value forKey:@"value"];
}

@end
15 changes: 15 additions & 0 deletions RSSParser/RSSMediaThumbnail.h
@@ -0,0 +1,15 @@
//
// RSSMediaThumbnail.h
// Pods
//
// Created by Joshua on 4/2/14.
//
//

#import <Foundation/Foundation.h>

@interface RSSMediaThumbnail : NSObject <NSCoding>
@property (strong,nonatomic) NSURL *url;
@property (assign,nonatomic) float height;
@property (assign,nonatomic) float width;
@end
30 changes: 30 additions & 0 deletions RSSParser/RSSMediaThumbnail.m
@@ -0,0 +1,30 @@
//
// RSSMediaThumbnail.m
// Pods
//
// Created by Joshua on 4/2/14.
//
//

#import "RSSMediaThumbnail.h"

@implementation RSSMediaThumbnail

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super init]) {
_url = [aDecoder decodeObjectForKey:@"url"];
_height = [[aDecoder decodeObjectForKey:@"height"] floatValue];
_width = [[aDecoder decodeObjectForKey:@"width"] floatValue];
}
return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.url forKey:@"url"];
[aCoder encodeObject:@(self.height) forKey:@"height"];
[aCoder encodeObject:@(self.width) forKey:@"width"];
}

@end
32 changes: 18 additions & 14 deletions RSSParser/RSSParser.h
Expand Up @@ -7,29 +7,33 @@
//

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

@class AFHTTPRequestOperation;
@class AFHTTPSessionManager;

@interface RSSParser : NSObject <NSXMLParserDelegate> {
RSSItem *currentItem;
NSMutableArray *items;
NSMutableString *tmpString;
void (^block)(NSArray *feedItems);
void (^failblock)(NSError *error);
}

@property (nonatomic, strong) AFHTTPRequestOperation *operation;
@interface RSSParser : NSObject <NSXMLParserDelegate>
@property (nonatomic, strong) AFHTTPSessionManager *client;
@property (nonatomic, strong) NSXMLParser *xmlParser;

+ (RSSParser *)parseRSSFeedForRequest:(NSURLRequest *)urlRequest
success:(void (^)(NSArray *feedItems))success
failure:(void (^)(NSError *error))failure;
+ (void)parseRSSFeedForRequest:(NSURLRequest *)urlRequest
success:(void (^)(NSArray *feedItems))success
failure:(void (^)(NSError *error))failure;

- (void)parseRSSFeedForURLString:(NSString *)urlString
success:(void (^)(NSArray *feedItems))success
failure:(void (^)(NSError *error))failure;

- (void)parseRSSFeedForURL:(NSURL *)url
success:(void (^)(NSArray *feedItems))success
failure:(void (^)(NSError *error))failure;

- (void)parseRSSFeedForRequest:(NSURLRequest *)urlRequest
success:(void (^)(NSArray *feedItems))success
failure:(void (^)(NSError *error))failure;

- (void)parseRSSFeedForURLString:(NSString *)urlString
parameters:(NSDictionary *)paremeters
success:(void (^)(NSArray *feedItems))success
failure:(void (^)(NSError *error))failure;
- (void)cancel;

@end

0 comments on commit 0197081

Please sign in to comment.