Class: Pwhois::WhoisParser
- Inherits:
-
Object
- Object
- Pwhois::WhoisParser
- Defined in:
- lib/pwhois.rb
Constant Summary collapse
- UNKNOWN =
Constants
"UNKNOWN"
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Instance variables.
-
#output_style ⇒ Object
Instance variables.
-
#verbose ⇒ Object
Instance variables.
Instance Method Summary collapse
- #get_attr(record, attr) ⇒ Object
-
#initialize ⇒ WhoisParser
constructor
A new instance of WhoisParser.
- #query(q) ⇒ Object
- #query_list(querys) ⇒ Object
Constructor Details
#initialize ⇒ WhoisParser
Returns a new instance of WhoisParser.
21 22 23 24 25 26 |
# 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 |
Instance Attribute Details
#attributes ⇒ Object
Instance variables
19 20 21 |
# File 'lib/pwhois.rb', line 19 def attributes @attributes end |
#output_style ⇒ Object
Instance variables
19 20 21 |
# File 'lib/pwhois.rb', line 19 def output_style @output_style end |
#verbose ⇒ Object
Instance variables
19 20 21 |
# File 'lib/pwhois.rb', line 19 def verbose @verbose end |
Instance Method Details
#get_attr(record, attr) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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) ⇒ Object
49 50 51 |
# File 'lib/pwhois.rb', line 49 def query(q) query_list([ q ]) end |
#query_list(querys) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# 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. end end if output_style == :table results.push(result) else print_item(result) end rescue Whois::ConnectionError => e $stderr.puts e. 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. $stderr.puts e.backtrace exit end end # querys.each if output_style == :table print_table(results) end end |