Class: HTTPI::Adapter::Typhoeus

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

Defined Under Namespace

Classes: TyphoesConnectionError

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Typhoeus

Returns a new instance of Typhoeus.



12
13
14
# File 'lib/httpi/adapter/typhoeus.rb', line 12

def initialize(request)
  @request = request
end

Instance Method Details

#request(http_method) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/httpi/adapter/typhoeus.rb', line 16

def request(http_method)
  @client = ::Typhoeus::Request.new(
    @request.url,
    method: http_method,
    body: @request.body,
    headers: @request.headers
  )

  configure_auth
  configure_proxy
  configure_ssl
  configure_timeouts

  response = @client.run

  if response.timed_out?
    raise TimeoutError
  elsif response.response_code == 0
    case response.return_message
    when /ssl/i
      raise SSLError, response.return_message
    else
      raise TyphoesConnectionError, response.return_message
    end
  else
    Response.new(response.code, response.headers, response.body)
  end
end