diff --git a/Classes/MWFeedItem.h b/Classes/MWFeedItem.h index 936ce60..8457a49 100644 --- a/Classes/MWFeedItem.h +++ b/Classes/MWFeedItem.h @@ -38,14 +38,8 @@ NSDate *updated; // Date the item was updated if available NSString *summary; // Description of item NSString *content; // More detailed content (if available) - - // Enclosures: Holds 1 or more item enclosures (i.e. podcasts, mp3. pdf, etc) - // - NSArray of NSDictionaries with the following keys: - // url: where the enclosure is located (NSString) - // length: how big it is in bytes (NSNumber) - // type: what its type is, a standard MIME type (NSString) - NSArray *enclosures; - + NSArray *enclosures; // Array of feed enclosures (MWFeedItemEnclosure) + } @property (nonatomic, copy) NSString *identifier; diff --git a/Classes/MWFeedItemEnclosure.h b/Classes/MWFeedItemEnclosure.h new file mode 100644 index 0000000..ac8fe34 --- /dev/null +++ b/Classes/MWFeedItemEnclosure.h @@ -0,0 +1,44 @@ +// +// MWFeedItemEnclosure.m +// MWFeedParser +// +// Copyright (c) 2010 Michael Waterfall +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// 1. The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// 2. This Software cannot be used to archive or collect data such as (but not +// limited to) that of events, news, experiences and activities, for the +// purpose of any concept relating to diary/journal keeping. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import + +@interface MWFeedItemEnclosure : NSObject { + + NSString *url; // Enclosure url + NSString *type; // Mime-type enclosure + NSInteger length; // File size in bytes + +} + +@property (nonatomic, copy) NSString *url; +@property (nonatomic, copy) NSString *type; +@property (nonatomic) NSInteger length; + +@end diff --git a/Classes/MWFeedItemEnclosure.m b/Classes/MWFeedItemEnclosure.m new file mode 100644 index 0000000..f5143e3 --- /dev/null +++ b/Classes/MWFeedItemEnclosure.m @@ -0,0 +1,69 @@ +// +// MWFeedItemEnclosure.m +// MWFeedParser +// +// Copyright (c) 2010 Michael Waterfall +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// 1. The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// 2. This Software cannot be used to archive or collect data such as (but not +// limited to) that of events, news, experiences and activities, for the +// purpose of any concept relating to diary/journal keeping. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "MWFeedItemEnclosure.h" + +@implementation MWFeedItemEnclosure + +@synthesize url, type, length; + +#pragma mark NSObject + +- (NSString *)description { + NSMutableString *string = [[NSMutableString alloc] initWithFormat:@"%@: ", NSStringFromClass([self class])]; + if (url) [string appendFormat:@"“%@”", url]; + if (type) [string appendFormat:@" (%@)", type]; + if (length) [string appendFormat:@" %i bytes", length]; + return [string autorelease]; +} + +- (void)dealloc { + [url release]; + [type release]; + [super dealloc]; +} + +#pragma mark NSCoding + +- (id)initWithCoder:(NSCoder *)decoder { + if ((self = [super init])) { + url = [[decoder decodeObjectForKey:@"url"] retain]; + type = [[decoder decodeObjectForKey:@"type"] retain]; + length = [decoder decodeIntegerForKey:@"length"]; + } + return self; +} + +- (void)encodeWithCoder:(NSCoder *)encoder { + if (url) [encoder encodeObject:url forKey:@"url"]; + if (type) [encoder encodeObject:type forKey:@"type"]; + if (length) [encoder encodeInteger:length forKey:@"length"]; +} + +@end \ No newline at end of file diff --git a/Classes/MWFeedParser.h b/Classes/MWFeedParser.h index e174c35..0e3dcb0 100644 --- a/Classes/MWFeedParser.h +++ b/Classes/MWFeedParser.h @@ -30,6 +30,7 @@ #import #import "MWFeedInfo.h" #import "MWFeedItem.h" +#import "MWFeedItemEnclosure.h" // Debug Logging #if 0 // Set to 1 to enable debug logging diff --git a/Classes/MWFeedParser.m b/Classes/MWFeedParser.m index 16ca275..a8dd968 100644 --- a/Classes/MWFeedParser.m +++ b/Classes/MWFeedParser.m @@ -877,49 +877,42 @@ - (void)setUrl:(NSURL *)value { #pragma mark - #pragma mark Misc -// Create an enclosure NSDictionary from enclosure (or link) attributes +// Create an enclosure (MWFeedItemEnclosure) from enclosure (or link) attributes - (BOOL)createEnclosureFromAttributes:(NSDictionary *)attributes andAddToItem:(MWFeedItem *)currentItem { // Create enclosure - NSDictionary *enclosure = nil; - NSString *encURL = nil, *encType = nil; - NSNumber *encLength = nil; + MWFeedItemEnclosure *enclosure = nil; if (attributes) { switch (feedType) { case FeedTypeRSS: { // http://cyber.law.harvard.edu/rss/rss.html#ltenclosuregtSubelementOfLtitemgt // - encURL = [attributes objectForKey:@"url"]; - encType = [attributes objectForKey:@"type"]; - encLength = [NSNumber numberWithLongLong:[((NSString *)[attributes objectForKey:@"length"]) longLongValue]]; + enclosure = [[MWFeedItemEnclosure alloc] init]; + enclosure.url = (NSString *)[attributes objectForKey:@"url"]; + enclosure.type = [attributes objectForKey:@"type"]; + enclosure.length = [((NSString *)[attributes objectForKey:@"length"]) integerValue]; break; } case FeedTypeRSS1: { // http://www.xs4all.nl/~foz/mod_enclosure.html // - encURL = [attributes objectForKey:@"rdf:resource"]; - encType = [attributes objectForKey:@"enc:type"]; - encLength = [NSNumber numberWithLongLong:[((NSString *)[attributes objectForKey:@"enc:length"]) longLongValue]]; + enclosure = [[MWFeedItemEnclosure alloc] init]; + enclosure.url = (NSString *)[attributes objectForKey:@"rdf:resource"]; + enclosure.type = [attributes objectForKey:@"enc:type"]; + enclosure.length = [((NSString *)[attributes objectForKey:@"enc:length"]) integerValue]; break; } case FeedTypeAtom: { // http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rel_attribute //