Class: Net::PingHTTP
Overview
For this class, host
is actually a URI.
Constant Summary
Constants inherited from Ping
Instance Attribute Summary
Attributes inherited from Ping
#exception, #host, #port, #timeout, #warning
Instance Method Summary collapse
-
#initialize(host, port = 80, timeout = 5) ⇒ PingHTTP
constructor
Creates and returns a new PingHTTP object.
-
#ping ⇒ Object
(also: #ping?)
Looks for an HTTP response from the URI passed to the constructor.
Constructor Details
#initialize(host, port = 80, timeout = 5) ⇒ PingHTTP
Creates and returns a new PingHTTP object. – Defined separately in order to set the default port to 80.
205 206 207 |
# File 'lib/net/ping.rb', line 205 def initialize(host, port=80, timeout=5) super(host, port, timeout) end |
Instance Method Details
#ping ⇒ Object Also known as: ping?
Looks for an HTTP response from the URI passed to the constructor. If the result is HTTPSuccess or HTTPOK, the ping was successful.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/net/ping.rb', line 211 def ping super success = false uri = URI.parse(@host) begin resp = HTTP.get_response(uri.host, uri.path, @port) rescue Exception => err @exception = err else case resp when Net::HTTPSuccess, Net::HTTPOK success = true else @exception = resp. end end success end |