Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Created October 22, 2012 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahemoff/3931897 to your computer and use it in GitHub Desktop.
Save mahemoff/3931897 to your computer and use it in GitHub Desktop.
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