Permalink
Browse files

Now parses RSS and Atom titles... not entries/items though.

  • Loading branch information...
1 parent 33316d3 commit 8c8be51c7b50096fa9c38e11ca0d88dbe0cea02c Michael Hughes committed Mar 17, 2013
Showing with 40 additions and 7 deletions.
  1. +10 −4 src/server/RSSCollector.coffee
  2. +30 −3 test/server/unit/RSSCollector_test.coffee
View
14 src/server/RSSCollector.coffee
@@ -3,7 +3,7 @@ http = require 'http'
exports.createRSSCollector = ->
- requestRSS:(connectionString,fun)->
+ requestFeed:(connectionString,fun)->
data=""
http.get connectionString, (res) ->
res.setEncoding('utf8')
@@ -15,8 +15,14 @@ exports.createRSSCollector = ->
console.log("Got error: " + e.message)
fun(e.message,null)
- parseRSS:(data,fun) ->
+ parseFeed:(data,fun) ->
parser = new xml2js.Parser({explicitArray:false})
parser.parseString data, (err,result)->
- set = result?.rss.channel
- fun(err,set)
+ if result.rss
+ fun(err,result.rss.channel)
+ else if result.feed
+ fun(err,result.feed)
+ else
+ fun("Unable to parse feed",null)
+
+
View
33 test/server/unit/RSSCollector_test.coffee
@@ -32,12 +32,39 @@ describe 'A RSS collector', ->
</channel>
</rss>
"""
- @collector.parseRSS data,(err,result)->
+ @collector.parseFeed data,(err,result)->
expect(err).to.be.null
expect(result.title,"title").to.equal("BBC News - Home")
done()
- it 'should be able to retrieve and parse some XML', (done)->
- @collector.requestRSS FakeRSS,(err,result)->
+ it 'should be able to retrieve and parse some RSS XML', (done)->
+ @collector.requestFeed FakeRSS,(err,result)->
expect(err,err).to.be.null
expect(result,"result").to.exist
+ done()
+ it 'should be able to parse some Atom XML', (done)->
+ data =
+ """
+ <?xml version="1.0" encoding="utf-8"?>
+ <feed xmlns="http://www.w3.org/2005/Atom">
+ <title>Example Feed</title>
+ <subtitle>Insert witty or insightful remark here</subtitle>
+ <link href="http://example.org/"/>
+ <updated>2003-12-13T18:30:02Z</updated>
+ <author>
+ <name>John Doe</name>
+ <email>johndoe@example.com</email>
+ </author>
+ <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
+ <entry>
+ <title>Atom-Powered Robots Run Amok</title>
+ <link href="http://example.org/2003/12/13/atom03"/>
+ <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
+ <updated>2003-12-13T18:30:02Z</updated>
+ <summary>Some text.</summary>
+ </entry>
+ </feed>
+ """
+ @collector.parseFeed data,(err,result)->
+ expect(err).to.be.null
+ expect(result.title,"title").to.equal("Example Feed")
done()

0 comments on commit 8c8be51

Please sign in to comment.