Class: Sonic::Protocol::HTTP

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/sonic/protocols/http.rb

Instance Method Summary collapse

Constructor Details

#initialize(service_checker) ⇒ HTTP

Returns a new instance of HTTP.



8
9
10
11
12
13
14
15
16
# File 'lib/sonic/protocols/http.rb', line 8

def initialize(service_checker)
  @service_checker = service_checker
  @http = Net::HTTP.new(service_checker.host, service_checker.port)
  if service_checker.protocol == :https
    @http.use_ssl = true
    @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  @request = Net::HTTP::Get.new(service_checker.path)
end

Instance Method Details

#getObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sonic/protocols/http.rb', line 18

def get
  begin
    response = @http.request(@request)
    @service_checker.response = response.body
    case response.code
    when '200', '201', '202', '203', '204', '205', '206'
      true
    else
      @service_checker.error = response.error
      false
    end
  rescue Exception => e
    @service_checker.error = e.to_s
    false
  end
end