Skip to content

Commit

Permalink
Add contacts support to whois.registro.br parser
Browse files Browse the repository at this point in the history
Closes GH-31

Squashed commit of the following:

commit 0ede837311b03fecacd79efa42bd47b29ab6f419
Merge: 4c7ea09 44ddefc
Author: Simone Carletti <weppos@weppos.net>
Date:   Mon Mar 26 17:51:44 2018 +0200

    Fix conflicts

commit 44ddefc
Author: Leandro Forain <forain@gmail.com>
Date:   Wed Jun 15 18:48:55 2016 -0300

    Add contacts support to whois.registro.br parser
  • Loading branch information
weppos committed Mar 26, 2018
1 parent 4c7ea09 commit 4735428
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 16 deletions.
14 changes: 6 additions & 8 deletions lib/whois/parsers/whois.registre.ma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
module Whois
class Parsers

#
# = whois.registre.ma parser
#
# Parser for the whois.registre.ma 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 WhoisRegistreMa < Base

Expand Down
60 changes: 52 additions & 8 deletions lib/whois/parsers/whois.registro.br.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
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

Expand All @@ -42,6 +40,7 @@ class WhoisRegistroBr < Base
!available?
end


property_supported :created_on do
if content_for_scanner =~ /created:\s+(.+?)(\s+#.+)?\n/
parse_time($1)
Expand All @@ -60,13 +59,58 @@ class WhoisRegistroBr < Base
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,67 @@
%s %TIME{2018-05-18}


#registrant_contacts
%s %CLASS{array}
%s %SIZE{1}
%s[0] %CLASS{contact}
%s[0].type == Whois::Parser::Contact::TYPE_REGISTRANT
%s[0].id == "DOADM17"
%s[0].name == "Domain Admin"
%s[0].organization == nil
%s[0].address == nil
%s[0].city == nil
%s[0].state == nil
%s[0].zip == nil
%s[0].country == nil
%s[0].country_code == nil
%s[0].phone == nil
%s[0].fax == nil
%s[0].email == "ccops@markmonitor.com"
%s[0].created_on %TIME{2010-05-20 00:00:00 UTC}
%s[0].updated_on %TIME{2017-01-03 00:00:00 UTC}

#admin_contacts
%s %CLASS{array}
%s %SIZE{1}
%s[0] %CLASS{contact}
%s[0].type == Whois::Parser::Contact::TYPE_ADMINISTRATIVE
%s[0].id == "DOADM17"
%s[0].name == "Domain Admin"
%s[0].organization == nil
%s[0].address == nil
%s[0].city == nil
%s[0].state == nil
%s[0].zip == nil
%s[0].country == nil
%s[0].country_code == nil
%s[0].phone == nil
%s[0].fax == nil
%s[0].email == "ccops@markmonitor.com"
%s[0].created_on %TIME{2010-05-20 00:00:00 UTC}
%s[0].updated_on %TIME{2017-01-03 00:00:00 UTC}

#technical_contacts
%s %CLASS{array}
%s %SIZE{1}
%s[0] %CLASS{contact}
%s[0].type == Whois::Parser::Contact::TYPE_TECHNICAL
%s[0].id == "DOADM17"
%s[0].name == "Domain Admin"
%s[0].organization == nil
%s[0].address == nil
%s[0].city == nil
%s[0].state == nil
%s[0].zip == nil
%s[0].country == nil
%s[0].country_code == nil
%s[0].phone == nil
%s[0].fax == nil
%s[0].email == "ccops@markmonitor.com"
%s[0].created_on %TIME{2010-05-20 00:00:00 UTC}
%s[0].updated_on %TIME{2017-01-03 00:00:00 UTC}


#nameservers
%s %CLASS{array}
%s %SIZE{4}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,72 @@
expect(subject.expires_on).to eq(Time.parse("2018-05-18"))
end
end
describe "#registrant_contacts" do
it do
expect(subject.registrant_contacts).to be_a(Array)
expect(subject.registrant_contacts.size).to eq(1)
expect(subject.registrant_contacts[0]).to be_a(Whois::Parser::Contact)
expect(subject.registrant_contacts[0].type).to eq(Whois::Parser::Contact::TYPE_REGISTRANT)
expect(subject.registrant_contacts[0].id).to eq("DOADM17")
expect(subject.registrant_contacts[0].name).to eq("Domain Admin")
expect(subject.registrant_contacts[0].organization).to eq(nil)
expect(subject.registrant_contacts[0].address).to eq(nil)
expect(subject.registrant_contacts[0].city).to eq(nil)
expect(subject.registrant_contacts[0].state).to eq(nil)
expect(subject.registrant_contacts[0].zip).to eq(nil)
expect(subject.registrant_contacts[0].country).to eq(nil)
expect(subject.registrant_contacts[0].country_code).to eq(nil)
expect(subject.registrant_contacts[0].phone).to eq(nil)
expect(subject.registrant_contacts[0].fax).to eq(nil)
expect(subject.registrant_contacts[0].email).to eq("ccops@markmonitor.com")
expect(subject.registrant_contacts[0].created_on).to eq(Time.parse("2010-05-20 00:00:00 UTC"))
expect(subject.registrant_contacts[0].updated_on).to eq(Time.parse("2017-01-03 00:00:00 UTC"))
end
end
describe "#admin_contacts" do
it do
expect(subject.admin_contacts).to be_a(Array)
expect(subject.admin_contacts.size).to eq(1)
expect(subject.admin_contacts[0]).to be_a(Whois::Parser::Contact)
expect(subject.admin_contacts[0].type).to eq(Whois::Parser::Contact::TYPE_ADMINISTRATIVE)
expect(subject.admin_contacts[0].id).to eq("DOADM17")
expect(subject.admin_contacts[0].name).to eq("Domain Admin")
expect(subject.admin_contacts[0].organization).to eq(nil)
expect(subject.admin_contacts[0].address).to eq(nil)
expect(subject.admin_contacts[0].city).to eq(nil)
expect(subject.admin_contacts[0].state).to eq(nil)
expect(subject.admin_contacts[0].zip).to eq(nil)
expect(subject.admin_contacts[0].country).to eq(nil)
expect(subject.admin_contacts[0].country_code).to eq(nil)
expect(subject.admin_contacts[0].phone).to eq(nil)
expect(subject.admin_contacts[0].fax).to eq(nil)
expect(subject.admin_contacts[0].email).to eq("ccops@markmonitor.com")
expect(subject.admin_contacts[0].created_on).to eq(Time.parse("2010-05-20 00:00:00 UTC"))
expect(subject.admin_contacts[0].updated_on).to eq(Time.parse("2017-01-03 00:00:00 UTC"))
end
end
describe "#technical_contacts" do
it do
expect(subject.technical_contacts).to be_a(Array)
expect(subject.technical_contacts.size).to eq(1)
expect(subject.technical_contacts[0]).to be_a(Whois::Parser::Contact)
expect(subject.technical_contacts[0].type).to eq(Whois::Parser::Contact::TYPE_TECHNICAL)
expect(subject.technical_contacts[0].id).to eq("DOADM17")
expect(subject.technical_contacts[0].name).to eq("Domain Admin")
expect(subject.technical_contacts[0].organization).to eq(nil)
expect(subject.technical_contacts[0].address).to eq(nil)
expect(subject.technical_contacts[0].city).to eq(nil)
expect(subject.technical_contacts[0].state).to eq(nil)
expect(subject.technical_contacts[0].zip).to eq(nil)
expect(subject.technical_contacts[0].country).to eq(nil)
expect(subject.technical_contacts[0].country_code).to eq(nil)
expect(subject.technical_contacts[0].phone).to eq(nil)
expect(subject.technical_contacts[0].fax).to eq(nil)
expect(subject.technical_contacts[0].email).to eq("ccops@markmonitor.com")
expect(subject.technical_contacts[0].created_on).to eq(Time.parse("2010-05-20 00:00:00 UTC"))
expect(subject.technical_contacts[0].updated_on).to eq(Time.parse("2017-01-03 00:00:00 UTC"))
end
end
describe "#nameservers" do
it do
expect(subject.nameservers).to be_a(Array)
Expand Down

0 comments on commit 4735428

Please sign in to comment.