class DoorKnock::Website

Attributes

url[R]

Public Class Methods

new(url) click to toggle source
# File lib/doorknock/website.rb, line 10
def initialize(url)
  @url = url
end

Public Instance Methods

body() click to toggle source
# File lib/doorknock/website.rb, line 14
def body
  @body ||= get_body
end
doc() click to toggle source
# File lib/doorknock/website.rb, line 35
def doc
  @doc ||= [].tap do |out|
    next unless body

    begin
      out << Oga.parse_html(body)
    rescue LL::ParserError => _
      nil
    end
  end.first
end
ok?() click to toggle source
# File lib/doorknock/website.rb, line 18
def ok?
  !body.nil?
end
panel?() click to toggle source
# File lib/doorknock/website.rb, line 22
def panel?
  password_form?
end
password_form?() click to toggle source
# File lib/doorknock/website.rb, line 26
def password_form?
  form = doc&.at_css("form")
  form && !form.at_css("input[type='password']").nil?
end
title() click to toggle source
# File lib/doorknock/website.rb, line 31
def title
  doc&.at_css("title")&.text
end

Private Instance Methods

get_body() click to toggle source
# File lib/doorknock/website.rb, line 49
def get_body
  res = HTTP.timeout(3).get(url)
  return nil if res.code != 200

  res.body.to_s
rescue HTTP::Error, OpenSSL::SSL::SSLError, Addressable::URI::InvalidURIError => _
  nil
end