Module: Isitup

Defined in:
lib/isitup.rb,
lib/isitup/version.rb

Overview

Docs to follow

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Class Method Details

.check(domain, options = {}) ⇒ Object



14
15
16
17
# File 'lib/isitup.rb', line 14

def self.check(domain, options = {})
    data = query_api(domain)
    process_data(data, options)
end

.process_data(data, options) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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