lib/whois/record/parser/whois.nic.fr.rb in whois-2.2.0 vs lib/whois/record/parser/whois.nic.fr.rb in whois-2.3.0

- old
+ new

@@ -1,24 +1,21 @@ #-- # Ruby Whois # # An intelligent pure Ruby WHOIS client and parser. # -# Copyright (c) 2009-2011 Simone Carletti <weppos@weppos.net> +# Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net> #++ require 'whois/record/parser/base' module Whois class Record class Parser - # - # = whois.nic.fr parser - # # Parser for the whois.nic.fr server. # # NOTE: This parser is just a stub and provides only a few basic methods # to check for domain availability and get domain status. # Please consider to contribute implementing missing methods. @@ -28,18 +25,24 @@ class WhoisNicFr < Base property_supported :status do if content_for_scanner =~ /status:\s+(.+)\n/ case $1.downcase - when "active" then :registered - when "registered" then :registered - when "redemption" then :redemption - when "blocked" then :inactive - # NEWSTATUS (reserved) - when "frozen" then :frozen - else - Whois.bug!(ParserError, "Unknown status `#{$1}'.") + when "active" then :registered + when "registered" then :registered + when "redemption" then :redemption + when "blocked" then :inactive + # The 'frozen' status seems to be a status + # where a registered domain is placed to prevent changes + # and/or when changes can't be made. + when "frozen" then :registered + # The 'not_open' status seems to indicate a domain + # that is already reserved and can't be registered directly. + # This is the case of second level names. + when "not_open" then :reserved + else + Whois.bug!(ParserError, "Unknown status `#{$1}'.") end else :available end end @@ -85,20 +88,31 @@ property_supported :nameservers do content_for_scanner.scan(/nserver:\s+(.+)\n/).flatten.map do |line| if line =~ /(.+) \[(.+)\]/ - Record::Nameserver.new($1, *$2.split(/\s+/)) + name = $1 + ips = $2.split(/\s+/) + ipv4 = ips.find { |ip| Whois::Server.valid_ipv4?(ip) } + ipv6 = ips.find { |ip| Whois::Server.valid_ipv6?(ip) } + Record::Nameserver.new(:name => name, :ipv4 => ipv4, :ipv6 => ipv6) else - Record::Nameserver.new(line) + Record::Nameserver.new(:name => line) end end end + # Checks whether the response has been throttled. + # + # @return [Boolean] + def response_throttled? + !!(content_for_scanner =~ /^%% Too many requests\.{3}/) + end - private + private + MULTIVALUE_KEYS = %w( address ) def parse_contact(element, type) return unless content_for_scanner =~ /#{element}:\s+(.+)\n/ @@ -111,15 +125,18 @@ name = nil organization = values["contact"] address = values["address"].join("\n") else name = values["contact"] - if values["address"].size > 2 + if values["address"].nil? + organization = nil + address = nil + elsif values["address"].size > 2 organization = values["address"][0] - address = values["address"][1..-1].join("\n") + address = values["address"][1..-1].join("\n") else organization = nil - address = values["address"].join("\n") + address = values["address"].join("\n") end end Record::Contact.new({ :type => type,