1

I'm new to Rails and wanted to try the Ruby Whois gem.

I defined an Active Record record that creates a report. That report would then be filled with data from the whois query (preferably parsed).

When I do the query I get something really weird. I've used ByeBug as a debugger:

$ (byebug) Whois.whois("google.it")

"\n*********************************************************************\n* Please note
 that the following result could be a subgroup of      *\n* the data contained in the database.    


    *\n*                                                                   *\n* Additional 
information can be visualized at:                      
*\n* http://www.nic.it/cgi-bin/Whois/whois.cgi
*\n*********************************************************************\n\nDomain:             google.it\nStatus:             ok\nCreated:            1999-12-10
00:00:00\nLast Update:        2014-05-07 00:52:45\nExpire Date:        2015-04-21\n
\nRegistrant\n  Name:             Google Ireland Holdings\n  Organization:     Google 
Ireland Holdings\n  ContactID:        DUP430692088\n  Address:          70 Sir John 
Rogersons Quay\n                    Dublin\n                    2\n                    
IE\n                    IE\n  Created:          2013-04-21 01:05:35\n  Last Update:      
2013-04-21 01:05:35\n\nAdmin Contact\n  Name:             Tsao Tu\n  Organization:     Tu 
Tsao\n  ContactID:        DUP142437129\n  Address:          70 Sir John Rogersons 
Quay\n                    Dublin\n                    2\n                    
IE\n                    IE\n  Created:          2013-04-21 01:05:35\n  Last Update:      
2013-04-21 01:05:35\n\nTechnical Contacts\n  Name:             Google Ireland Holdings\n  
Organization:     Google Ireland Holdings\n  ContactID:        DUP430692088\n  
Address:          70 Sir John Rogersons Quay\n                    
Dublin\n                    2\n                    IE\n                    IE\n  
Created:          2013-04-21 01:05:35\n  Last Update:      2013-04-21 01:05:35\n
\nRegistrar\n  Organization:     MarkMonitor International Limited\n  Name:             
MARKMONITOR-REG\n  Web:              https://www.markmonitor.com/\n\nNameservers\n  
ns1.google.com\n  ns4.google.com\n  ns2.google.com\n  ns3.google.com\n\n"



$ (byebug) Whois.whois("google.it").parser

#<Whois::Record::Parser:0x000000065bdc30 

    @record="\n*********************************************************************\n* 
Please note that the following result could be a subgroup of      *\n* the data contained 
in the database.                               
*\n*                                                                   *\n* Additional 
information can be visualized at:                      *\n* http://www.nic.it/cgi-bin/Whois
/whois.cgi
*\n*********************************************************************
\n\nDomain:             google.it\nStatus:             ok\nCreated:  1999-12-10
00:00:00\nLast Update:        2014-05-07 00:52:45\nExpire Date:        2015-04-21\n
\nRegistrant\n  Name:             Google Ireland Holdings\n  Organization:     Google 
Ireland Holdings\n  ContactID:        DUP430692088\n  Address:          70 Sir John 
Rogersons Quay\n                    Dublin\n                    2\n                    
IE\n                    IE\n  Created:          2013-04-21 01:05:35\n  Last Update:      
2013-04-21 01:05:35\n\nAdmin Contact\n  Name:             Tsao Tu\n  Organization:     Tu 
Tsao\n  ContactID:        DUP142437129\n  Address:          70 Sir John Rogersons 
Quay\n                    Dublin\n                    2\n                    
IE\n                    IE\n  Created:          2013-04-21 01:05:35\n  Last Update:      
2013-04-21 01:05:35\n\nTechnical Contacts\n  Name:             Google Ireland Holdings\n  Organization:     Google Ireland Holdings\n  ContactID:        DUP430692088\n  
Address:          70 Sir John Rogersons Quay\n                    
Dublin\n                    2\n                    IE\n                    IE\n  
Created:          2013-04-21 01:05:35\n  Last Update:      2013-04-21 01:05:35\n
\nRegistrar\n  Organization:     MarkMonitor International Limited\n  Name:             
MARKMONITOR-REG\n  Web:              https://www.markmonitor.com/\n\nNameservers\n  
ns1.google.com\n  ns4.google.com\n  ns2.google.com\n  ns3.google.com\n\n">

I would like to know what all this is about. It isn't structured anything like it would be in IRB or on a simple console.

And when I try looking at the properties it just tells me to buzz off:

$ (byebug) Whois.whois("google.it").property_supported?(:domain)

NoMethodError Exception: undefined method `property_supported?' for #<Whois::Record:0x000000065aba08>
nil

I'm on a virtual machine (Ubuntu precise64) running Rails 4.0, and Ruby version 2.1.2. The web server is the default Webrick.

All I'd like to do is get the object <Whois::Record> and extract the values from it, such as domain, domain_id, registrar and so on... any tips ?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Exos
  • 75
  • 6
  • tried to make the code readable but only got so far – Michael Durrant Sep 30 '14 at 12:22
  • Please take the time to use correct grammar and formatting. It makes your question a lot easier to read, which helps us help you solve the problem. *NOT* doing that only discourages potential answerers, who figure you didn't care enough to write a readable question so why should they care enough to try to help. – the Tin Man Sep 30 '14 at 16:14

2 Answers2

0
  1. The output in the console shows that making the call returns the output expected (setting @record).

  2. property_supported? didn't work because that method is not available on this type of object.

Also I've never heard of byebug.
Are you able to do rails console from the root of the application and try using objects there ?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
  • Well from what i understood, the rails debugger wasn't maintained for rails versions > 3.0 so i had to look for something else. Byebug is actually quite easy to use, well i wouldn't really know since i haven't tried any other debugger though. – Exos Sep 30 '14 at 14:14
  • [Byebug](https://github.com/deivid-rodriguez/byebug) is a very nice Ruby debugger for v2.0+ – the Tin Man Sep 30 '14 at 16:20
0

The #whois method returns a Whois::Record object which wraps the whois response string and provides parsing capabilities. The output you see in the console is just the object representation.

record = Whois.whois("google.it")
record.class
# => Whois::Record

The Record documentation explains you how to use the object. For instance, to print out its String representation, explicitly call puts or use .to_s.

puts record.to_s

If you need to access a specific property, there is no need to invoke the parser. Simply access the property.

record.expires_on
# => 2015-04-21 00:00:00 +0200

Make sure to read the library documentation.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
  • Can't believe i got stuck because of a Ruby non Rails basic thingy. Thank you so much ! And yeah i did check over and over the documentation but i guess there are some subtleties i will miss no matter... – Exos Sep 30 '14 at 14:16