url_resolver follows redirects to resolve URLs. It's pretty alright.
Gemfile:
gem 'url_resolver'
Rubygems:
gem install url_resolver
UrlResolver.resolve('https://www.google.com')
# => "https://www.google.com"
UrlResolver.resolve('https://analytics.google.com')
# => "https://www.google.com/analytics/"
url_resolver supports caching in case you're planning on hitting a lot of the same URLs over and over and over and over again.
It also supports using a custom list of errors to ignore.
UrlResolver.configure do |config|
config.cache = Redis.new # default: nil
config.cache_failures = true # default: true
config.user_agent = 'Custom User-Agent' # default: 'Ruby'
config.errors_to_ignore << MyModule::MyError
end
or
UrlResolver.configuration.cache = Redis.new
UrlResolver.configuration.cache_failures = true
UrlResolver.configuration.user_agent = 'Custom User-Agent'
UrlResolver.configuration.errors_to_ignore << MyModule::MyError
- Handle redirects that resolve to nonstandard protocols
- Initial release
- configurable cache timeouts + keys
- non-Redis caches
- more configurable failure handling (request timeouts, bad URLs, etc)
- support non-RestClient http clients
- relax and enjoy life