Class: PoolParty::Verifiers::HttpStatus
- Inherits:
-
VerifierBase
- Object
- VerifierBase
- PoolParty::Verifiers::HttpStatus
- 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
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Attributes inherited from VerifierBase
Instance Method Summary collapse
-
#initialize(uri, status) ⇒ HttpStatus
constructor
A new instance of HttpStatus.
- #passing? ⇒ Boolean
- #to_s ⇒ Object
Methods inherited from VerifierBase
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
#status ⇒ Object (readonly)
Returns the value of attribute status.
28 29 30 |
# File 'lib/poolparty/verification/verifiers/http_status.rb', line 28 def status @status end |
#uri ⇒ Object (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
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_s ⇒ Object
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 |