feed_parser 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,8 +20,15 @@ class FeedParser
20
20
  end
21
21
 
22
22
  def url
23
- _url = @feed.xpath(Dsl[@type][:url]).text
24
- @url = (!_url.nil? && _url.length > 0 && _url || @feed.xpath(Dsl[@type][:url]).attribute("href").text)
23
+ _url = case @type
24
+ when :rss
25
+ @feed.xpath(Dsl[@type][:url]) && @feed.xpath(Dsl[@type][:url])
26
+ when :atom
27
+ @feed.xpath(Dsl[@type][:url]).attribute("href")
28
+ else
29
+ nil
30
+ end
31
+ @url = _url && _url.text || ""
25
32
  end
26
33
 
27
34
  def items
@@ -6,8 +6,8 @@ class FeedParser
6
6
  @guid = item.xpath(Dsl[@type][:item_guid]).text
7
7
  @title = item.xpath(Dsl[@type][:item_title]).text
8
8
  @author = item.xpath(Dsl[@type][:item_author]).text
9
- @description = item.xpath(Dsl[@type][:item_description]).text
10
- @content = item.xpath(Dsl[@type][:item_content]).text
9
+ @description = possible_text(item.xpath(Dsl[@type][:item_description]))
10
+ @content = possible_text(item.xpath(Dsl[@type][:item_content]))
11
11
  self
12
12
  end
13
13
 
@@ -34,6 +34,11 @@ class FeedParser
34
34
  :content => content
35
35
  }
36
36
  end
37
+
38
+ private
39
+ def possible_text(element)
40
+ element && element.text || ''
41
+ end
37
42
  end
38
43
 
39
44
  class RssItem < FeedItem
data/lib/feed_parser.rb CHANGED
@@ -3,7 +3,7 @@ require 'nokogiri'
3
3
 
4
4
  class FeedParser
5
5
 
6
- VERSION = "0.2.1"
6
+ VERSION = "0.2.2"
7
7
 
8
8
  def initialize(opts)
9
9
  @url = opts[:url]
@@ -84,6 +84,21 @@ describe FeedParser do
84
84
  }
85
85
  ]
86
86
  },
87
+ 'basecamp.rss.xml' => {
88
+ :title => "Awesome project",
89
+ :url => "",
90
+ :items => [
91
+ {
92
+ :guid => "basecamp.00000000.Comment.1234567",
93
+ :link => "https://awesome.basecamphq.com/unique_item_link",
94
+ :title => "Comment posted: Re: Howdy how?",
95
+ :categories => [],
96
+ :author => "Ffuuuuuuu- Le.",
97
+ :description => "<div>trololooo</div><p>Company: awesome | Project: Awesome project</p>",
98
+ :content => ""
99
+ }
100
+ ]
101
+ },
87
102
  'TechCrunch.xml' => {
88
103
  :title => "TechCrunch",
89
104
  :url => "http://techcrunch.com",
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
3
+ <channel>
4
+ <title>Awesome project</title>
5
+ <link></link>
6
+ <description>Recent items</description>
7
+ <language>en-us</language>
8
+ <ttl>40</ttl>
9
+ <item>
10
+ <title>Comment posted: Re: Howdy how?</title>
11
+ <description>&lt;div&gt;trololooo&lt;/div&gt;&lt;p&gt;Company: awesome | Project: Awesome project&lt;/p&gt;</description>
12
+ <pubDate>Wed, 09 Nov 2011 20:35:18 +0000</pubDate>
13
+ <guid isPermaLink="false">basecamp.00000000.Comment.1234567</guid>
14
+ <link>https://awesome.basecamphq.com/unique_item_link</link>
15
+ <dc:creator>Ffuuuuuuu- Le.</dc:creator>
16
+ </item>
17
+ </channel>
18
+ </rss>
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feed_parser
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Arttu Tervo
@@ -69,6 +69,7 @@ files:
69
69
  - lib/feed_parser/self_sanitizer.rb
70
70
  - spec/feed_parser_spec.rb
71
71
  - spec/fixtures/TechCrunch.xml
72
+ - spec/fixtures/basecamp.rss.xml
72
73
  - spec/fixtures/gcal.atom.xml
73
74
  - spec/fixtures/nodeta.rss.xml
74
75
  - spec/fixtures/sanitize.me.rss.xml
@@ -110,6 +111,7 @@ summary: Rss and Atom feed parser
110
111
  test_files:
111
112
  - spec/feed_parser_spec.rb
112
113
  - spec/fixtures/TechCrunch.xml
114
+ - spec/fixtures/basecamp.rss.xml
113
115
  - spec/fixtures/gcal.atom.xml
114
116
  - spec/fixtures/nodeta.rss.xml
115
117
  - spec/fixtures/sanitize.me.rss.xml