simple-rss 1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -30,6 +30,9 @@ But since the parser can read Atom feeds as easily as RSS feeds, there are optio
30
30
  The parser does not care about the correctness of the XML as it does not use an XML library to read the information. Thus it is flexible and allows for easy extending via:
31
31
 
32
32
  SimpleRSS.feed_tags << :some_new_tag
33
+ SimpleRSS.item_tags << :"item+myrel" # this will extend SimpleRSS to be able to parse RSS items or ATOM entries that have a rel specified, common in many blogger feeds
34
+ SimpleRSS.item_tags << :"feedburner:origLink" # this will extend SimpleRSS to be able to parse RSS items or ATOM entries that have a specific pre-tag specified, common in many feedburner feeds
35
+
33
36
 
34
37
  == Authors
35
38
  * Lucas Carlson (mailto:lucas@rufy.com)
data/Rakefile CHANGED
@@ -127,7 +127,6 @@ task :upload => [:package] do
127
127
  end
128
128
 
129
129
  cookie = login_response["set-cookie"]
130
- puts login_response["set-cookie"]
131
130
  raise "Login failed" unless cookie
132
131
  headers = { "Cookie" => cookie }
133
132
 
@@ -2,7 +2,7 @@ require 'cgi'
2
2
  require 'time'
3
3
 
4
4
  class SimpleRSS
5
- VERSION = "1.1"
5
+ VERSION = "1.2"
6
6
 
7
7
  attr_reader :items, :source
8
8
  alias :entries :items
@@ -23,13 +23,14 @@ class SimpleRSS
23
23
 
24
24
  @@item_tags = [
25
25
  :id,
26
- :title, :link,
26
+ :title, :link, :'link+alternate', :'link+self', :'link+edit', :'link+replies',
27
27
  :author, :contributor,
28
28
  :description, :summary, :content, :'content:encoded', :comments,
29
29
  :pubDate, :published, :updated, :expirationDate, :modified, :'dc:date',
30
30
  :category, :guid,
31
31
  :'trackback:ping', :'trackback:about',
32
- :'dc:creator', :'dc:title', :'dc:subject', :'dc:rights', :'dc:publisher'
32
+ :'dc:creator', :'dc:title', :'dc:subject', :'dc:rights', :'dc:publisher',
33
+ :'feedburner:origLink'
33
34
  ]
34
35
 
35
36
  def initialize(source)
@@ -93,12 +94,25 @@ class SimpleRSS
93
94
  @source.scan( %r{<(rss:|atom:)?(item|entry)([\s][^>]*)?>(.*?)</(rss:|atom:)?(item|entry)>}mi ) do |match|
94
95
  item = Hash.new
95
96
  @@item_tags.each do |tag|
