class Pwhois::WhoisParser

Constants

UNKNOWN

Constants

Attributes

attributes[RW]

Instance variables

output_style[RW]

Instance variables

verbose[RW]

Instance variables

Public Class Methods

new() click to toggle source
# File lib/pwhois.rb, line 21
def initialize()
    @whois_client = Whois::Client.new
    @verbose = false
    @output_style = :list
    @attributes = [:domain, :created_on, :updated_on, :registrar_name]
end

Public Instance Methods

get_attr(record, attr) click to toggle source
# File lib/pwhois.rb, line 29
def get_attr(record, attr)
    if record == nil
        raise(ArgumentError, ":record must not be nil")
    end

    if "#{attr}".start_with?("registrar")
        if record.registrar != nil
            a = "#{attr}".split('_')[1]
            get_attr(record.registrar, a)
        end
    else
        if record.respond_to?(attr)
            record.send(attr)
        else
            raise(ArgumentError, "Warning:  attribute \"#{ attr }\" does not exist for this domain")
        end
    end
end
query(q) click to toggle source
# File lib/pwhois.rb, line 49
def query(q)
    query_list([ q ])
end
query_list(querys) click to toggle source
# File lib/pwhois.rb, line 54
def query_list(querys)
    print_header()

    # only required for table listings.
    results = []

    querys.each do |q|
        result = Hash.new
        begin
            print_verbose("Querying whois for #{q}...")
            record = @whois_client.lookup(q)
            if !record
                $stderr.puts "No WHOIS record found for #{q}"
            end

            attributes.each do |a|
                begin
                    result[a] = get_attr(record, a)
                rescue ArgumentError => e
                    $stderr.puts e.message
                end
            end

            if output_style == :table
                results.push(result)
            else
                print_item(result)
            end
        rescue Whois::ConnectionError => e
            $stderr.puts e.message
        rescue Timeout::Error
            $stderr.puts "Timeout encountered retrieving data for #{q}"
        rescue SystemExit,Interrupt
            print_verbose("Ctrl-C pressed, exiting")
            exit
        rescue NoMethodError, StandardError => e
            $stderr.puts e.message
            $stderr.puts e.backtrace
            exit
        end
    end # querys.each

    if output_style == :table
        print_table(results)
    end
end

Private Instance Methods

print_header() click to toggle source
print_item(result) click to toggle source
print_list_item(result) click to toggle source
print_table(records) click to toggle source
print_verbose(msg) click to toggle source
quote_if_include(str, char) click to toggle source
# File lib/pwhois.rb, line 110
def quote_if_include(str, char)
    if "#{str}".include?(char)
        "\"#{str}\""
    else
        "#{str}"
    end
end