Sha256: 16807ee98383bf1dfaf068c28327448183077f06544909e9cda123474a57f770

Contents?: true

Size: 850 Bytes

Versions: 143

Compression:

Stored size: 850 Bytes

Contents

module Onebox
  class StatusCheck
    def initialize(url, options = Onebox.options)
      @url = url
      @options = options
      @status = -1
    end

    def ok?
      status > 199 && status < 300
    end

    def status
      check if @status == -1
      @status
    end

    def human_status
      case status
      when 0
        :connection_error
      when 200..299
        :success
      when 400..499
        :client_error
      when 500..599
        :server_error
      else
        :unknown_error
      end
    end

    private

    def check
      res = open(@url, read_timeout: (@options.timeout || Onebox.options.timeout))
      @status = res.status.first.to_i
    rescue OpenURI::HTTPError => e
      @status = e.io.status.first.to_i
    rescue Timeout::Error, Errno::ECONNREFUSED, Net::HTTPError
      @status = 0
    end
  end
end

Version data entries

143 entries across 143 versions & 1 rubygems

Version Path
onebox-1.8.7 lib/onebox/status_check.rb
onebox-1.8.6 lib/onebox/status_check.rb
onebox-1.8.5 lib/onebox/status_check.rb
onebox-1.8.4 lib/onebox/status_check.rb
onebox-1.8.3 lib/onebox/status_check.rb
onebox-1.8.2 lib/onebox/status_check.rb
onebox-1.8.1 lib/onebox/status_check.rb
onebox-1.8.0 lib/onebox/status_check.rb
onebox-1.7.9 lib/onebox/status_check.rb
onebox-1.7.8 lib/onebox/status_check.rb
onebox-1.7.7 lib/onebox/status_check.rb
onebox-1.7.6 lib/onebox/status_check.rb
onebox-1.7.5 lib/onebox/status_check.rb
onebox-1.7.4 lib/onebox/status_check.rb
onebox-1.7.3 lib/onebox/status_check.rb
onebox-1.7.2 lib/onebox/status_check.rb
onebox-1.7.1 lib/onebox/status_check.rb
onebox-1.7.0 lib/onebox/status_check.rb
onebox-1.6.9 lib/onebox/status_check.rb
onebox-1.6.8 lib/onebox/status_check.rb