Class: HTTPI::Adapter::HTTPClient

Inherits:
Base
  • Object
show all
Defined in:
lib/httpi/adapter/httpclient.rb

Overview

HTTPI::Adapter::HTTPClient

Adapter for the HTTPClient client. rubygems.org/gems/httpclient

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

register

Constructor Details

#initialize(request) ⇒ HTTPClient

Returns a new instance of HTTPClient.


15
16
17
18
# File 'lib/httpi/adapter/httpclient.rb', line 15

def initialize(request)
  @request = request
  @client = ::HTTPClient.new
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client


20
21
22
# File 'lib/httpi/adapter/httpclient.rb', line 20

def client
  @client
end

Instance Method Details

#request(method) ⇒ Object

Executes arbitrary HTTP requests.

See Also:


24
25
26
27
28
29
30
31
32
# File 'lib/httpi/adapter/httpclient.rb', line 24

def request(method)
  setup_client
  respond_with @client.request(method, @request.url, nil, @request.body, @request.headers, &@request.on_body)
rescue OpenSSL::SSL::SSLError
  raise SSLError
rescue Errno::ECONNREFUSED   # connection refused
  $!.extend ConnectionError
  raise
end