Browse files

Merge pull request #1 from icebreaker/master

Support for atom:link discovery. Thanks to @icebreaker!
  • Loading branch information...
2 parents 3cc897d + 47441b8 commit afac1b92655567c7ecbefac7b73deb13795e2165 @damog committed Mar 12, 2012
Showing with 31 additions and 2 deletions.
  1. +18 −0 lib/feedbag.rb
  2. +13 −2 test/feedbag_test.rb
View
18 lib/feedbag.rb
@@ -101,6 +101,13 @@ def self.find(url, args = {})
end
# first with links
+ (doc/"atom:link").each do |l|
+ next unless l["rel"]
+ if l["type"] and @content_types.include?(l["type"].downcase.strip) and l["rel"].downcase == "self"
+ self.add_feed(l["href"], url, $base_uri)
+ end
+ end
+
(doc/"link").each do |l|
next unless l["rel"]
if l["type"] and @content_types.include?(l["type"].downcase.strip) and (l["rel"].downcase =~ /alternate/i or l["rel"] == "service.feed")
@@ -122,6 +129,10 @@ def self.find(url, args = {})
end
end
+ # Added support for feeds like http://tabtimes.com/tbfeed/mashable/full.xml
+ if url.match(/.xml$/) and doc.root and doc.root["xml:base"] and doc.root["xml:base"].strip == url.strip
+ self.add_feed(url, nil)
+ end
end
rescue Timeout::Error => err
$stderr.puts "Timeout error ocurred with `#{url}: #{err}'"
@@ -182,3 +193,10 @@ def self._is_http_valid(uri, orig_url)
end
end
+if __FILE__ == $0
+ if ARGV.size == 0
+ puts 'usage: feedbag url'
+ else
+ puts Feedbag.find ARGV.first
+ end
+end
View
15 test/feedbag_test.rb
@@ -15,5 +15,16 @@ class FeedbagTest < ActiveSupport::TestCase
assert Feedbag.feed?(rss_url)
end
-
-end
+
+ test "Feedbag find should discover feeds containing atom:link" do
+ feeds = []
+ feeds << 'http://www.psfk.com/feeds/mashable'
+ feeds << 'http://jenniferlynch.wordpress.com/feed'
+ feeds << 'http://lurenbijdeburen.wordpress.com/feed'
+
+ feeds.each do |url|
+ assert_equal [url], Feedbag.find(url)
+ end
+ end
+
+end

0 comments on commit afac1b9

Please sign in to comment.