Module: Utilities::Net
- Defined in:
- lib/utilities/net.rb
Overview
Special general routines for Net-specific itams
Class Method Summary collapse
-
.ask_about(text) ⇒ Object
URI site responce to the request.
-
.resolves?(text) ⇒ Boolean
True if URI site responds positivly to the request.
Class Method Details
.ask_about(text) ⇒ Object
Returns URI site responce to the request.
34 35 36 37 38 39 |
# File 'lib/utilities/net.rb', line 34 def self.ask_about(text) uri = URI.parse(text) ::Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| http.head(uri.path) end end |
.resolves?(text) ⇒ Boolean
Returns true if URI site responds positivly to the request.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/utilities/net.rb', line 7 def self.resolves?(text) responded = false if text =~ /^http(s)*:\/\/(.+)/ # http:// or https:// parsed = true uri = URI.parse(text) if uri.host.nil? parsed = false end if parsed ::Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| resp = http.head(uri.path) case resp.code # when '200', '302', '303', '308' when /^[23]\d\d$/ responded = true when /^[145]\d\d$/ responded = false end # resp.each { |k, v| puts "#{k}: #{v}" } end end end responded end |