Class: Checkup::Service::Http

Inherits:
Base
  • Object
show all
Defined in:
lib/checkup/service/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Configuration::Helpers

#clear_defaults!, #load_defaults!

Constructor Details

This class inherits a constructor from Checkup::Service::Base

Instance Attribute Details

#expected_codeObject

Returns the value of attribute expected_code.



10
11
12
# File 'lib/checkup/service/http.rb', line 10

def expected_code
  @expected_code
end

#expected_responseObject

Returns the value of attribute expected_response.



11
12
13
# File 'lib/checkup/service/http.rb', line 11

def expected_response
  @expected_response
end

#methodObject

Returns the value of attribute method.



9
10
11
# File 'lib/checkup/service/http.rb', line 9

def method
  @method
end

#urlObject

Returns the value of attribute url.



8
9
10
# File 'lib/checkup/service/http.rb', line 8

def url
  @url
end

Instance Method Details

#identifierObject



42
43
44
# File 'lib/checkup/service/http.rb', line 42

def identifier
  return "#{self.method} #{self.url}"
end

#perform!Object



13
14
15
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
# File 'lib/checkup/service/http.rb', line 13

def perform!
  super
  
  response = ::HTTParty.send(self.method.to_sym, self.url)
  
  Logger.message "Got #{response.code} from #{self.url}"
  
  result = response.code == self.expected_code
  
  if !result
    raise Checkup::Errors::Service::Http::AssertError, 
      "Expected code #{self.expected_code}, got #{response.code}"
  end
  
  if self.expected_response.is_a? Regexp
    result &&= !!self.expected_response.match(response.body)
    if !result
      raise Checkup::Errors::Service::Http::RegexpError,
        "Expected match for #{self.expected_response.to_s}"
    end
  else
    result &&= self.expected_response == response.body
      raise Checkup::Errors::Service::Http::AssertError, 
        "Expected response #{self.expected_response}"
  end
  
  return result
end