Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
canonicalize feed urls
def test_feedburner_aliased
series = Series.create title: 'foo', url: 'http://feeds.feedburner.com/InTheBleachersPodcast'
assert_not_nil Series.find_by_url('http://feeds.feedburner.com/inthebleacherspodcast')
assert_not_nil Series.find_by_url('http://feeds.feedburner.com/inthebleacherspodcast/')
assert_not_nil Series.find_by_url('http://feeds.feedburner.com/inthebleacherspodcast.xml')
assert_not_nil Series.find_by_url('http://feeds.feedburner.com/inthebleacherspodcast?format=rss')
assert_not_nil Series.find_by_url('http://feeds2.feedburner.com/inthebleacherspodcast?format=rss')
assert_not_nil (series = Series.find_by_url('http://feeds.feedburner.com/InTheBleachersPodcast'))
assert_equal 'http://feeds.feedburner.com/inthebleacherspodcast', series.url
end
def self.canonicalize_uri(uri)
uri = Addressable::URI.heuristic_parse(uri)
uri.scheme = 'http' unless uri.scheme=='http' or uri.scheme=='https'
if uri.host =~ /feedburner.com$/
uri.host = 'feeds.feedburner.com' # ignore feeds2 alias
uri.path = uri.path.downcase.gsub(/\/$/, '').gsub(/\..+/,'')
uri.query=nil
end
uri.to_s.strip
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment