Class: PoolParty::Verifiers::HttpStatus

Inherits:
VerifierBase show all
Defined in:
lib/poolparty/verification/verifiers/http_status.rb

Overview

HttpStatus Verifier

Verify the HTTP response code from a particular url

Usage

http_status url, response_code

Example

verify do
  http_status "http://host/index.html", 200
  http_status "http://host/index.html", :success
  http_status "http://host/asdfasdfads.html", 404
end

Instance Attribute Summary collapse

Attributes inherited from VerifierBase

#host

Instance Method Summary collapse

Methods inherited from VerifierBase

inherited, #name

Constructor Details

#initialize(uri, status) ⇒ HttpStatus

Returns a new instance of HttpStatus.



29
30
31
32
# File 'lib/poolparty/verification/verifiers/http_status.rb', line 29

def initialize(uri, status)
  @uri    = URI.parse(uri)
  @status = status
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



28
29
30
# File 'lib/poolparty/verification/verifiers/http_status.rb', line 28

def status
  @status
end

#uriObject (readonly)

Returns the value of attribute uri.



28
29
30
# File 'lib/poolparty/verification/verifiers/http_status.rb', line 28

def uri
  @uri
end

Instance Method Details

#passing?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/poolparty/verification/verifiers/http_status.rb', line 34

def passing?
  http = Net::HTTP.new(@uri.host)
  response = http.request_get(@uri.path && !@uri.path.empty? ? @uri.path : "/")

  return case true
         when status.kind_of?(Numeric)
           response.code == @status.to_s 
         when status.kind_of?(Symbol)
           case status
           when :success then response.kind_of?(Net::HTTPSuccess)
           else 
             raise "unknown symbol #{status}"
           end
         else
           raise "unknown status type #{status}"
         end
end

#to_sObject



52
53
54
# File 'lib/poolparty/verification/verifiers/http_status.rb', line 52

def to_s
  "<#{self.class.to_s} uri:#{uri} status:#{status}>"
end