Sha256: ba372dba2fb133ea69f15bb171e36e1e1f9850376379db89282ed6544d1c0f6c

Contents?: true

Size: 1.1 KB

Versions: 17

Compression:

Stored size: 1.1 KB

Contents

require 'net/https'
require 'uri'
require 'open-uri'
require 'openssl'

class SiteChecker

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

	class <<self
		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

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

		def site
			@@site
		end

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

		def proxy
			@@proxy
		end
	end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
rhodes-7.6.0 lib/build/SiteChecker.rb
rhodes-7.5.1 lib/build/SiteChecker.rb
rhodes-7.4.1 lib/build/SiteChecker.rb
rhodes-7.1.17 lib/build/SiteChecker.rb
rhodes-6.2.0 lib/build/SiteChecker.rb
rhodes-6.0.11 lib/build/SiteChecker.rb
rhodes-5.5.18 lib/build/SiteChecker.rb
rhodes-5.5.17 lib/build/SiteChecker.rb
rhodes-5.5.15 lib/build/SiteChecker.rb
rhodes-5.5.0.22 lib/build/SiteChecker.rb
rhodes-5.5.2 lib/build/SiteChecker.rb
rhodes-5.5.0.7 lib/build/SiteChecker.rb
rhodes-5.5.0.3 lib/build/SiteChecker.rb
rhodes-5.5.0 lib/build/SiteChecker.rb
tauplatform-1.0.3 lib/build/SiteChecker.rb
tauplatform-1.0.2 lib/build/SiteChecker.rb
tauplatform-1.0.1 lib/build/SiteChecker.rb