module Isitup

Docs to follow

Constants

VERSION

Public Class Methods

check(domain, options = {}) click to toggle source
# File lib/isitup.rb, line 14
def self.check(domain, options = {})
    data = query_api(domain)
    process_data(data, options)
end
process_data(data, options) click to toggle source
# File lib/isitup.rb, line 34
def self.process_data(data, options)
    case data.status
    when 1
        if options[:color]
            "The domain: #{data.domain} is up! Response time: #{data.time}".green
        else
            "The domain: #{data.domain} is up! Response time: #{data.time}"
        end
    when 2
        if options[:color]
            "The domain: #{data.domain} is down".red
        else
            "The domain: #{data.domain} is down"
        end
    else
        if options[:color]
            "#{data.domain} is not a valid domain!".blue
        else
            "#{data.domain} is not a valid domain!"
        end
    end
end
query_api(domain) click to toggle source
# File lib/isitup.rb, line 19
def self.query_api(domain)
    url = "http://isitup.org/#{domain}.json"
    response = RestClient.get(url)
    data = JSON.parse(response)

    OpenStruct.new(
        domain: data['domain'],
        status: data['status_code'],
        time: data['response_time']
    )
rescue RestClient::Exception => e
    e.response
    nil
end