lib/whois/parsers/whois.registro.br.rb in whois-parser-1.0.1 vs lib/whois/parsers/whois.registro.br.rb in whois-parser-1.1.0
- old
+ new
@@ -1,31 +1,29 @@
#--
# Ruby Whois
#
# An intelligent pure Ruby WHOIS client and parser.
#
-# Copyright (c) 2009-2015 Simone Carletti <weppos@weppos.net>
+# Copyright (c) 2009-2018 Simone Carletti <weppos@weppos.net>
#++
require_relative 'base'
module Whois
class Parsers
- #
- # = whois.registro.br parser
- #
# Parser for the whois.registro.br 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.
- # See WhoisNicIt parser for an explanation of all available methods
- # and examples.
+ # @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.
#
+ # @see Whois::Parsers::Example
+ # The Example parser for the list of all available methods.
+ #
class WhoisRegistroBr < Base
property_supported :status do
if available?
:available
@@ -40,10 +38,11 @@
property_supported :registered? do
!available?
end
+
property_supported :created_on do
if content_for_scanner =~ /created:\s+(.+?)(\s+#.+)?\n/
parse_time($1)
end
end
@@ -58,16 +57,61 @@
if content_for_scanner =~ /expires:\s+(.+?)\n/
parse_time($1)
end
end
+
+ property_supported :registrant_contacts do
+ parse_contact("owner-c", Parser::Contact::TYPE_REGISTRANT)
+ end
+
+ property_supported :admin_contacts do
+ parse_contact("admin-c", Parser::Contact::TYPE_ADMINISTRATIVE)
+ end
+
+ property_supported :technical_contacts do
+ parse_contact("tech-c", Parser::Contact::TYPE_TECHNICAL)
+ end
+
+
property_supported :nameservers do
content_for_scanner.scan(/nserver:\s+(.+)\n/).flatten.map do |line|
name, ipv4 = line.strip.split(" ")
Parser::Nameserver.new(:name => name, :ipv4 => ipv4)
end
end
+
+ private
+
+ def parse_contact(element, type)
+ return unless content_for_scanner =~ /#{element}:\s+(.+)\n/
+
+ id = $1
+ content_for_scanner.scan(/nic-hdl-br:\s+#{id}\n((.+\n)+)\n/).any? ||
+ Whois.bug!(ParserError, "Unable to parse contact block for nic-hdl-br: #{id}")
+ values = build_hash($1.scan(/(.+?):\s+(.+?)\n/))
+
+ created_on = values["created"] ? Time.utc(*values["created"][0..3],*values["created"][4..5],*values["created"][6..7]) : nil
+ updated_on = values["changed"] ? Time.utc(*values["changed"][0..3],*values["changed"][4..5],*values["changed"][6..7]) : nil
+
+ Parser::Contact.new({
+ type: type,
+ id: id,
+ name: values["person"],
+ email: values["e-mail"],
+ created_on: created_on,
+ updated_on: updated_on
+ })
+ end
+
+ def build_hash(tokens)
+ {}.tap do |hash|
+ tokens.each do |key, value|
+ hash[key] = value
+ end
+ end
+ end
end
end
end