LongURL::Direct

Public Class Methods

follow_redirections(orig, limit = 5) click to toggle source

Will follow redirections given url orig.

Exceptions

# File lib/longurl/direct.rb, line 12
    def self.follow_redirections(orig, limit = 5)
      raise LongURL::TooManyRedirections if limit == 0
      uri = LongURL::URL.check(orig)
      Net::HTTP.start(uri.host, uri.port) do |http|
        answer = http.get(uri.path.empty? ? '/' : uri.path)
        dest = answer['Location']
        (dest && dest[0, 7] == 'http://' && follow_redirections(dest, limit - 1)) || orig
      end
    rescue Timeout::Error, Errno::ENETUNREACH, Errno::ETIMEDOUT, SocketError
      raise LongURL::NetworkError
    rescue
      raise LongURL::UnknownError
    end

Disabled; run with $DEBUG to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.