clayton/consummo

View on GitHub
lib/consummo/enrichers/url_resolver.rb

Summary

Maintainability
A
0 mins
Test Coverage
require 'httparty'

module Consummo
  class UrlResolver
    def resolve(url)
      return url if url.blank?
      begin
        response = HTTParty.head(url, follow_redirects: true)
        response.request.last_uri
      rescue Errno::ECONNREFUSED, URI::InvalidURIError, HTTParty::RedirectionTooDeep
        url
      end
    end
  end
end