Class: Shoes::HttpRequest

Inherits:
Object
  • Object
show all
Defined in:
shoes-core/lib/shoes/http_request.rb

Instance Method Summary collapse

Constructor Details

#initialize(started_proc = nil, redirects_left = 5) ⇒ HttpRequest

Returns a new instance of HttpRequest.



19
20
21
22
# File 'shoes-core/lib/shoes/http_request.rb', line 19

def initialize(started_proc = nil, redirects_left = 5)
  @started_proc = started_proc
  @redirects_left = redirects_left
end

Instance Method Details

#read_chunks(url, meth, body, headers = {}, &blk) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'shoes-core/lib/shoes/http_request.rb', line 24

def read_chunks(url, meth, body, headers = {}, &blk)
  uri = URI(url)
  Net::HTTP.start(uri.host, uri.port, use_ssl: needs_ssl?(uri)) do |http|
    request = build_request(uri, meth, body, headers)

    http.request(request) do |response|
      case response
      when Net::HTTPSuccess
        handle_success(response, &blk)
      when Net::HTTPRedirection
        handle_redirect(response, headers, &blk)
      else
        handle_error(response)
      end
    end
  end
end