Ruby Whois 0.8.1

October 23rd, 2009 at 11:44 pm • permalink0 comments

WhoisWhois 0.8.1 is now available. The new version of the GEM includes the compatibility with the new Denic response format and a small features to check whether the current answer supports a specific property.

For example, let’s suppose you want to create a basic whois interface and you need to display the creation and expiration dates for any domain entered by the user. Some whois responses don’t provide the registration date and if you try to access the created_on property the library will raise a PropertyNotSupported error.

a = Whois.query "google.be"
a.created_on
>> a.created_on
Whois::PropertyNotSupported: Unable to find a parser for `created_on'
	from /Library/Ruby/Gems/1.8/gems/whois-0.8.1/lib/whois/answer/parser.rb:73:in `method_missing'
	from /Library/Ruby/Gems/1.8/gems/whois-0.8.1/lib/whois/answer.rb:125:in `send'
	from /Library/Ruby/Gems/1.8/gems/whois-0.8.1/lib/whois/answer.rb:125:in `method_missing'
	from (irb):8

Prior to Whois 0.8.1 you would have to rescue the exception and the final code can get pretty messy. Now all you have to do is to check whether the answer supports the property with the supported? method.

a = Whois.query "google.be"
if a.supported? :created_on
  a.created_on
end

As usual, you can install/upgrade the library via RubyGems.

gem install whois
  1. New in Whois: Applying the Principle of Least Surprise
  2. New in Whois: property is set?
  3. Ruby Whois 0.8.0
  4. Whois 0.9.0: WHOIS parsers, CLI and performances
  5. Ruby Whois 1.0 is here!

Filed in Programming • Tags: , , ,

Add a Comment




Follow Me
    Random Quote