Module: SiteChecker

Defined in:
lib/site_checker.rb,
lib/site_checker/cli.rb,
lib/site_checker/version.rb

Defined Under Namespace

Classes: CLI

Constant Summary collapse

VERSION =
"0.1.4"

Class Method Summary collapse

Class Method Details

.status(site, print_stdout = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/site_checker.rb', line 7

def self.status(site, print_stdout = nil)
	uri = URI.parse(site)
	http = Net::HTTP.new(uri.host, uri.port)
	proto = site.split(':')
	if proto[0] == "https"
		http.use_ssl = true
	end
	start_time = Time.now
	request = Net::HTTP::Get.new(uri.request_uri)
	res = http.request(request)
	end_time = Time.now - start_time

	if print_stdout
		# status
		puts "Website - #{site}"
		puts "Status - #{res.code} #{res.message}"
		puts "Response time - #{end_time} seconds"
	end
	res.code
end