diff --git a/lib/parser/atom.ex b/lib/parser/atom.ex
index f9b72ab..40bae42 100644
--- a/lib/parser/atom.ex
+++ b/lib/parser/atom.ex
@@ -12,7 +12,7 @@ defmodule FeedParser.Parser.Atom do
def accepts(data, content_type) do
case content_type do
"application/atom+xml" ->
- true
+ {true, XML.parse(data)}
_ when content_type in ["text/xml", "application/xml"] ->
doc = XML.parse(data)
diff --git a/test/feed_parser_test.exs b/test/feed_parser_test.exs
index 37e34c7..eebb4d3 100644
--- a/test/feed_parser_test.exs
+++ b/test/feed_parser_test.exs
@@ -1,8 +1,4 @@
defmodule FeedParserTest do
use ExUnit.Case
doctest FeedParser
-
- test "greets the world" do
- assert FeedParser.hello() == :world
- end
end
diff --git a/test/fixtures/atom/feed.xml b/test/fixtures/atom/feed.xml
new file mode 100644
index 0000000..18ab87a
--- /dev/null
+++ b/test/fixtures/atom/feed.xml
@@ -0,0 +1,20 @@
+
+
+
+ Example Feed
+
+ 2003-12-13T18:30:02Z
+
+ John Doe
+
+ urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6
+
+
+ Atom-Powered Robots Run Amok
+
+ urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a
+ 2003-12-13T18:30:02Z
+ Some text.
+
+
+
diff --git a/test/fixtures/jsonfeed/feed.json b/test/fixtures/jsonfeed/feed.json
new file mode 100644
index 0000000..b895db8
--- /dev/null
+++ b/test/fixtures/jsonfeed/feed.json
@@ -0,0 +1,18 @@
+{
+ "version": "https://jsonfeed.org/version/1",
+ "title": "My Example Feed",
+ "home_page_url": "https://example.org/",
+ "feed_url": "https://example.org/feed.json",
+ "items": [
+ {
+ "id": "2",
+ "content_text": "This is a second item.",
+ "url": "https://example.org/second-item"
+ },
+ {
+ "id": "1",
+ "content_html": "
Hello, world!
",
+ "url": "https://example.org/initial-post"
+ }
+ ]
+}
diff --git a/test/fixtures/rss2/feed.xml b/test/fixtures/rss2/feed.xml
new file mode 100644
index 0000000..37c6144
--- /dev/null
+++ b/test/fixtures/rss2/feed.xml
@@ -0,0 +1,22 @@
+
+
+
+ Liftoff News
+ http://liftoff.msfc.nasa.gov/
+ Liftoff to Space Exploration.
+ en-us
+ Tue, 10 Jun 2003 04:00:00 GMT
+ Tue, 10 Jun 2003 09:41:01 GMT
+ http://blogs.law.harvard.edu/tech/rss
+ Weblog Editor 2.0
+ editor@example.com
+ webmaster@example.com
+ -
+ Star City
+ http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp
+ How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's <a href="http://howe.iki.rssi.ru/GCTC/gctc_e.htm">Star City</a>.
+ Tue, 03 Jun 2003 09:39:21 UTC
+ http://liftoff.msfc.nasa.gov/2003/06/03.html#item573
+
+
+
diff --git a/test/fixtures/rssinjson/feed.json b/test/fixtures/rssinjson/feed.json
new file mode 100644
index 0000000..7d0e8e6
--- /dev/null
+++ b/test/fixtures/rssinjson/feed.json
@@ -0,0 +1,58 @@
+{
+ "rss": {
+ "version": "2.0",
+ "xmlns:source": "http://source.scripting.com/",
+ "channel": {
+ "title": "Scripting News",
+ "link": "http://scripting.com/",
+ "description": "Scripting News, the weblog started in 1994 that bootstrapped the blogging revolution. 🚀",
+ "pubDate": "Sat, 31 Aug 2019 18:04:35 GMT",
+ "lastBuildDate": "Sat, 31 Aug 2019 22:49:49 GMT",
+ "language": "en-us",
+ "copyright": "© 1994-2019 Dave Winer.",
+ "generator": "oldSchool v0.5.29",
+ "docs": "https://github.com/scripting/Scripting-News/blob/master/rss-in-json/README.md",
+ "source:localTime": "Sat, August 31, 2019 6:49 PM EDT",
+ "cloud": {
+ "domain": "rpc.rsscloud.io",
+ "port": 5337,
+ "path": "/pleaseNotify",
+ "registerProcedure": "",
+ "protocol": "http-post"
+ },
+ "source:account": [
+ {
+ "service": "twitter",
+ "#value": "davewiner"
+ },
+ {
+ "service": "facebook",
+ "#value": "dave.winer.12"
+ },
+ {
+ "service": "github",
+ "#value": "scripting"
+ },
+ {
+ "service": "linkedin",
+ "#value": "scripting"
+ }
+ ],
+ "item": [
+ {
+ "link": "http://scripting.com/2019/08/31.html#a151142",
+ "description": "I've been reading a lot about the MIT Media Lab lately. I read that founder of the lab, Nicholas Negroponte, made a deal with Louis and Jane, the founders of Wired, he bought 10 percent of the magazine for $75K and got a column on the inside back cover, which was prime real estate. This got me thinking. The Media Lab and Wired were made for each other. I loved Wired, but I also was aware that they went for gee-whiz tech over substantial tech more than I wished they would. The Media Lab produced lots of buzzworthy demos that never turned into usable tech. What I really wanted? A Wired/Media Lab that only covered open source tech. It was the style of Wired that attracted me, at the time all tech pubs were made for geeks who were suspicious of anything that looked too slick. I want beautiful artistic simplicity, the kind of look that Wired was so good at, applied to practical almost mundane tech. The developers who love all that stuff are the people I want to work with. Stuff that works and that can change the world right now, looking good, not popcorn-like gee-whiz tech that has limited depth or substance. ",
+ "pubDate": "Sat, 31 Aug 2019 15:11:42 UTC",
+ "guid": "http://scripting.com/2019/08/31.html#a151142",
+ "source:outline": {
+ "text": "I've been reading a lot about the MIT Media Lab lately. I read that founder of the lab, Nicholas Negroponte, made a deal with Louis and Jane, the founders of Wired, he bought 10 percent of the magazine for $75K and got a column on the inside back cover, which was prime real estate. This got me thinking. The Media Lab and Wired were made for each other. I loved Wired, but I also was aware that they went for gee-whiz tech over substantial tech more than I wished they would. The Media Lab produced lots of buzzworthy demos that never turned into usable tech. What I really wanted? A Wired/Media Lab that only covered open source tech. It was the style of Wired that attracted me, at the time all tech pubs were made for geeks who were suspicious of anything that looked too slick. I want beautiful artistic simplicity, the kind of look that Wired was so good at, applied to practical almost mundane tech. The developers who love all that stuff are the people I want to work with. Stuff that works and that can change the world right now, looking good, not popcorn-like gee-whiz tech that has limited depth or substance. ",
+ "created": "Sat, 31 Aug 2019 15:11:42 UTC",
+ "type": "outline",
+ "image": "http://scripting.com/images/2019/08/31/thisIsNextYear.png",
+ "permalink": "http://scripting.com/2019/08/31.html#a151142"
+ }
+ }
+ ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/parser/atom_test.exs b/test/parser/atom_test.exs
new file mode 100644
index 0000000..2ffa451
--- /dev/null
+++ b/test/parser/atom_test.exs
@@ -0,0 +1,25 @@
+defmodule FeedParser.Parser.AtomTest do
+ use ExUnit.Case
+ alias FeedParser.Parser.Atom
+ doctest Atom
+
+ test "matches atom feed" do
+ data = File.read!("test/fixtures/atom/feed.xml")
+ assert {true, _} = Atom.accepts(data, "application/atom+xml")
+ assert {true, _} = Atom.accepts(data, "application/xml")
+ end
+
+ test "parses atom feed" do
+ data = File.read!("test/fixtures/atom/feed.xml")
+ {true, parsed_data} = Atom.accepts(data, "application/atom+xml")
+ assert {:ok, %FeedParser.Feed{} = feed} = Atom.parse_feed(parsed_data)
+ assert feed.site_url == "http://example.org/"
+ assert feed.title == "Example Feed"
+ assert [%FeedParser.Item{} = item] = feed.items
+ assert item.guid == "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"
+ assert item.title == "Atom-Powered Robots Run Amok"
+ assert item.url == "http://example.org/2003/12/13/atom03"
+ assert item.date == ~U[2003-12-13 18:30:02Z]
+ assert item.content == "Some text."
+ end
+end
diff --git a/test/parser/jsonfeed_test.exs b/test/parser/jsonfeed_test.exs
new file mode 100644
index 0000000..b4401b8
--- /dev/null
+++ b/test/parser/jsonfeed_test.exs
@@ -0,0 +1,26 @@
+defmodule FeedParser.Parser.JSONFeedTest do
+ use ExUnit.Case
+ alias FeedParser.Parser.JSONFeed
+ doctest JSONFeed
+
+ test "matches json feed" do
+ data = File.read!("test/fixtures/jsonfeed/feed.json")
+ assert {true, _} = JSONFeed.accepts(data, "application/json")
+ end
+
+ test "parses json feed" do
+ data = File.read!("test/fixtures/jsonfeed/feed.json")
+ {true, parsed_data} = JSONFeed.accepts(data, "application/json")
+ assert {:ok, %FeedParser.Feed{} = feed} = JSONFeed.parse_feed(parsed_data)
+ assert feed.title == "My Example Feed"
+ assert feed.site_url == "https://example.org/"
+ IO.inspect(feed.items)
+ assert [%FeedParser.Item{} = item2, %FeedParser.Item{} = item1] = feed.items
+ assert item2.guid == "2"
+ assert item2.content == "This is a second item."
+ assert item2.url == "https://example.org/second-item"
+ assert item1.guid == "1"
+ assert item1.content == "Hello, world!
"
+ assert item1.url == "https://example.org/initial-post"
+ end
+end
diff --git a/test/parser/rss2_test.exs b/test/parser/rss2_test.exs
new file mode 100644
index 0000000..61035d7
--- /dev/null
+++ b/test/parser/rss2_test.exs
@@ -0,0 +1,28 @@
+defmodule FeedParser.Parser.RSS2Test do
+ use ExUnit.Case
+ alias FeedParser.Parser.RSS2
+ doctest RSS2
+
+ test "matches rss2 feed" do
+ data = File.read!("test/fixtures/rss2/feed.xml")
+ assert {true, _} = RSS2.accepts(data, "application/rss+xml")
+ assert {true, _} = RSS2.accepts(data, "application/xml")
+ end
+
+ test "parses rss2 feed" do
+ data = File.read!("test/fixtures/rss2/feed.xml")
+ {true, parsed_data} = RSS2.accepts(data, "application/rss+xml")
+ assert {:ok, %FeedParser.Feed{} = feed} = RSS2.parse_feed(parsed_data)
+ assert feed.title == "Liftoff News"
+ assert feed.site_url == "http://liftoff.msfc.nasa.gov/"
+ assert [%FeedParser.Item{} = item] = feed.items
+ assert item.title == "Star City"
+ assert item.url == "http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp"
+
+ assert item.content ==
+ "How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's Star City."
+
+ assert item.date == ~U[2003-06-03 09:39:21Z]
+ assert item.guid == "http://liftoff.msfc.nasa.gov/2003/06/03.html#item573"
+ end
+end
diff --git a/test/parser/rssinjson_test.exs b/test/parser/rssinjson_test.exs
new file mode 100644
index 0000000..d69db97
--- /dev/null
+++ b/test/parser/rssinjson_test.exs
@@ -0,0 +1,22 @@
+defmodule FeedParser.Parser.RSSInJSONTest do
+ use ExUnit.Case
+ alias FeedParser.Parser.RSSInJSON
+ doctest RSSInJSON
+
+ test "matches rss-in-json feed" do
+ data = File.read!("test/fixtures/rssinjson/feed.json")
+ assert {true, _} = RSSInJSON.accepts(data, "application/json")
+ end
+
+ test "parses rss-in-json feed" do
+ data = File.read!("test/fixtures/rssinjson/feed.json")
+ {true, parsed_data} = RSSInJSON.accepts(data, "application/json")
+ assert {:ok, %FeedParser.Feed{} = feed} = RSSInJSON.parse_feed(parsed_data)
+ assert feed.title == "Scripting News"
+ assert feed.site_url == "http://scripting.com/"
+ assert [%FeedParser.Item{} = item] = feed.items
+ assert item.url == "http://scripting.com/2019/08/31.html#a151142"
+ assert item.guid == "http://scripting.com/2019/08/31.html#a151142"
+ assert item.date == ~U[2019-08-31 15:11:42Z]
+ end
+end