Class: Net::PingHTTP

Inherits:
Ping
  • Object
show all
Includes:
Net
Defined in:
lib/net/ping.rb

Overview

For this class, host is actually a URI.

Constant Summary

Constants inherited from Ping

Net::Ping::VERSION

Instance Attribute Summary

Attributes inherited from Ping

#exception, #host, #port, #timeout, #warning

Instance Method Summary collapse

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

#pingObject 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.message
      end
   end

   success
end