Sha256: d17ef42631419d43ff235c58a721b8c886adaca09c532532b6b934c320bd5ea7

Contents?: true

Size: 778 Bytes

Versions: 1

Compression:

Stored size: 778 Bytes

Contents

class ProconBypassMan::WebConnectivityChecker
  # @param [String, NilClass] url
  def initialize(url)
    @url = url
  end

  # @return [String]
  def to_s
    if @url.nil?
      return "DISABLE"
    end

    if alive?
      return "ENABLE (#{@url})"
    else
     return "UNREACHABLE (#{@url})"
    end
  end

  private

  # @return [Boolean]
  def alive?
    uri = URI.parse(@url)
    response = nil

    begin
      Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
        request = Net::HTTP::Head.new(uri)
        response = http.request(request)
      end
    rescue StandardError => e
      ProconBypassMan.logger.error e
      return false
    end

    response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPMovedPermanently)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
procon_bypass_man-0.3.7 lib/procon_bypass_man/support/web_connectivity_checker.rb