Class: Io::Flow::Reference::V0::HttpClient::DefaultHttpHandlerInstance

Inherits:
HttpHandlerInstance show all
Defined in:
lib/io_flow_reference_v0.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_uri) ⇒ DefaultHttpHandlerInstance

Returns a new instance of DefaultHttpHandlerInstance.



682
683
684
685
686
687
688
# File 'lib/io_flow_reference_v0.rb', line 682

def initialize(base_uri)
  @base_uri = Preconditions.assert_class('base_uri', base_uri, URI)
  @client = Net::HTTP.new(@base_uri.host, @base_uri.port)
  if @base_uri.scheme == "https"
    configure_ssl
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



680
681
682
# File 'lib/io_flow_reference_v0.rb', line 680

def client
  @client
end

Instance Method Details

#configure_sslObject

Called to configure SSL if the base uri requires it



711
712
713
714
715
716
# File 'lib/io_flow_reference_v0.rb', line 711

def configure_ssl
  @client.use_ssl = true
  @client.verify_mode = OpenSSL::SSL::VERIFY_PEER
  @client.cert_store = OpenSSL::X509::Store.new
  @client.cert_store.set_default_paths
end

#execute(request) ⇒ Object



690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
# File 'lib/io_flow_reference_v0.rb', line 690

def execute(request)
  response = begin
               @client.request(request)
             rescue SocketError => e
               raise Exception.new("Error accessing uri[#{full_uri(request.path)}]: #{e}")
             end

  case response
  when Net::HTTPSuccess
    response.body
  else
    body = response.body rescue nil
    raise HttpClient::ServerError.new(response.code.to_i, response.message, :body => body, :uri => full_uri(request.path).to_s)
  end
end

#full_uri(path) ⇒ Object



706
707
708
# File 'lib/io_flow_reference_v0.rb', line 706

def full_uri(path)
  File.join(@base_uri.to_s, path)
end