Use string constants for RSS element and attribute names.

This commit is contained in:
Jake Petroules committed 2014-08-27 20:53:27 -04:00
1 parent f72bd52e87
commit 8d74807b23
4 files changed
+31 -15

No files matched your search

+4 -4
View File
@@ -145,14 +145,14 @@
for (NSString *name in nodesDict)
{
node = [self bestNodeInNodes:nodesDict[name]];
if ([name isEqualToString:@"enclosure"])
if ([name isEqualToString:SURSSElementEnclosure])
{
// enclosure is flattened as a separate dictionary for some reason
NSDictionary *encDict = [(NSXMLElement *)node attributesAsDictionary];
dict[@"enclosure"] = encDict;
dict[name] = encDict;
}
else if ([name isEqualToString:@"pubDate"])
else if ([name isEqualToString:SURSSElementPubDate])
{
// pubDate is expected to be an NSDate by SUAppcastItem, but the RSS class was returning an NSString
NSDate *date = [NSDate dateWithNaturalLanguageString:[node stringValue]];
@@ -164,7 +164,7 @@
NSMutableArray *deltas = [NSMutableArray array];
NSEnumerator *childEnum = [[node children] objectEnumerator];
for (NSXMLNode *child in childEnum) {
if ([[child name] isEqualToString:@"enclosure"])
if ([[child name] isEqualToString:SURSSElementEnclosure])
[deltas addObject:[(NSXMLElement *)child attributesAsDictionary]];
}
dict[name] = deltas;
+11 -11
View File
@@ -47,7 +47,7 @@
- (BOOL)isDeltaUpdate
{
return self.propertiesDictionary[@"enclosure"][SUAppcastAttributeDeltaFrom] != nil;
return self.propertiesDictionary[SURSSElementEnclosure][SUAppcastAttributeDeltaFrom] != nil;
}
- (BOOL)isCriticalUpdate
@@ -64,7 +64,7 @@
{
self = [super init];
if (self) {
id enclosure = dict[@"enclosure"];
id enclosure = dict[SURSSElementEnclosure];
// Try to find a version string.
// Finding the new version number from the RSS feed is a little bit hacky. There are two ways:
@@ -80,11 +80,11 @@
}
if (newVersion == nil) // no sparkle:version attribute anywhere?
{
SULog(@"warning: <enclosure> for URL '%@' is missing sparkle:version attribute. Version comparison may be unreliable. Please always specify sparkle:version", enclosure[@"url"]);
SULog(@"warning: <%@> for URL '%@' is missing %@ attribute. Version comparison may be unreliable. Please always specify %@", SURSSElementEnclosure, enclosure[SURSSAttributeURL], SUAppcastAttributeVersion, SUAppcastAttributeVersion);
// Separate the url by underscores and take the last component, as that'll be closest to the end,
// then we remove the extension. Hopefully, this will be the version.
NSArray *fileComponents = [enclosure[@"url"] componentsSeparatedByString:@"_"];
NSArray *fileComponents = [enclosure[SURSSAttributeURL] componentsSeparatedByString:@"_"];
if ([fileComponents count] > 1) {
newVersion = [[fileComponents lastObject] stringByDeletingPathExtension];
}
@@ -92,17 +92,17 @@
if (!newVersion) {
if (error) {
*error = @"Feed item lacks sparkle:version attribute, and version couldn't be deduced from file name (would have used last component of a file name like AppName_1.3.4.zip)";
*error = [NSString stringWithFormat:@"Feed item lacks %@ attribute, and version couldn't be deduced from file name (would have used last component of a file name like AppName_1.3.4.zip)", SUAppcastAttributeVersion];
}
return nil;
}
propertiesDictionary = [[NSMutableDictionary alloc] initWithDictionary:dict];
self.title = dict[@"title"];
self.date = dict[@"pubDate"];
self.itemDescription = dict[@"description"];
self.title = dict[SURSSElementTitle];
self.date = dict[SURSSElementPubDate];
self.itemDescription = dict[SURSSElementDescription];
NSString *theInfoURL = dict[@"link"];
NSString *theInfoURL = dict[SURSSElementLink];
if (theInfoURL) {
if (![theInfoURL isKindOfClass:[NSString class]]) {
SULog(@"SUAppcastItem -initWithDictionary: Info URL is not of valid type.");
@@ -120,7 +120,7 @@
return nil;
}
NSString *enclosureURLString = enclosure[@"url"];
NSString *enclosureURLString = enclosure[SURSSAttributeURL];
if (!enclosureURLString && !theInfoURL) {
if (error) {
*error = @"Feed item's enclosure lacks URL";
@@ -166,7 +166,7 @@
for (NSDictionary *deltaDictionary in deltaDictionaries) {
NSMutableDictionary *fakeAppCastDict = [dict mutableCopy];
[fakeAppCastDict removeObjectForKey:SUAppcastElementDeltas];
fakeAppCastDict[@"enclosure"] = deltaDictionary;
fakeAppCastDict[SURSSElementEnclosure] = deltaDictionary;
SUAppcastItem *deltaItem = [[[self class] alloc] initWithDictionary:fakeAppCastDict];
deltas[deltaDictionary[SUAppcastAttributeDeltaFrom]] = deltaItem;
+8
View File
@@ -71,6 +71,14 @@ extern NSString *const SUAppcastElementMaximumSystemVersion;
extern NSString *const SUAppcastElementReleaseNotesLink;
extern NSString *const SUAppcastElementTags;
extern NSString *const SURSSAttributeURL;
extern NSString *const SURSSElementDescription;
extern NSString *const SURSSElementEnclosure;
extern NSString *const SURSSElementLink;
extern NSString *const SURSSElementPubDate;
extern NSString *const SURSSElementTitle;
// -----------------------------------------------------------------------------
// Errors:
// -----------------------------------------------------------------------------
+8
View File
@@ -63,3 +63,11 @@ NSString *const SUAppcastElementMinimumSystemVersion = @"sparkle:minimumSystemVe
NSString *const SUAppcastElementMaximumSystemVersion = @"sparkle:maximumSystemVersion";
NSString *const SUAppcastElementReleaseNotesLink = @"sparkle:releaseNotesLink";
NSString *const SUAppcastElementTags = @"sparkle:tags";
NSString *const SURSSAttributeURL = @"url";
NSString *const SURSSElementDescription = @"description";
NSString *const SURSSElementEnclosure = @"enclosure";
NSString *const SURSSElementLink = @"link";
NSString *const SURSSElementPubDate = @"pubDate";
NSString *const SURSSElementTitle = @"title";