Class: Checkup::Service::Http
Instance Attribute Summary collapse
-
#expected_code ⇒ Object
Returns the value of attribute expected_code.
-
#expected_response ⇒ Object
Returns the value of attribute expected_response.
-
#method ⇒ Object
Returns the value of attribute method.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
Methods inherited from Base
Methods included from Configuration::Helpers
#clear_defaults!, #load_defaults!
Constructor Details
This class inherits a constructor from Checkup::Service::Base
Instance Attribute Details
#expected_code ⇒ Object
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_response ⇒ Object
Returns the value of attribute expected_response.
11 12 13 |
# File 'lib/checkup/service/http.rb', line 11 def expected_response @expected_response end |
#method ⇒ Object
Returns the value of attribute method.
9 10 11 |
# File 'lib/checkup/service/http.rb', line 9 def method @method end |
#url ⇒ Object
Returns the value of attribute url.
8 9 10 |
# File 'lib/checkup/service/http.rb', line 8 def url @url end |
Instance Method Details
#identifier ⇒ Object
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. "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 |