Skip to content

Commit

Permalink
creating in memory XML for the sparkle framework code
Browse files Browse the repository at this point in the history
  • Loading branch information
yene committed Sep 10, 2015
1 parent 6792cc0 commit 489d6c7
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions Sparkle/SUAppcast.m
Expand Up @@ -98,13 +98,55 @@ - (void)downloadDidFinish:(NSURLDownload *)__unused aDownload
BOOL failed = NO;
NSArray *xmlItems = nil;
NSMutableArray *appcastItems = [NSMutableArray array];
NSDictionary *json;

if (self.downloadFilename)
{
// convert json to xml
NSData *fileContent = [NSData dataWithContentsOfFile:self.downloadFilename];
json = [NSJSONSerialization JSONObjectWithData:fileContent options:0 error:&error];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:fileContent options:0 error:&error];

// convert ISO 8601 to RFC1123
NSDate *dateISO = [NSDate dateWithNaturalLanguageString:json[@"published_at"]];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EE, d LLLL yyyy HH:mm:ss Z"];
NSString *dateRFC = [dateFormat stringFromDate:dateISO];

NSDictionary *download = json[@"assets"][0];
NSString *version = [json[@"tag_name"] stringByReplacingOccurrencesOfString:@"v" withString:@""];

NSString *xmlContent = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<rss version=\"2.0\" xmlns:sparkle=\"http://www.andymatuschak.org/xml-namespaces/sparkle\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"
"<channel>\n"
"<title>Github Sparkle</title>\n"
"<link>http://sparkle-project.org/files/sparkletestcast.xml</link>\n"
"<description>Most recent changes with links to updates.</description>\n"
"<language>en</language>\n"
"<item>\n"
"<title>%@</title>\n"
"<description>\n"
"<![CDATA[\n"
"%@"
"]]>"
"</description>\n"
"<pubDate>%@</pubDate>\n"
"<enclosure url=\"%@\" sparkle:version=\"%@\" length=\"%@\" type=\"application/octet-stream\" />\n"
"</item>\n"

"</channel>\n"
"</rss>\n",
json[@"name"],
json[@"body"],
dateRFC,
download[@"browser_download_url"],
version,
download[@"size"]
];


NSUInteger options = 0;
options = NSXMLNodeOptionsNone;
document = [[NSXMLDocument alloc] initWithXMLString:xmlContent options:options error:&error];

[[NSFileManager defaultManager] removeItemAtPath:self.downloadFilename error:nil];
self.downloadFilename = nil;
}
Expand All @@ -113,10 +155,18 @@ - (void)downloadDidFinish:(NSURLDownload *)__unused aDownload
failed = YES;
}

if (nil == json)
if (nil == document)
{
failed = YES;
}
else
{
xmlItems = [document nodesForXPath:@"/rss/channel/item" error:&error];
if (nil == xmlItems)
{
failed = YES;
}
}

if (failed == NO)
{
Expand Down

0 comments on commit 489d6c7

Please sign in to comment.