Class: RedirectFollower

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

Overview

Follow redirects for given urls with net http to find out their destinations

Source code mostly ripped from John Nunemaker: railstips.org/blog/archives/2009/03/04/following-redirects-with-nethttp/

Defined Under Namespace

Classes: TooManyRedirects

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_url, limit = 5) ⇒ RedirectFollower

Returns a new instance of RedirectFollower.



23
24
25
# File 'lib/redirect_follower.rb', line 23

def initialize(original_url, limit=5)
  @original_url, @redirect_limit = original_url, limit
end

Instance Attribute Details

#original_urlObject

Returns the value of attribute original_url.



20
21
22
# File 'lib/redirect_follower.rb', line 20

def original_url
  @original_url
end

#redirect_limitObject

Returns the value of attribute redirect_limit.



20
21
22
# File 'lib/redirect_follower.rb', line 20

def redirect_limit
  @redirect_limit
end

#responseObject



36
37
38
39
# File 'lib/redirect_follower.rb', line 36

def response
  resolve unless @response
  @response
end

#urlObject



27
28
29
30
# File 'lib/redirect_follower.rb', line 27

def url
  resolve unless @url
  @url
end

Instance Method Details

#bodyObject



32
33
34
# File 'lib/redirect_follower.rb', line 32

def body
  response.body
end