Class: RedirectFollower

Inherits:
Object show all
Defined in:
lib/spix_parser/tools/redirect_follower.rb

Class Method Summary collapse

Class Method Details

.resolve(url) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/spix_parser/tools/redirect_follower.rb', line 5

def self.resolve(url)
  @response = ""
  begin
    timeout(5) do
      t = Thread.new {@response = Net::HTTP.get_response(URI.parse(url)) }
      t.join

      if @response.kind_of?(Net::HTTPRedirection)
        return redirect_url(@response)
      end
    end
  rescue Timeout::Error, URI::InvalidURIError
    return url
  end

  url
end