Created
October 22, 2012 15:00
-
-
Save mahemoff/3931897 to your computer and use it in GitHub Desktop.
canonicalize feed urls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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