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
- .check(domain, options = {}) ⇒ Object
- .process_data(data, options) ⇒ Object
- .query_api(domain) ⇒ Object
Class Method Details
.check(domain, options = {}) ⇒ Object
14 15 16 17 |
# File 'lib/isitup.rb', line 14 def self.check(domain, = {}) data = query_api(domain) process_data(data, ) 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, ) case data.status when 1 if [: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 [:color] "The domain: #{data.domain} is down".red else "The domain: #{data.domain} is down" end else if [: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 |