Skip to content

Commit

Permalink
Adding tags to entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Hughes authored and Michael Hughes committed Mar 20, 2013
1 parent 35d5b14 commit dc54c6e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/server/FeedCollector.coffee
Expand Up @@ -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) ->
Expand Down Expand Up @@ -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])

19 changes: 15 additions & 4 deletions 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 () ->
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.