class Koji::Website
Attributes
url[R]
Public Class Methods
new(url)
click to toggle source
# File lib/koji/website.rb, line 12 def initialize(url) @url = URI(url) rescue URI::Error => _e raise ArgumentError, "#{uri} is not a valid URL." end
Public Instance Methods
body()
click to toggle source
# File lib/koji/website.rb, line 22 def body @body ||= response ? response&.body&.to_s : nil end
doc()
click to toggle source
# File lib/koji/website.rb, line 30 def doc @doc ||= body ? parse_html(body.to_s) : nil end
exception()
click to toggle source
# File lib/koji/website.rb, line 34 def exception @exception || nil end
response()
click to toggle source
# File lib/koji/website.rb, line 18 def response @response ||= get end
sha256()
click to toggle source
# File lib/koji/website.rb, line 26 def sha256 @sha256 ||= body ? Digest::SHA256.hexdigest(body.to_s) : nil end
Private Instance Methods
get()
click to toggle source
# File lib/koji/website.rb, line 49 def get http.get(url) rescue OpenSSL::SSL::SSLError, HTTP::Error, Addressable::URI::InvalidURIError => e @exception = e nil end
http()
click to toggle source
# File lib/koji/website.rb, line 40 def http if proxy = ENV["HTTPS_PROXY"] || ENV["https_proxy"] || ENV["HTTP_PROXY"] || ENV["http_proxy"] uri = URI(proxy) HTTP.via(uri.hostname, uri.port) else HTTP end end
parse_html(html)
click to toggle source
# File lib/koji/website.rb, line 56 def parse_html(html) Oga.parse_html(html) rescue ArgumentError, Encoding::CompatibilityError, LL::ParserError => _e nil end