Class: Heartcheck::Webservice::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/heartcheck/webservice/http_client.rb

Overview

Http Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, proxy, ignore_ssl_cert, headers, open_timeout = nil, read_timeout = nil) ⇒ HttpClient

Returns a new instance of HttpClient.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/heartcheck/webservice/http_client.rb', line 8

def initialize(url, proxy, ignore_ssl_cert, headers, open_timeout = nil, read_timeout = nil)
  @uri = URI(url)
  @headers = headers || {}
  @proxy = URI(proxy) if proxy

  @http = Net::HTTP.new(@uri.host, @uri.port, proxy_host, proxy_port)
  @http.use_ssl = @uri.scheme == 'https'
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE if ignore_ssl_cert
  @http.open_timeout = open_timeout if open_timeout
  @http.read_timeout = read_timeout if read_timeout
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/heartcheck/webservice/http_client.rb', line 6

def headers
  @headers
end

#httpObject (readonly)

Returns the value of attribute http.



6
7
8
# File 'lib/heartcheck/webservice/http_client.rb', line 6

def http
  @http
end

#open_timeoutObject (readonly)

Returns the value of attribute open_timeout.



6
7
8
# File 'lib/heartcheck/webservice/http_client.rb', line 6

def open_timeout
  @open_timeout
end

#proxyObject (readonly)

Returns the value of attribute proxy.



6
7
8
# File 'lib/heartcheck/webservice/http_client.rb', line 6

def proxy
  @proxy
end

#read_timeoutObject (readonly)

Returns the value of attribute read_timeout.



6
7
8
# File 'lib/heartcheck/webservice/http_client.rb', line 6

def read_timeout
  @read_timeout
end

#requestObject (readonly)

Returns the value of attribute request.



6
7
8
# File 'lib/heartcheck/webservice/http_client.rb', line 6

def request
  @request
end

#uriObject (readonly)

Returns the value of attribute uri.



6
7
8
# File 'lib/heartcheck/webservice/http_client.rb', line 6

def uri
  @uri
end

Instance Method Details

#getObject



20
21
22
23
24
25
26
# File 'lib/heartcheck/webservice/http_client.rb', line 20

def get
  @request = Net::HTTP::Get.new(uri.request_uri)

  headers.each { |k, v| request[k] = v }

  http.request request
end