Sha256: 7562b0d39a2506d40c299afb8fa4446eef9999fafd006abffa40900e48fa8dfd

Contents?: true

Size: 712 Bytes

Versions: 26

Compression:

Stored size: 712 Bytes

Contents

require "net/http"
require "uri"

module Bard
  class Ping < Struct.new(:server)
    def self.call server
      new(server).call
    end

    def call
      server.ping.reject do |url|
        response = get_response_with_redirect(url) rescue nil
        response.is_a?(Net::HTTPSuccess)
      end
    end

    private

    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
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
bard-1.4.4 lib/bard/ping.rb
bard-1.4.3 lib/bard/ping.rb
bard-1.4.2 lib/bard/ping.rb
bard-1.4.1 lib/bard/ping.rb
bard-1.4.0 lib/bard/ping.rb
bard-1.3.9 lib/bard/ping.rb
bard-1.3.8 lib/bard/ping.rb
bard-1.3.7 lib/bard/ping.rb
bard-1.3.6 lib/bard/ping.rb
bard-1.3.5 lib/bard/ping.rb
bard-1.3.4 lib/bard/ping.rb
bard-1.3.3 lib/bard/ping.rb
bard-1.3.2 lib/bard/ping.rb
bard-1.3.1 lib/bard/ping.rb
bard-1.3.0 lib/bard/ping.rb
bard-1.2.0 lib/bard/ping.rb
bard-1.1.2 lib/bard/ping.rb
bard-1.1.1 lib/bard/ping.rb
bard-1.1.0 lib/bard/ping.rb
bard-1.0.8 lib/bard/ping.rb