Browse files

Adding tags to entries

  • Loading branch information...
1 parent 35d5b14 commit dc54c6e25843d6203f70db26e8aad083504d8f18 Michael Hughes committed Mar 20, 2013
Showing with 27 additions and 6 deletions.
  1. +12 −2 src/server/FeedCollector.coffee
  2. +15 −4 test/server/unit/FeedCollector_test.coffee
View
14 src/server/FeedCollector.coffee
@@ -4,6 +4,15 @@ _ = require 'underscore'
exports.createFeedCollector = ->
+ tags = []
+
+ collectFeed:(feed,fun)->
+ tags = feed.tags
+ @requestFeed feed.URL,(err,data)=>
+ if err then fun(err,null)
+ else
+ @parseFeed data, fun
+
requestFeed:(URL,fun)->
data=""
http.get URL, (res) ->
@@ -34,9 +43,10 @@ exports.createFeedCollector = ->
parseEntry:(e)->
title: e.title
- link: e.link.$.href
+ link: if e.link.$ then e.link.$.href else e.link
+ tags: tags
parseRSS:(data)->
title: data.title
- entry: _.flatten([data.item])
+ entry: @parseEntry(e) for e in _.flatten([data.item])
View
19 test/server/unit/FeedCollector_test.coffee
@@ -1,7 +1,8 @@
collector = require '../../../src/server/FeedCollector.coffee'
+feed = require '../../../src/server/Feed.coffee'
expect = (require 'chai').expect
-FakeRSS = "http://localhost:7777/rss.xml"
+fakeRSS = "http://localhost:7777/rss.xml"
describe 'A Feed collector', ->
beforeEach () ->
@@ -40,7 +41,7 @@ describe 'A Feed collector', ->
done()
it 'should be able to retrieve and parse some RSS XML', (done)->
- @collector.requestFeed FakeRSS,(err,result)->
+ @collector.requestFeed fakeRSS,(err,result)->
expect(err,err).to.be.null
expect(result,"result").to.exist
done()
@@ -82,5 +83,15 @@ describe 'A Feed collector', ->
}
expect(@collector.parseEntry entry).to.eql {
title:"abc"
- link:"http://example.org/2003/12/13/atom03"
- }
+ link:"http://example.org/2003/12/13/atom03",
+ tags:[]
+ }
+
+ it 'should be able to retrieve a feed when provided with a Feed object', (done)->
+ fakeFeed = feed.createFeed(fakeRSS,["News"])
+ @collector.collectFeed fakeFeed,(err,result)->
+ expect(err).to.be.null
+ expect(result.title).to.equal "BBC News - Home"
+ expect(result.entry[0].title).to.equal "Cameron halts press regulation talks"
+ expect(result.entry[0].tags).to.eql ["News"]
+ done()

0 comments on commit dc54c6e

Please sign in to comment.