Class: Resterl::GetRequest
- Inherits:
-
GenericRequest
- Object
- GenericRequest
- Resterl::GetRequest
- Defined in:
- lib/resterl/get_request.rb
Overview
Redirect code from: railstips.org/blog/archives/2009/03/04/following-redirects-with-nethttp/
Constant Summary
Constants inherited from GenericRequest
Resterl::GenericRequest::DEFAULT_HEADERS
Instance Attribute Summary collapse
-
#redirect_limit ⇒ Object
Returns the value of attribute redirect_limit.
Attributes inherited from GenericRequest
#body, #response, #rest_client, #url
Instance Method Summary collapse
-
#initialize(client, url, query_params, headers) ⇒ GetRequest
constructor
A new instance of GetRequest.
- #perform ⇒ Object
Constructor Details
#initialize(client, url, query_params, headers) ⇒ GetRequest
Returns a new instance of GetRequest.
6 7 8 9 |
# File 'lib/resterl/get_request.rb', line 6 def initialize client, url, query_params, headers super client, url, query_params, headers @redirect_limit = @rest_client.[:max_redirect_depth] end |
Instance Attribute Details
#redirect_limit ⇒ Object
Returns the value of attribute redirect_limit.
4 5 6 |
# File 'lib/resterl/get_request.rb', line 4 def redirect_limit @redirect_limit end |
Instance Method Details
#perform ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/resterl/get_request.rb', line 11 def perform raise TooManyRedirects if redirect_limit < 0 http, path = http_object_and_query_path request = Net::HTTP::Get.new path, @headers apply_basic_auth request self.response = http.request(request) # Follow redirects if response.is_a?(Net::HTTPRedirection) && !response.is_a?(Net::HTTPNotModified) self.url = redirect_url self.redirect_limit -= 1 perform end self end |