96
- if match[3] =~ %r{<(rss:|atom:)?#{tag}(.*?)>(.*?)</(rss:|atom:)?#{tag}>}mi
97
- nil
98
- elsif match[3] =~ %r{<(rss:|atom:)?#{tag}(.*?)/\s*>}mi
99
- nil
97
+ if tag.to_s.include?("+")
98
+ tag_data = tag.to_s.split("+")
99
+ tag = tag_data[0]
100
+ rel = tag_data[1]
101
+
102
+ if match[3] =~ %r{<(rss:|atom:)?#{tag}(.*?)rel=['"]#{rel}['"](.*?)>(.*?)</(rss:|atom:)?#{tag}>}mi
103
+ nil
104
+ elsif match[3] =~ %r{<(rss:|atom:)?#{tag}(.*?)rel=['"]#{rel}['"](.*?)/\s*>}mi
105
+ nil
106
+ end
107
+ item[clean_tag("#{tag}+#{rel}")] = clean_content(tag, $3, $4) if $3 || $4
108
+ else
109
+ if match[3] =~ %r{<(rss:|atom:)?#{tag}(.*?)>(.*?)</(rss:|atom:)?#{tag}>}mi
110
+ nil
111
+ elsif match[3] =~ %r{<(rss:|atom:)?#{tag}(.*?)/\s*>}mi
112
+ nil
113
+ end
114
+ item[clean_tag(tag)] = clean_content(tag, $2, $3) if $2 || $3
100
115
  end
101
- item[clean_tag(tag)] = clean_content(tag, $2, $3) if $2 || $3
102
116
  end
103
117
  def item.method_missing(name, *args) self[name] end
104
118
  @items << item
@@ -122,9 +136,13 @@ class SimpleRSS
122
136
  tag.to_s.gsub(':','_').intern
123
137
  end
124
138
 
125
- def unescape(content)
126
- CGI.unescape(content).gsub(/(<!\[CDATA\[|\]\]>)/,'').strip
127
- end
139
+ def unescape(content)
140
+ if content =~ /([^-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]]%)/n then
141
+ CGI.unescape(content).gsub(/(<!\[CDATA\[|\]\]>)/,'').strip
142
+ else
143
+ content.gsub(/(<!\[CDATA\[|\]\]>)/,'').strip
144
+ end
145
+ end
128
146
  end
129
147
 
130
148
  class SimpleRSSError < StandardError
metadata CHANGED
@@ -1,77 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
3
- specification_version: 1
4
2
  name: simple-rss
5
3
  version: !ruby/object:Gem::Version
6
- version: "1.1"
7
- date: 2006-02-01 00:00:00 -08:00
8
- 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.
9
- require_paths:
10
- - lib
11
- email: lucas@rufy.com
12
- homepage: http://simple-rss.rubyforge.org/
13
- rubyforge_project:
14
- description: 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.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: "1.2"
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
6
  authors:
29
7
  - Lucas Carlson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-25 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: 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.
17
+ email: lucas@rufy.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
30
24
  files:
31
25
  - lib/simple-rss.rb
32
26
  - test/base
33
- - test/data
34
- - test/test_helper.rb
35
27
  - test/base/base_test.rb
28
+ - test/data
36
29
  - test/data/atom.xml
37
30
  - test/data/not-rss.xml
38
31
  - test/data/rss09.rdf
39
32
  - test/data/rss20.xml
33
+ - test/test_helper.rb
40
34
  - LICENSE
41
35
  - Rakefile
42
36
  - README
43
- - html/classes
44
- - html/created.rid
45
- - html/files
46
- - html/fr_class_index.html
47
- - html/fr_file_index.html
48
- - html/fr_method_index.html
49
- - html/index.html
50
- - html/rdoc-style.css
51
- - html/classes/SimpleRSS.html
52
- - html/classes/SimpleRSS.src
53
- - html/classes/SimpleRSSError.html
54
- - html/classes/SimpleRSS.src/M000001.html
55
- - html/classes/SimpleRSS.src/M000002.html
56
- - html/classes/SimpleRSS.src/M000004.html
57
- - html/classes/SimpleRSS.src/M000005.html
58
- - html/classes/SimpleRSS.src/M000006.html
59
- - html/classes/SimpleRSS.src/M000007.html
60
- - html/classes/SimpleRSS.src/M000008.html
61
- - html/files/lib
62
- - html/files/README.html
63
- - html/files/lib/simple-rss_rb.html
64
- test_files: []
65
-
37
+ has_rdoc: true
38
+ homepage: http://simple-rss.rubyforge.org/
39
+ post_install_message:
66
40
  rdoc_options: []
67
41
 
68
- extra_rdoc_files: []
69
-
70
- executables: []
71
-
72
- extensions: []
73
-
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
74
56
  requirements: []
75
57
 
76
- dependencies: []
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.1
60
+ signing_key:
61
+ specification_version: 2
62
+ 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.
63
+ test_files: []
77
64
 
@@ -1,292 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>Class: SimpleRSS</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <div id="classHeader">
50
- <table class="header-table">
51
- <tr class="top-aligned-row">
52
- <td><strong>Class</strong></td>
53
- <td class="class-name-in-header">SimpleRSS</td>
54
- </tr>
55
- <tr class="top-aligned-row">
56
- <td><strong>In:</strong></td>
57
- <td>
58
- <a href="../files/lib/simple-rss_rb.html">
59
- lib/simple-rss.rb
60
- </a>
61
- <br />
62
- </td>
63
- </tr>
64
-
65
- <tr class="top-aligned-row">
66
- <td><strong>Parent:</strong></td>
67
- <td>
68
- Object
69
- </td>
70
- </tr>
71
- </table>
72
- </div>
73
- <!-- banner header -->
74
-
75
- <div id="bodyContent">
76
-
77
-
78
-
79
- <div id="contextContent">
80
-
81
-
82
-
83
- </div>
84
-
85
- <div id="method-list">
86
- <h3 class="section-bar">Methods</h3>
87
-
88
- <div class="name-list">
89
- <a href="#M000002">channel</a>&nbsp;&nbsp;
90
- <a href="#M000003">feed</a>&nbsp;&nbsp;
91
- <a href="#M000004">feed_tags</a>&nbsp;&nbsp;
92
- <a href="#M000005">feed_tags=</a>&nbsp;&nbsp;
93
- <a href="#M000006">item_tags</a>&nbsp;&nbsp;
94
- <a href="#M000007">item_tags=</a>&nbsp;&nbsp;
95
- <a href="#M000001">new</a>&nbsp;&nbsp;
96
- <a href="#M000008">parse</a>&nbsp;&nbsp;
97
- </div>
98
- </div>
99
-
100
- </div>
101
-
102
-
103
- <!-- if includes -->
104
-
105
- <div id="section">
106
-
107
-
108
- <div id="constants-list">
109
- <h3 class="section-bar">Constants</h3>
110
-
111
- <div class="name-list">
112
- <table summary="Constants">
113
- <tr class="top-aligned-row context-row">
114
- <td class="context-item-name">VERSION</td>
115
- <td>=</td>
116
- <td class="context-item-value">&quot;1.1&quot;</td>
117
- </tr>
118
- </table>
119
- </div>
120
- </div>
121
-
122
- <div id="aliases-list">
123
- <h3 class="section-bar">External Aliases</h3>
124
-
125
- <div class="name-list">
126
- <table summary="aliases">
127
- <tr class="top-aligned-row context-row">
128
- <td class="context-item-name">items</td>
129
- <td>-></td>
130
- <td class="context-item-value">entries</td>
131
- </tr>
132
- </table>
133
- </div>
134
- </div>
135
-
136
-
137
- <div id="attribute-list">
138
- <h3 class="section-bar">Attributes</h3>
139
-
140
- <div class="name-list">
141
- <table>
142
- <tr class="top-aligned-row context-row">
143
- <td class="context-item-name">items</td>
144
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
145
- <td class="context-item-desc"></td>
146
- </tr>
147
- <tr class="top-aligned-row context-row">
148
- <td class="context-item-name">source</td>
149
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
150
- <td class="context-item-desc"></td>
151
- </tr>
152
- </table>
153
- </div>
154
- </div>
155
-
156
-
157
-
158
- <!-- if method_list -->
159
- <div id="methods">
160
- <h3 class="section-bar">Public Class methods</h3>
161
-
162
- <div id="method-M000004" class="method-detail">
163
- <a name="M000004"></a>
164
-
165
- <div class="method-heading">
166
- <a href="SimpleRSS.src/M000004.html" target="Code" class="method-signature"
167
- onclick="popupCode('SimpleRSS.src/M000004.html');return false;">
168
- <span class="method-name">feed_tags</span><span class="method-args">()</span>
169
- </a>
170
- </div>
171
-
172
- <div class="method-description">
173
- </div>
174
- </div>
175
-
176
- <div id="method-M000005" class="method-detail">
177
- <a name="M000005"></a>
178
-
179
- <div class="method-heading">
180
- <a href="SimpleRSS.src/M000005.html" target="Code" class="method-signature"
181
- onclick="popupCode('SimpleRSS.src/M000005.html');return false;">
182
- <span class="method-name">feed_tags=</span><span class="method-args">(ft)</span>
183
- </a>
184
- </div>
185
-
186
- <div class="method-description">
187
- </div>
188
- </div>
189
-
190
- <div id="method-M000006" class="method-detail">
191
- <a name="M000006"></a>
192
-
193
- <div class="method-heading">
194
- <a href="SimpleRSS.src/M000006.html" target="Code" class="method-signature"
195
- onclick="popupCode('SimpleRSS.src/M000006.html');return false;">
196
- <span class="method-name">item_tags</span><span class="method-args">()</span>
197
- </a>
198
- </div>
199
-
200
- <div class="method-description">
201
- </div>
202
- </div>
203
-
204
- <div id="method-M000007" class="method-detail">
205
- <a name="M000007"></a>
206
-
207
- <div class="method-heading">
208
- <a href="SimpleRSS.src/M000007.html" target="Code" class="method-signature"
209
- onclick="popupCode('SimpleRSS.src/M000007.html');return false;">
210
- <span class="method-name">item_tags=</span><span class="method-args">(it)</span>
211
- </a>
212
- </div>
213
-
214
- <div class="method-description">
215
- </div>
216
- </div>
217
-
218
- <div id="method-M000001" class="method-detail">
219
- <a name="M000001"></a>
220
-
221
- <div class="method-heading">
222
- <a href="SimpleRSS.src/M000001.html" target="Code" class="method-signature"
223
- onclick="popupCode('SimpleRSS.src/M000001.html');return false;">
224
- <span class="method-name">new</span><span class="method-args">(source)</span>
225
- </a>
226
- </div>
227
-
228
- <div class="method-description">
229
- </div>
230
- </div>
231
-
232
- <div id="method-M000008" class="method-detail">
233
- <a name="M000008"></a>
234
-
235
- <div class="method-heading">
236
- <a href="SimpleRSS.src/M000008.html" target="Code" class="method-signature"
237
- onclick="popupCode('SimpleRSS.src/M000008.html');return false;">
238
- <span class="method-name">parse</span><span class="method-args">(source, do_validate=true, ignore_unknown_element=true, parser_class=false)</span>
239
- </a>
240
- </div>
241
-
242
- <div class="method-description">
243
- <p>
244
- The strict attribute is for compatibility with Ruby&#8217;s standard RSS
245
- parser
246
- </p>
247
- </div>
248
- </div>
249
-
250
- <h3 class="section-bar">Public Instance methods</h3>
251
-
252
- <div id="method-M000002" class="method-detail">
253
- <a name="M000002"></a>
254
-
255
- <div class="method-heading">
256
- <a href="SimpleRSS.src/M000002.html" target="Code" class="method-signature"
257
- onclick="popupCode('SimpleRSS.src/M000002.html');return false;">
258
- <span class="method-name">channel</span><span class="method-args">()</span>
259
- </a>
260
- </div>
261
-
262
- <div class="method-description">
263
- </div>
264
- </div>
265
-
266
- <div id="method-M000003" class="method-detail">
267
- <a name="M000003"></a>
268
-
269
- <div class="method-heading">
270
- <span class="method-name">feed</span><span class="method-args">()</span>
271
- </div>
272
-
273
- <div class="method-description">
274
- <p>
275
- Alias for <a href="SimpleRSS.html#M000002">channel</a>
276
- </p>
277
- </div>
278
- </div>
279
-
280
-
281
- </div>
282
-
283
-
284
- </div>
285
-
286
-
287
- <div id="validator-badges">
288
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
289
- </div>
290
-
291
- </body>
292
- </html>