Class: Resterl::GetRequest

Inherits:
GenericRequest show all
Defined in:
lib/resterl/get_request.rb

Overview

Constant Summary

Constants inherited from GenericRequest

Resterl::GenericRequest::DEFAULT_HEADERS

Instance Attribute Summary collapse

Attributes inherited from GenericRequest

#body, #response, #rest_client, #url

Instance Method Summary collapse

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.options[:max_redirect_depth]
end

Instance Attribute Details

#redirect_limitObject

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

#performObject

Raises:

  • (TooManyRedirects)


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