diff --git a/Muon.xcodeproj/project.pbxproj b/Muon.xcodeproj/project.pbxproj index 8cc8388..db76712 100644 --- a/Muon.xcodeproj/project.pbxproj +++ b/Muon.xcodeproj/project.pbxproj @@ -59,6 +59,10 @@ 89CAD4E01BA4A203006D79FC /* atom_large.xml in Resources */ = {isa = PBXBuildFile; fileRef = 8981316F1AFC75270090FA7F /* atom_large.xml */; }; 89D427FD1B8CFB44006CD81C /* sparkfun.rss in Resources */ = {isa = PBXBuildFile; fileRef = 89D427FC1B8CFB44006CD81C /* sparkfun.rss */; }; 89D428011B8D0143006CD81C /* sparkfun1.html in Resources */ = {isa = PBXBuildFile; fileRef = 89D428001B8D0143006CD81C /* sparkfun1.html */; }; + 89E08DD61C43751E00E3D5FC /* xkcd.atom in Resources */ = {isa = PBXBuildFile; fileRef = 89E08DD51C43751E00E3D5FC /* xkcd.atom */; }; + 89E08DD71C43758B00E3D5FC /* xkcd.atom in Resources */ = {isa = PBXBuildFile; fileRef = 89E08DD51C43751E00E3D5FC /* xkcd.atom */; }; + 89E08DD91C437B1100E3D5FC /* xkcd.rss in Resources */ = {isa = PBXBuildFile; fileRef = 89E08DD81C437B1100E3D5FC /* xkcd.rss */; }; + 89E08DDA1C437B1500E3D5FC /* xkcd.rss in Resources */ = {isa = PBXBuildFile; fileRef = 89E08DD81C437B1100E3D5FC /* xkcd.rss */; }; 89E9C20F1AF495A400620A55 /* String+Muon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89E9C20E1AF495A400620A55 /* String+Muon.swift */; }; 89E9C2111AF4987D00620A55 /* StringExtensionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89E9C2101AF4987D00620A55 /* StringExtensionSpec.swift */; }; /* End PBXBuildFile section */ @@ -140,6 +144,8 @@ 89BBC1161AF2BCA0006025AA /* Author.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Author.swift; sourceTree = ""; }; 89D427FC1B8CFB44006CD81C /* sparkfun.rss */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = sparkfun.rss; sourceTree = ""; }; 89D428001B8D0143006CD81C /* sparkfun1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = sparkfun1.html; sourceTree = ""; }; + 89E08DD51C43751E00E3D5FC /* xkcd.atom */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = xkcd.atom; sourceTree = ""; }; + 89E08DD81C437B1100E3D5FC /* xkcd.rss */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = xkcd.rss; sourceTree = ""; }; 89E9C20E1AF495A400620A55 /* String+Muon.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Muon.swift"; sourceTree = ""; }; 89E9C2101AF4987D00620A55 /* StringExtensionSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtensionSpec.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -255,6 +261,8 @@ 8967016D1AF1749300BCD0DD /* researchkit.rss */, 89D427FC1B8CFB44006CD81C /* sparkfun.rss */, 89D428001B8D0143006CD81C /* sparkfun1.html */, + 89E08DD51C43751E00E3D5FC /* xkcd.atom */, + 89E08DD81C437B1100E3D5FC /* xkcd.rss */, 89BBC10C1AF1EB2D006025AA /* rss091.rss */, 89BBC10E1AF1EB4E006025AA /* rss092.rss */, 89BBC1121AF1EC06006025AA /* rss100.rss */, @@ -432,9 +440,11 @@ files = ( 89CAD4E01BA4A203006D79FC /* atom_large.xml in Resources */, 89CAD4DA1BA4A203006D79FC /* rss092.rss in Resources */, + 89E08DD71C43758B00E3D5FC /* xkcd.atom in Resources */, 89CAD4D71BA4A203006D79FC /* sparkfun.rss in Resources */, 89CAD4DF1BA4A203006D79FC /* rss2_large.rss in Resources */, 89CAD4DC1BA4A203006D79FC /* rss200.rss in Resources */, + 89E08DDA1C437B1500E3D5FC /* xkcd.rss in Resources */, 89CAD4D81BA4A203006D79FC /* sparkfun1.html in Resources */, 89CAD4DD1BA4A203006D79FC /* atom100.xml in Resources */, 89CAD4DB1BA4A203006D79FC /* rss100.rss in Resources */, @@ -457,9 +467,11 @@ files = ( 89BBC1131AF1EC06006025AA /* rss100.rss in Resources */, 89BBC10D1AF1EB2D006025AA /* rss091.rss in Resources */, + 89E08DD61C43751E00E3D5FC /* xkcd.atom in Resources */, 89BBC10F1AF1EB4E006025AA /* rss092.rss in Resources */, 89BBC1111AF1EB70006025AA /* rss200.rss in Resources */, 89D427FD1B8CFB44006CD81C /* sparkfun.rss in Resources */, + 89E08DD91C437B1100E3D5FC /* xkcd.rss in Resources */, 898131741AFC75530090FA7F /* rss2_large.rss in Resources */, 898131701AFC75270090FA7F /* atom_large.xml in Resources */, 8967016E1AF1749300BCD0DD /* researchkit.rss in Resources */, diff --git a/Muon/FeedParser.swift b/Muon/FeedParser.swift index d69456f..c640d64 100644 --- a/Muon/FeedParser.swift +++ b/Muon/FeedParser.swift @@ -332,7 +332,7 @@ public class FeedParser: NSOperation, NSXMLParserDelegate { articleHelper.link += str case "guid", "id": articleHelper.guid += str - case "description": + case "description", "summary": articleHelper.description += str case "pubdate", "published": articleHelper.published += str @@ -394,7 +394,7 @@ public class FeedParser: NSOperation, NSXMLParserDelegate { } } else { if let href = attributeDict["href"] as? String where currentElement == "link" { - if attributeDict["rel"] == nil || attributeDict["rel"] as? String == "self" { + if attributeDict["rel"] == nil || attributeDict["rel"] as? String == "self" || attributeDict["rel"] as? String == "alternate" { feedHelper.link = href } } diff --git a/MuonTests/IntegrationSpec.swift b/MuonTests/IntegrationSpec.swift index 23f647c..08c0355 100644 --- a/MuonTests/IntegrationSpec.swift +++ b/MuonTests/IntegrationSpec.swift @@ -87,6 +87,67 @@ class IntegrationSpec: QuickSpec { } } + describe("xkcd (atom)") { + beforeEach { + parser = parserWithContentsOfFile("xkcd.atom") + } + + it("should parse the feed") { + expect(feed).toNot(beNil()) + if let feed = feed { + expect(feed.title).to(equal("xkcd.com")) + expect(feed.link).to(equal(NSURL(string: "http://xkcd.com/")!)) + expect(feed.lastUpdated).to(equal("2016-01-11T00:00:00Z".RFC3339Date())) + } + } + + it("should parse the feed's items") { + expect(feed?.articles.count).to(equal(4)) + if let article = feed?.articles.first { + expect(article.title).to(equal("Magnus")) + expect(article.link).to(equal(NSURL(string: "http://xkcd.com/1628/"))) + expect(article.guid).to(equal("http://xkcd.com/1628/")) + expect(article.description).to(equal("\"In")) + expect(article.content).to(beNil()) + let updated = "2016-01-11T00:00:00Z".RFC3339Date() + expect(article.published).to(beNil()) + expect(article.updated).to(equal(updated)) + expect(article.enclosures.count).to(equal(0)) + } + } + } + + describe("xkcd (rss)") { + beforeEach { + parser = parserWithContentsOfFile("xkcd.rss") + } + + it("should parse the feed") { + expect(feed).toNot(beNil()) + if let feed = feed { + expect(feed.title).to(equal("xkcd.com")) + expect(feed.link).to(equal(NSURL(string: "http://xkcd.com/")!)) + expect(feed.description).to(equal("xkcd.com: A webcomic of romance and math humor.")) + expect(feed.language).to(equal(NSLocale(localeIdentifier: "en"))) + } + } + + it("should parse the feed's items") { + expect(feed?.articles.count).to(equal(4)) + if let article = feed?.articles.first { + expect(article.title).to(equal("Magnus")) + expect(article.link).to(equal(NSURL(string: "http://xkcd.com/1628/"))) + expect(article.guid).to(equal("http://xkcd.com/1628/")) + expect(article.description).to(equal("\"In")) + expect(article.content).to(beNil()) + let updated = "Mon, 11 Jan 2016 05:00:00 -0000".RFC822Date() + expect(article.published).to(equal(updated)) + expect(article.updated).to(beNil()) + expect(article.enclosures.count).to(equal(0)) + } + } + } + describe("RSS 0.91") { beforeEach { parser = parserWithContentsOfFile("rss091.rss") diff --git a/MuonTests/xkcd.atom b/MuonTests/xkcd.atom new file mode 100644 index 0000000..ed3d302 --- /dev/null +++ b/MuonTests/xkcd.atom @@ -0,0 +1,35 @@ + + +xkcd.com + +http://xkcd.com/ +2016-01-11T00:00:00Z + + Magnus + + 2016-01-11T00:00:00Z + http://xkcd.com/1628/ + <img src="http://imgs.xkcd.com/comics/magnus.png" title="In the latest round, 9-year-old Muhammad Ali beat 10-year-old JFK at air hockey, while Secretariat lost the hot-dog-eating crown to 12-year-old Ken Jennings. Meanwhile, in a huge upset, 11-year-old Martha Stewart knocked out the adult Ronda Rousey." alt="In the latest round, 9-year-old Muhammad Ali beat 10-year-old JFK at air hockey, while Secretariat lost the hot-dog-eating crown to 12-year-old Ken Jennings. Meanwhile, in a huge upset, 11-year-old Martha Stewart knocked out the adult Ronda Rousey." /> + + + Woosh + + 2016-01-08T00:00:00Z + http://xkcd.com/1627/ + <img src="http://imgs.xkcd.com/comics/woosh.png" title="It also occasionally replies with 'Comment of the year', 'Are you for real', and 'I'm taking a screenshot so I can remember this moment forever'." alt="It also occasionally replies with 'Comment of the year', 'Are you for real', and 'I'm taking a screenshot so I can remember this moment forever'." /> + + + Judgment Day + + 2016-01-06T00:00:00Z + http://xkcd.com/1626/ + <img src="http://imgs.xkcd.com/comics/judgment_day.png" title="It took a lot of booster rockets, but luckily Amazon had recently built thousands of them to bring Amazon Prime same-day delivery to the Moon colony." alt="It took a lot of booster rockets, but luckily Amazon had recently built thousands of them to bring Amazon Prime same-day delivery to the Moon colony." /> + + + Substitutions 2 + + 2016-01-04T00:00:00Z + http://xkcd.com/1625/ + <img src="http://imgs.xkcd.com/comics/substitutions_2.png" title="Within a few minutes, our roads will be full of uncontrollably-swerving cars and our skies full of Amazon delivery dogs." alt="Within a few minutes, our roads will be full of uncontrollably-swerving cars and our skies full of Amazon delivery dogs." /> + + \ No newline at end of file diff --git a/MuonTests/xkcd.rss b/MuonTests/xkcd.rss new file mode 100644 index 0000000..73427f0 --- /dev/null +++ b/MuonTests/xkcd.rss @@ -0,0 +1,37 @@ + + + + xkcd.com + http://xkcd.com/ + xkcd.com: A webcomic of romance and math humor. + en + + Magnus + http://xkcd.com/1628/ + <img src="http://imgs.xkcd.com/comics/magnus.png" title="In the latest round, 9-year-old Muhammad Ali beat 10-year-old JFK at air hockey, while Secretariat lost the hot-dog-eating crown to 12-year-old Ken Jennings. Meanwhile, in a huge upset, 11-year-old Martha Stewart knocked out the adult Ronda Rousey." alt="In the latest round, 9-year-old Muhammad Ali beat 10-year-old JFK at air hockey, while Secretariat lost the hot-dog-eating crown to 12-year-old Ken Jennings. Meanwhile, in a huge upset, 11-year-old Martha Stewart knocked out the adult Ronda Rousey." /> + Mon, 11 Jan 2016 05:00:00 -0000 + http://xkcd.com/1628/ + + + Woosh + http://xkcd.com/1627/ + <img src="http://imgs.xkcd.com/comics/woosh.png" title="It also occasionally replies with 'Comment of the year', 'Are you for real', and 'I'm taking a screenshot so I can remember this moment forever'." alt="It also occasionally replies with 'Comment of the year', 'Are you for real', and 'I'm taking a screenshot so I can remember this moment forever'." /> + Fri, 08 Jan 2016 05:00:00 -0000 + http://xkcd.com/1627/ + + + Judgment Day + http://xkcd.com/1626/ + <img src="http://imgs.xkcd.com/comics/judgment_day.png" title="It took a lot of booster rockets, but luckily Amazon had recently built thousands of them to bring Amazon Prime same-day delivery to the Moon colony." alt="It took a lot of booster rockets, but luckily Amazon had recently built thousands of them to bring Amazon Prime same-day delivery to the Moon colony." /> + Wed, 06 Jan 2016 05:00:00 -0000 + http://xkcd.com/1626/ + + + Substitutions 2 + http://xkcd.com/1625/ + <img src="http://imgs.xkcd.com/comics/substitutions_2.png" title="Within a few minutes, our roads will be full of uncontrollably-swerving cars and our skies full of Amazon delivery dogs." alt="Within a few minutes, our roads will be full of uncontrollably-swerving cars and our skies full of Amazon delivery dogs." /> + Mon, 04 Jan 2016 05:00:00 -0000 + http://xkcd.com/1625/ + + + \ No newline at end of file