rrsimple-rss 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rrsimple-rss.rb +17 -5
- data/rrsimple-rss.gemspec +1 -1
- data/test/base/base_test.rb +37 -0
- metadata +1 -1
data/lib/rrsimple-rss.rb
CHANGED
@@ -2,7 +2,7 @@ require 'cgi'
|
|
2
2
|
require 'time'
|
3
3
|
|
4
4
|
class RRSimpleRSS
|
5
|
-
VERSION = "1.3.
|
5
|
+
VERSION = "1.3.4"
|
6
6
|
|
7
7
|
attr_reader :items, :source
|
8
8
|
alias :entries :items
|
@@ -18,7 +18,7 @@ class RRSimpleRSS
|
|
18
18
|
:image, :logo, :icon, :rating,
|
19
19
|
:rights, :copyright,
|
20
20
|
:textInput, :'feedburner:browserFriendly',
|
21
|
-
:'itunes:author', :'itunes:category', :"full-text"
|
21
|
+
:'itunes:author', :'itunes:category', :"full-text", :categories, :keywords
|
22
22
|
]
|
23
23
|
|
24
24
|
@@item_tags = [
|
@@ -27,14 +27,14 @@ class RRSimpleRSS
|
|
27
27
|
:author, :contributor,
|
28
28
|
:description, :summary, :content, :'content:encoded', :comments,
|
29
29
|
:pubDate, :published, :updated, :expirationDate, :modified, :'dc:date',
|
30
|
-
:category, :guid,
|
30
|
+
:category, :categories, :guid,
|
31
31
|
:'trackback:ping', :'trackback:about',
|
32
32
|
:'dc:creator', :'dc:title', :'dc:subject', :'dc:rights', :'dc:publisher',
|
33
33
|
:'feedburner:origLink',
|
34
34
|
:'media:content#url', :'media:content#type', :'media:content#height', :'media:content#width',
|
35
35
|
:'media:title', :'media:thumbnail#url', :'media:thumbnail#height', :'media:thumbnail#width',
|
36
36
|
:'media:credit', :'media:credit#role',
|
37
|
-
:'media:category', :'media:category#scheme', :"full-text"
|
37
|
+
:'media:category', :'media:category#scheme', :"full-text", :keywords
|
38
38
|
]
|
39
39
|
|
40
40
|
def initialize(source, options={})
|
@@ -109,6 +109,7 @@ class RRSimpleRSS
|
|
109
109
|
elsif match[3] =~ %r{<(rss:|atom:)?#{tag}(.*?)rel=['"]#{rel}['"](.*?)/\s*>}mi
|
110
110
|
nil
|
111
111
|
end
|
112
|
+
|
112
113
|
item[clean_tag("#{tag}+#{rel}")] = clean_content(tag, $3, $4) if $3 || $4
|
113
114
|
elsif tag.to_s.include?("#")
|
114
115
|
tag_data = tag.to_s.split("#")
|
@@ -119,6 +120,7 @@ class RRSimpleRSS
|
|
119
120
|
elsif match[3] =~ %r{<(rss:|atom:)?#{tag}(.*?)#{attrib}=['"](.*?)['"](.*?)/\s*>}mi
|
120
121
|
nil
|
121
122
|
end
|
123
|
+
|
122
124
|
item[clean_tag("#{tag}_#{attrib}")] = clean_content(tag, attrib, $3) if $3
|
123
125
|
else
|
124
126
|
if match[3] =~ %r{<(rss:|atom:)?#{tag}(.*?)>(.*?)</(rss:|atom:)?#{tag}>}mi
|
@@ -126,7 +128,13 @@ class RRSimpleRSS
|
|
126
128
|
elsif match[3] =~ %r{<(rss:|atom:)?#{tag}(.*?)/\s*>}mi
|
127
129
|
nil
|
128
130
|
end
|
129
|
-
|
131
|
+
|
132
|
+
if tag == :category || tag == :keywords
|
133
|
+
item[:categories] = match[3].scan(%r{<(rss:|atom:)?#{tag}(.*?)>(.*?)</(rss:|atom:)?#{tag}>}mi).map {|x| category(x[2])}
|
134
|
+
else
|
135
|
+
item[clean_tag(tag)] = clean_content(tag, $2, $3) if $2 || $3
|
136
|
+
end
|
137
|
+
|
130
138
|
end
|
131
139
|
end
|
132
140
|
|
@@ -137,6 +145,10 @@ class RRSimpleRSS
|
|
137
145
|
|
138
146
|
end
|
139
147
|
|
148
|
+
def category(str)
|
149
|
+
str.include?("CDATA") ? str[9..str.length-4] : str
|
150
|
+
end
|
151
|
+
|
140
152
|
def clean_content(tag, attrs, content)
|
141
153
|
content = content.to_s
|
142
154
|
case tag
|
data/rrsimple-rss.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "rrsimple-rss"
|
3
|
-
s.version = "1.3.
|
3
|
+
s.version = "1.3.4"
|
4
4
|
s.date = "2010-07-06"
|
5
5
|
s.summary = "A simple, flexible, extensible, and liberal RSS and Atom reader for Ruby. It is designed to be backwards compatible with the standard RSS parser, but will never do RSS generation."
|
6
6
|
s.email = "rodrigo@rrmartins.com"
|
data/test/base/base_test.rb
CHANGED
@@ -6,7 +6,9 @@ require 'pry'
|
|
6
6
|
|
7
7
|
class BaseTest < Test::Unit::TestCase
|
8
8
|
def setup
|
9
|
+
@rss_prnews = RRSimpleRSS.parse open(File.dirname(__FILE__) + '/../data/prnews.xml')
|
9
10
|
@rss_bbc = RRSimpleRSS.parse open(File.dirname(__FILE__) + '/../data/bbc.xml')
|
11
|
+
@rss_baboo = RRSimpleRSS.parse open(File.dirname(__FILE__) + '/../data/baboo.xml')
|
10
12
|
@rss09 = RRSimpleRSS.parse open(File.dirname(__FILE__) + '/../data/rss09.rdf')
|
11
13
|
@rss20 = RRSimpleRSS.parse open(File.dirname(__FILE__) + '/../data/rss20.xml')
|
12
14
|
@media_rss = RRSimpleRSS.parse open(File.dirname(__FILE__) + '/../data/media_rss.xml')
|
@@ -18,15 +20,45 @@ class BaseTest < Test::Unit::TestCase
|
|
18
20
|
assert_equal @rss09, @rss09.channel
|
19
21
|
assert_equal @rss20, @rss20.channel
|
20
22
|
assert_equal @atom, @atom.feed
|
23
|
+
assert_equal @rss_baboo, @rss_baboo.feed
|
24
|
+
assert_equal @rss_prnews, @rss_prnews.feed
|
21
25
|
end
|
22
26
|
|
23
27
|
def test_items
|
28
|
+
assert_kind_of Array, @rss_baboo.items
|
24
29
|
assert_kind_of Array, @rss_bbc.items
|
25
30
|
assert_kind_of Array, @rss09.items
|
26
31
|
assert_kind_of Array, @rss20.items
|
27
32
|
assert_kind_of Array, @atom.entries
|
33
|
+
assert_kind_of Array, @rss_prnews.items
|
28
34
|
end
|
29
35
|
|
36
|
+
def test_rss_prnews
|
37
|
+
assert_equal 20, @rss_prnews.items.size
|
38
|
+
assert_equal "PR Newswire Releases", @rss_prnews.title.force_encoding("UTF-8")
|
39
|
+
assert_equal "http://www.prnewswire.com/news-releases/sva-promove-exposicao-de-cartazes-que-retrata-a-evolucao-do-design-grafico-nos-ultimos-70-anos-540199401.html", @rss_prnews.channel.link
|
40
|
+
assert_equal "http://www.prnewswire.com/news-releases/sva-promove-exposicao-de-cartazes-que-retrata-a-evolucao-do-design-grafico-nos-ultimos-70-anos-540199401.html", @rss_prnews.items.first.link
|
41
|
+
assert_equal "http://www.prnewswire.com/news-releases/sva-promove-exposicao-de-cartazes-que-retrata-a-evolucao-do-design-grafico-nos-ultimos-70-anos-540199401.html", @rss_prnews.items.first[:link]
|
42
|
+
assert_equal Time.parse("2015-11-04 15:30:00 -0200"), @rss_prnews.items.first.pubDate
|
43
|
+
assert_equal Time.parse("2015-11-09 11:55:45 -0200"), @rss_prnews.channel.lastBuildDate
|
44
|
+
assert_nil @rss_prnews.items.first.full_text
|
45
|
+
assert_not_nil @rss_prnews.items.first.description
|
46
|
+
assert_kind_of Array, @rss_prnews.items.first.categories
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_rss_baboo
|
50
|
+
assert_equal 21, @rss_baboo.items.size
|
51
|
+
assert_equal "BABOO", @rss_baboo.title.force_encoding("UTF-8")
|
52
|
+
assert_equal "http://www.baboo.com.br", @rss_baboo.channel.link
|
53
|
+
assert_equal "http://www.baboo.com.br/internet/lista-do-procon-sp-com-lojas-online-que-devem-ser-evitadas-e-atualizada/", @rss_baboo.items.first.link
|
54
|
+
assert_equal "http://www.baboo.com.br/internet/lista-do-procon-sp-com-lojas-online-que-devem-ser-evitadas-e-atualizada/", @rss_baboo.items.first[:link]
|
55
|
+
assert_equal Time.parse("2015-11-05 14:11:24 -0200"), @rss_baboo.items.first.pubDate
|
56
|
+
assert_equal Time.parse("2015-11-05 14:11:24 -0200"), @rss_baboo.channel.lastBuildDate
|
57
|
+
assert_nil @rss_baboo.items.first.full_text
|
58
|
+
assert_not_nil @rss_baboo.items.first.description
|
59
|
+
assert_kind_of Array, @rss_baboo.items.first.categories
|
60
|
+
end
|
61
|
+
|
30
62
|
def test_rss_bbc
|
31
63
|
assert_equal 9, @rss_bbc.items.size
|
32
64
|
assert_equal "BBCBrasil.com | Vídeos e Fotos", @rss_bbc.title.force_encoding("UTF-8")
|
@@ -36,6 +68,7 @@ class BaseTest < Test::Unit::TestCase
|
|
36
68
|
assert_equal Time.parse("2015-11-03 08:21:50 -0200"), @rss_bbc.items.first.pubDate
|
37
69
|
assert_equal Time.parse("2015-11-05 07:33:38 -0200"), @rss_bbc.channel.lastBuildDate
|
38
70
|
assert_not_nil @rss_bbc.items.first.full_text
|
71
|
+
assert_kind_of Array, @rss_bbc.items.first.categories
|
39
72
|
end
|
40
73
|
|
41
74
|
def test_rss09
|
@@ -47,6 +80,7 @@ class BaseTest < Test::Unit::TestCase
|
|
47
80
|
assert_equal Time.parse("2005-09-09 06:52:31 -0300"), @rss09.items.first.dc_date
|
48
81
|
assert_equal Time.parse("Fri Sep 09 02:52:31 PDT 2005"), @rss09.channel.dc_date
|
49
82
|
assert_nil @rss09.items.first.full_text
|
83
|
+
assert_kind_of Array, @rss09.items.first.categories
|
50
84
|
end
|
51
85
|
|
52
86
|
def test_media_rss
|
@@ -68,6 +102,7 @@ class BaseTest < Test::Unit::TestCase
|
|
68
102
|
assert_equal "pets frodo", @media_rss.items.first.media_category
|
69
103
|
assert_equal "urn:flickr:tags", @media_rss.items.first.media_category_scheme
|
70
104
|
assert_nil @media_rss.items.first.full_text
|
105
|
+
assert_kind_of Array, @media_rss.items.first.categories
|
71
106
|
end
|
72
107
|
|
73
108
|
def test_rss20
|
@@ -78,6 +113,7 @@ class BaseTest < Test::Unit::TestCase
|
|
78
113
|
assert_equal "http://feeds.feedburner.com/rufytech?m=68", @rss20.items.first[:link]
|
79
114
|
assert_equal "This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site.", @rss20.channel.feedburner_browserFriendly
|
80
115
|
assert_nil @rss20.items.first.full_text
|
116
|
+
assert_kind_of Array, @rss20.items.first.categories
|
81
117
|
end
|
82
118
|
|
83
119
|
def test_atom
|
@@ -87,6 +123,7 @@ class BaseTest < Test::Unit::TestCase
|
|
87
123
|
assert_equal "http://example.org/2005/04/02/atom", @atom.entries.first.link
|
88
124
|
assert_equal "http://example.org/2005/04/02/atom", @atom.entries.first[:link]
|
89
125
|
assert_nil @atom.entries.first.full_text
|
126
|
+
assert_kind_of Array, @atom.entries.first.categories
|
90
127
|
end
|
91
128
|
|
92
129
|
def test_bad_feed
|