Sha256: 735d6fc290c372aa02a387289bd073f87aa803c527aeb3fa9b1f221ec4ed7dad

Contents?: true

Size: 825 Bytes

Versions: 5

Compression:

Stored size: 825 Bytes

Contents

require 'rubygems'
require 'hpricot'

class Autodiscovery
  def initialize(page_html)
    # Downcase the html because capitalized stuff might mess up the Hpricot matching
    @doc = Hpricot(page_html)
  end

  # Returns the url of the feed, or nil if none found
  def discover
    # Look for rss link, e.g.
    # <link rel="alternate" type="application/rss+xml" title="RSS"
    #       href="http://feeds.feedburner.com/TheRssBlog">
    # Tricky: Hpricot CSS attribute selectors are written like XPath selectors
    [:rss, :atom].each do |flavor|
      if x=@doc.at("head link[@type=application/#{flavor}+xml]")
        puts "Found feed link #{x}"
        return x[:href]
      end
    end
    if x=@doc.at("head link[@type=text/xml]")
      puts "Found feed link #{x}"
      return x[:href]
    end
    return nil
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fastreader-1.0.4 lib/autodiscovery.rb
fastreader-1.0.5 lib/autodiscovery.rb
fastreader-1.0.6 lib/autodiscovery.rb
fastreader-1.0.7 lib/autodiscovery.rb
fastreader-1.0.8 lib/autodiscovery.rb