Class: HTTPI::Adapter::HTTP

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

Overview

HTTPI::Adapter::HTTP

Adapter for the http.rb client. github.com/httprb/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

register

Constructor Details

#initialize(request) ⇒ HTTP

Returns a new instance of HTTP.


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/httpi/adapter/http.rb', line 15

def initialize(request)
  if request.auth.digest?
    raise NotSupportedError, "http.rb does not support HTTP digest authentication"
  end
  if request.auth.ntlm?
    raise NotSupportedError, "http.rb does not support NTLM digest authentication"
  end

  @request = request
  @client = create_client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client


27
28
29
# File 'lib/httpi/adapter/http.rb', line 27

def client
  @client
end

Instance Method Details

#request(method) ⇒ Object

Executes arbitrary HTTP requests.

See Also:


31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/httpi/adapter/http.rb', line 31

def request(method)
  unless ::HTTP::Request::METHODS.include? method
    raise NotSupportedError, "http.rb does not support custom HTTP methods"
  end
  response = begin
    @client.send(method, @request.url, :body => @request.body)
  rescue OpenSSL::SSL::SSLError
    raise SSLError
  end

  Response.new(response.code, response.headers.to_h, response.body.to_s)
end