Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding tags to entries

  • Loading branch information...
commit dc54c6e25843d6203f70db26e8aad083504d8f18 1 parent 35d5b14
Michael Hughes authored
14 src/server/FeedCollector.coffee
@@ -4,6 +4,15 @@ _ = require 'underscore'
4 4
5 5 exports.createFeedCollector = ->
6 6
  7 + tags = []
  8 +
  9 + collectFeed:(feed,fun)->
  10 + tags = feed.tags
  11 + @requestFeed feed.URL,(err,data)=>
  12 + if err then fun(err,null)
  13 + else
  14 + @parseFeed data, fun
  15 +
7 16 requestFeed:(URL,fun)->
8 17 data=""
9 18 http.get URL, (res) ->
@@ -34,9 +43,10 @@ exports.createFeedCollector = ->
34 43
35 44 parseEntry:(e)->
36 45 title: e.title
37   - link: e.link.$.href
  46 + link: if e.link.$ then e.link.$.href else e.link
  47 + tags: tags
38 48
39 49 parseRSS:(data)->
40 50 title: data.title
41   - entry: _.flatten([data.item])
  51 + entry: @parseEntry(e) for e in _.flatten([data.item])
42 52
19 test/server/unit/FeedCollector_test.coffee
... ... @@ -1,7 +1,8 @@
1 1 collector = require '../../../src/server/FeedCollector.coffee'
  2 +feed = require '../../../src/server/Feed.coffee'
2 3 expect = (require 'chai').expect
3 4
4   -FakeRSS = "http://localhost:7777/rss.xml"
  5 +fakeRSS = "http://localhost:7777/rss.xml"
5 6
6 7 describe 'A Feed collector', ->
7 8 beforeEach () ->
@@ -40,7 +41,7 @@ describe 'A Feed collector', ->
40 41 done()
41 42
42 43 it 'should be able to retrieve and parse some RSS XML', (done)->
43   - @collector.requestFeed FakeRSS,(err,result)->
  44 + @collector.requestFeed fakeRSS,(err,result)->
44 45 expect(err,err).to.be.null
45 46 expect(result,"result").to.exist
46 47 done()
@@ -82,5 +83,15 @@ describe 'A Feed collector', ->
82 83 }
83 84 expect(@collector.parseEntry entry).to.eql {
84 85 title:"abc"
85   - link:"http://example.org/2003/12/13/atom03"
86   - }
  86 + link:"http://example.org/2003/12/13/atom03",
  87 + tags:[]
  88 + }
  89 +
  90 + it 'should be able to retrieve a feed when provided with a Feed object', (done)->
  91 + fakeFeed = feed.createFeed(fakeRSS,["News"])
  92 + @collector.collectFeed fakeFeed,(err,result)->
  93 + expect(err).to.be.null
  94 + expect(result.title).to.equal "BBC News - Home"
  95 + expect(result.entry[0].title).to.equal "Cameron halts press regulation talks"
  96 + expect(result.entry[0].tags).to.eql ["News"]
  97 + done()

0 comments on commit dc54c6e

Please sign in to comment.
Something went wrong with that request. Please try again.