Class: Unwind::RedirectFollower
- Inherits:
-
Object
- Object
- Unwind::RedirectFollower
- Defined in:
- lib/unwind.rb
Instance Attribute Summary collapse
-
#final_url ⇒ Object
readonly
Returns the value of attribute final_url.
-
#original_url ⇒ Object
readonly
Returns the value of attribute original_url.
-
#redirect_limit ⇒ Object
readonly
Returns the value of attribute redirect_limit.
-
#redirects ⇒ Object
readonly
Returns the value of attribute redirects.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(original_url, limit = 5) ⇒ RedirectFollower
constructor
A new instance of RedirectFollower.
- #redirected? ⇒ Boolean
- #resolve(current_url = nil, options = {}) ⇒ Object
Constructor Details
#initialize(original_url, limit = 5) ⇒ RedirectFollower
Returns a new instance of RedirectFollower.
14 15 16 17 18 |
# File 'lib/unwind.rb', line 14 def initialize(original_url, limit=5) @original_url, @redirect_limit = original_url, limit @redirects = [] end |
Instance Attribute Details
#final_url ⇒ Object (readonly)
Returns the value of attribute final_url.
12 13 14 |
# File 'lib/unwind.rb', line 12 def final_url @final_url end |
#original_url ⇒ Object (readonly)
Returns the value of attribute original_url.
12 13 14 |
# File 'lib/unwind.rb', line 12 def original_url @original_url end |
#redirect_limit ⇒ Object (readonly)
Returns the value of attribute redirect_limit.
12 13 14 |
# File 'lib/unwind.rb', line 12 def redirect_limit @redirect_limit end |
#redirects ⇒ Object (readonly)
Returns the value of attribute redirects.
12 13 14 |
# File 'lib/unwind.rb', line 12 def redirects @redirects end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
12 13 14 |
# File 'lib/unwind.rb', line 12 def response @response end |
Class Method Details
.resolve(original_url, limit = 5) ⇒ Object
44 45 46 |
# File 'lib/unwind.rb', line 44 def self.resolve(original_url, limit=5) new(original_url, limit).resolve end |
Instance Method Details
#redirected? ⇒ Boolean
20 21 22 |
# File 'lib/unwind.rb', line 20 def redirected? !(self.final_url == self.original_url) end |
#resolve(current_url = nil, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/unwind.rb', line 24 def resolve(current_url=nil, ={}) ok_to_continue? current_url ||= self.original_url #adding this header because we really only care about resolving the url headers = ( || {}).merge({"accept-encoding" => "none"}) response = Faraday.get(current_url, {}, headers) if is_response_redirect?(response) handle_redirect(redirect_url(response), current_url, response, headers) elsif = (current_url, response) handle_redirect(, current_url, response, headers) else handle_final_response(current_url, response) end self end |