feedtools 0.2.25 → 0.2.26
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/lib/feed_tools/database_feed_cache.rb +3 -0
- data/lib/feed_tools/feed.rb +57 -4
- data/lib/feed_tools/monkey_patch.rb +21 -3
- data/lib/feed_tools/version.rb +1 -1
- data/test/unit/rss_test.rb +12 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
data/lib/feed_tools/feed.rb
CHANGED
@@ -45,7 +45,7 @@ module FeedTools
|
|
45
45
|
@href = nil
|
46
46
|
@id = nil
|
47
47
|
@title = nil
|
48
|
-
@
|
48
|
+
@subtitle = nil
|
49
49
|
@link = nil
|
50
50
|
@last_retrieved = nil
|
51
51
|
@time_to_live = nil
|
@@ -158,7 +158,35 @@ module FeedTools
|
|
158
158
|
end
|
159
159
|
self.update!
|
160
160
|
end
|
161
|
+
else
|
162
|
+
ugly_redirect = FeedTools::XmlHelper.try_xpaths(self.xml_document, [
|
163
|
+
"redirect/newLocation/text()"
|
164
|
+
], :select_result_value => true)
|
165
|
+
if !ugly_redirect.blank?
|
166
|
+
self.feed_data = nil
|
167
|
+
self.href = ugly_redirect
|
168
|
+
if FeedTools.feed_cache.nil?
|
169
|
+
self.cache_object = nil
|
170
|
+
else
|
171
|
+
self.cache_object =
|
172
|
+
FeedTools.feed_cache.find_by_href(ugly_redirect)
|
173
|
+
end
|
174
|
+
self.update!
|
175
|
+
end
|
161
176
|
end
|
177
|
+
|
178
|
+
# Reset everything that needs to be reset.
|
179
|
+
@xml_document = nil
|
180
|
+
@encoding_from_feed_data = nil
|
181
|
+
@root_node = nil
|
182
|
+
@channel_node = nil
|
183
|
+
@id = nil
|
184
|
+
@title = nil
|
185
|
+
@subtitle = nil
|
186
|
+
@copyright = nil
|
187
|
+
@link = nil
|
188
|
+
@time_to_live = nil
|
189
|
+
@entries = nil
|
162
190
|
end
|
163
191
|
end
|
164
192
|
|
@@ -331,7 +359,7 @@ module FeedTools
|
|
331
359
|
|
332
360
|
# Returns the encoding that the feed was parsed with
|
333
361
|
def encoding
|
334
|
-
if @encoding.
|
362
|
+
if @encoding.blank?
|
335
363
|
unless self.http_headers.blank?
|
336
364
|
@encoding = "utf-8"
|
337
365
|
else
|
@@ -344,8 +372,9 @@ module FeedTools
|
|
344
372
|
# Returns the encoding of feed calculated only from the xml data.
|
345
373
|
# I.e., the encoding we would come up with if we ignore RFC 3023.
|
346
374
|
def encoding_from_feed_data
|
347
|
-
if @encoding_from_feed_data.
|
375
|
+
if @encoding_from_feed_data.blank?
|
348
376
|
raw_data = self.feed_data
|
377
|
+
return nil if raw_data.nil?
|
349
378
|
encoding_from_xml_instruct =
|
350
379
|
raw_data.scan(
|
351
380
|
/^<\?xml [^>]*encoding="([\w]*)"[^>]*\?>/
|
@@ -404,6 +433,24 @@ module FeedTools
|
|
404
433
|
unless self.cache_object.nil?
|
405
434
|
self.cache_object.feed_data = new_feed_data
|
406
435
|
end
|
436
|
+
ugly_redirect = FeedTools::XmlHelper.try_xpaths(self.xml_document, [
|
437
|
+
"redirect/newLocation/text()"
|
438
|
+
], :select_result_value => true)
|
439
|
+
if !ugly_redirect.blank?
|
440
|
+
for var in self.instance_variables
|
441
|
+
self.instance_variable_set(var, nil)
|
442
|
+
end
|
443
|
+
@http_headers = {}
|
444
|
+
@feed_data = nil
|
445
|
+
self.href = ugly_redirect
|
446
|
+
if FeedTools.feed_cache.nil?
|
447
|
+
self.cache_object = nil
|
448
|
+
else
|
449
|
+
self.cache_object =
|
450
|
+
FeedTools.feed_cache.find_by_href(ugly_redirect)
|
451
|
+
end
|
452
|
+
self.update!
|
453
|
+
end
|
407
454
|
end
|
408
455
|
|
409
456
|
# Returns the feed's raw data as utf-8.
|
@@ -744,6 +791,7 @@ module FeedTools
|
|
744
791
|
end
|
745
792
|
end
|
746
793
|
end
|
794
|
+
|
747
795
|
# rdf:about is ordered last because a lot of people put the url to
|
748
796
|
# the feed inside it instead of a link to their blog.
|
749
797
|
# Ordering it last gives them as many chances as humanly possible
|
@@ -755,7 +803,8 @@ module FeedTools
|
|
755
803
|
"feed/@rdf:resource",
|
756
804
|
"feed/@resource",
|
757
805
|
"@rdf:about",
|
758
|
-
"@about"
|
806
|
+
"@about",
|
807
|
+
"newLocation/text()"
|
759
808
|
], :select_result_value => true) do |result|
|
760
809
|
override_href.call(FeedTools::UriHelper.normalize_url(result))
|
761
810
|
end
|
@@ -2439,6 +2488,10 @@ module FeedTools
|
|
2439
2488
|
# The cache is disabled for this feed, do nothing.
|
2440
2489
|
return
|
2441
2490
|
end
|
2491
|
+
if self.feed_data.blank? && self.http_headers.blank?
|
2492
|
+
# There's no data, nothing to save.
|
2493
|
+
return
|
2494
|
+
end
|
2442
2495
|
if self.http_headers['content-type'] =~ /text\/html/ ||
|
2443
2496
|
self.http_headers['content-type'] =~ /application\/xhtml\+xml/
|
2444
2497
|
if self.title.nil? && self.link.nil? && self.entries.blank?
|
@@ -553,7 +553,13 @@ module REXML # :nodoc:
|
|
553
553
|
parser.variables = variables
|
554
554
|
path = "*" unless path
|
555
555
|
element = [element] unless element.kind_of? Array
|
556
|
-
|
556
|
+
retried = false
|
557
|
+
begin
|
558
|
+
parser.parse(path, element)
|
559
|
+
rescue NoMethodError => error
|
560
|
+
retry if !retried
|
561
|
+
raise error
|
562
|
+
end
|
557
563
|
end
|
558
564
|
|
559
565
|
def self.liberal_first(element, path=nil, namespaces={},
|
@@ -563,7 +569,13 @@ module REXML # :nodoc:
|
|
563
569
|
parser.variables = variables
|
564
570
|
path = "*" unless path
|
565
571
|
element = [element] unless element.kind_of? Array
|
566
|
-
|
572
|
+
retried = false
|
573
|
+
begin
|
574
|
+
parser.parse(path, element)[0]
|
575
|
+
rescue NoMethodError => error
|
576
|
+
retry if !retried
|
577
|
+
raise error
|
578
|
+
end
|
567
579
|
end
|
568
580
|
|
569
581
|
def self.liberal_each(element, path=nil, namespaces={},
|
@@ -573,7 +585,13 @@ module REXML # :nodoc:
|
|
573
585
|
parser.variables = variables
|
574
586
|
path = "*" unless path
|
575
587
|
element = [element] unless element.kind_of? Array
|
576
|
-
|
588
|
+
retried = false
|
589
|
+
begin
|
590
|
+
parser.parse(path, element).each( &block )
|
591
|
+
rescue NoMethodError => error
|
592
|
+
retry if !retried
|
593
|
+
raise error
|
594
|
+
end
|
577
595
|
end
|
578
596
|
end
|
579
597
|
|
data/lib/feed_tools/version.rb
CHANGED
data/test/unit/rss_test.rb
CHANGED
@@ -20,6 +20,18 @@ class RssTest < Test::Unit::TestCase
|
|
20
20
|
}
|
21
21
|
end
|
22
22
|
|
23
|
+
def test_radio_redirection
|
24
|
+
with_feed(:from_data => <<-FEED
|
25
|
+
<redirect>
|
26
|
+
<newLocation>http://www.slashdot.org/index.rss</newLocation>
|
27
|
+
</redirect>
|
28
|
+
FEED
|
29
|
+
) { |feed|
|
30
|
+
assert_not_nil feed.href
|
31
|
+
assert_not_nil feed.title
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
23
35
|
def test_feed_title
|
24
36
|
with_feed(:from_file => 'wellformed/rss/channel_title.xml') { |feed|
|
25
37
|
assert_equal("Example feed", feed.title)
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: feedtools
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2006-07-
|
6
|
+
version: 0.2.26
|
7
|
+
date: 2006-07-20 00:00:00 -04:00
|
8
8
|
summary: Parsing, generation, and caching system for xml news feeds.
|
9
9
|
require_paths:
|
10
10
|
- lib
|