Sha256: b29d8c3dc2aec39706db9a95e88b4a1ef1ef2cfe4e70753ac5313f3bbc82aa4f
Contents?: true
Size: 1008 Bytes
Versions: 15
Compression:
Stored size: 1008 Bytes
Contents
require 'net/http' module Freyr class Pinger # URL to ping attr_reader :url # Time that the ping took attr_reader :time # Response object attr_reader :response def initialize(command) @command = command @url = command.ping end # The URI object for the given URL def uri @uri ||= URI.parse(url) end # Send a ping to the url def ping t = Time.now @response = Net::HTTP.get_response(uri) rescue Errno::ECONNREFUSED ensure @time = Time.now-t @response end def code response.code if response end # Did the response recieve a success http code def success? response.is_a?(Net::HTTPSuccess) end # Did the response recieve a 500 error def server_error? response.is_a?(Net::HTTPInternalServerError) end # Did it recieve 2xx or 500 def server_probably_launched? success? || server_error? end end end
Version data entries
15 entries across 15 versions & 1 rubygems