class Bard::Ping

Public Class Methods

call(server) click to toggle source
# File lib/bard/ping.rb, line 6
def self.call server
  new(server).call
end

Public Instance Methods

call() click to toggle source
# File lib/bard/ping.rb, line 10
def call
  server.ping.reject do |url|
    response = get_response_with_redirect(url) rescue nil
    response.is_a?(Net::HTTPSuccess)
  end
end

Private Instance Methods

get_response_with_redirect(uri_str, limit=5) click to toggle source
# File lib/bard/ping.rb, line 19
def get_response_with_redirect uri_str, limit=5
  response = Net::HTTP.get_response(URI(uri_str))

  case response
  when Net::HTTPRedirection
    if limit == 0
      puts "too many HTTP redirects"
      response
    else
      get_response_with_redirect(response["location"], limit - 1)
    end
  else
    response
  end
end