Class: SiteChecker

Inherits:
Object show all
Defined in:
lib/build/SiteChecker.rb

Constant Summary collapse

@@was_checked =
false
@@available =
false
@@site =
""
@@proxy =
nil

Class Method Summary collapse

Class Method Details

.is_available?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/build/SiteChecker.rb', line 14

def is_available? 
	if !@@was_checked
		@@available = false
		uri = URI.parse(@@site)

		begin
			if !(proxy.nil? || proxy.empty?)
				proxy_uri = URI.parse(proxy)
				http = Net::HTTP.new(uri.host, uri.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password )
			else
				http = Net::HTTP.new(uri.host, uri.port)
			end

			if uri.scheme == "https"  # enable SSL/TLS
				http.use_ssl = true
				http.verify_mode = OpenSSL::SSL::VERIFY_NONE
			end

			http.start {
				http.request_get(uri.path) {|res|}
			}
			@@available = true
		rescue => e
			puts "Error accessing #{uri.inspect}: #{e.inspect}"
			puts e.backtrace
		end
		@@was_checked = true
	end
	@@available
end

.proxyObject



59
60
61
# File 'lib/build/SiteChecker.rb', line 59

def proxy
	@@proxy
end

.proxy=(proxy) ⇒ Object



54
55
56
57
# File 'lib/build/SiteChecker.rb', line 54

def proxy=(proxy)
	@@proxy = proxy
	@@was_checked = false
end

.siteObject



50
51
52
# File 'lib/build/SiteChecker.rb', line 50

def site
	@@site
end

.site=(site) ⇒ Object



45
46
47
48
# File 'lib/build/SiteChecker.rb', line 45

def site=(site)
	@@site = site
	@@was_checked = false
end