Permalink
Browse files

Added contacts parsing for whois.ua

  • Loading branch information...
1 parent 9cb7c05 commit b7a1bd80d5f89954acf7ecec21297d89cd1384ec @Uko Uko committed May 31, 2012
@@ -83,12 +83,56 @@ class WhoisUa < Base
property_not_supported :registrar
+
+ property_not_supported :registrant_contacts
+
+ property_supported :admin_contacts do
+ build_contact("Administrative", Whois::Record::Contact::TYPE_ADMIN)
+ end
+
+ property_supported :technical_contacts do
+ build_contact("Technical", Whois::Record::Contact::TYPE_TECHNICAL)
+ end
+
+
property_supported :nameservers do
content_for_scanner.scan(/nserver:\s+(.+)\n/).flatten.map do |name|
Record::Nameserver.new(:name => name.strip.downcase)
end
end
+ private
+
+
+ def build_contact(element, type)
+ record = []
+ content_for_scanner.scan(/%\s#{element}\sContact:\n %\s=+\n ((?: .+\n)+) (?: \n|\z)/ix).flatten.each do |match|
+ address = match.scan(/address:\s+(.+)\n/).flatten
+ zip = nil
+ zip = address[1].slice!(/\s+\d{5}/).strip if address[1] =~ /\s+\d{5}/
+ zip = address[1].slice!(/\d{5}\s+/).strip if address[1] =~ /\d{5}\s+/
+ state = nil
+ state = address[1].slice!(/\s+[A-Z]{2}\z/).strip if address[1] =~ /\s+[A-Z]{2}\z/
+
+ record.push Record::Contact.new(
+ :type => type,
+ :id => match[/org-id:\s+(.+)\n/,1],
+ :name => nil,
+ :organization => match.scan(/organization:\s+(.+)\n/).join("\n"),
+ :address => address[0],
+ :zip => zip,
+ :state => state,
+ :city => address[1],
+ :country => address[2],
+ :phone => match[/phone:\s+(.+)\n/,1],
+ :fax => match[/fax-no:\s+(.+)\n/,1],
+ :email => match[/e-mail:\s+(.+)\n/,1],
+ :updated_on => (Time.parse($1.split(" ").last) if match =~ /changed:\s+(.+)\n/)
+ )
+ end
+ record
+ end
+
end
end
@@ -29,6 +29,16 @@
#expires_on
should: %s == nil
+#registrant_contacts
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+#admin_contacts
+ should: %s CLASS(array)
+ should: %s == []
+
+#technical_contacts
+ should: %s CLASS(array)
+ should: %s == []
#registrar
should: %s raise_error(Whois::PropertyNotSupported)
@@ -36,6 +36,48 @@
#registrar
should: %s raise_error(Whois::PropertyNotSupported)
+#registrant_contacts
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+#admin_contacts
+ should: %s CLASS(array)
+ should: %s SIZE(1)
+ should: %s[0] CLASS(contact)
+ should: %s[0].type == Whois::Record::Contact::TYPE_ADMIN
+ should: %s[0].id == "N/A"
+ should: %s[0].name == nil
+ should: %s[0].organization == "Google Inc."
+ should: %s[0].address == "1600 Amphitheatre Parkway"
+ should: %s[0].city == "Mountain View"
+ should: %s[0].zip == "94043"
+ should: %s[0].state == "CA"
+ should: %s[0].country == "US"
+ should: %s[0].country_code == nil
+ should: %s[0].phone == "+1 6503300100"
+ should: %s[0].fax == "+1 6506188571"
+ should: %s[0].email == "dns-admin@google.com"
+ should: %s[0].created_on == nil
+ should: %s[0].updated_on == Time.parse("2012-02-01 21:09:42")
+
+#technical_contacts
+ should: %s CLASS(array)
+ should: %s SIZE(1)
+ should: %s[0] CLASS(contact)
+ should: %s[0].type == Whois::Record::Contact::TYPE_TECHNICAL
+ should: %s[0].id == "N/A"
+ should: %s[0].name == nil
+ should: %s[0].organization == "Google Inc."
+ should: %s[0].address == "1600 Amphitheatre Parkway"
+ should: %s[0].city == "Mountain View"
+ should: %s[0].zip == "94043"
+ should: %s[0].state == "CA"
+ should: %s[0].country == "US"
+ should: %s[0].country_code == nil
+ should: %s[0].phone == "+1 6503300100"
+ should: %s[0].fax == "+1 6506188571"
+ should: %s[0].email == "dns-admin@google.com"
+ should: %s[0].created_on == nil
+ should: %s[0].updated_on == Time.parse("2012-02-01 21:09:42")
#nameservers
should: %s CLASS(array)
@@ -71,6 +71,23 @@
@parser.expires_on.should == nil
end
end
+ describe "#registrant_contacts" do
+ it do
+ lambda { @parser.registrant_contacts }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#admin_contacts" do
+ it do
+ @parser.admin_contacts.should be_a(Array)
+ @parser.admin_contacts.should == []
+ end
+ end
+ describe "#technical_contacts" do
+ it do
+ @parser.technical_contacts.should be_a(Array)
+ @parser.technical_contacts.should == []
+ end
+ end
describe "#registrar" do
it do
lambda { @parser.registrar }.should raise_error(Whois::PropertyNotSupported)
@@ -79,6 +79,55 @@
lambda { @parser.registrar }.should raise_error(Whois::PropertyNotSupported)
end
end
+ describe "#registrant_contacts" do
+ it do
+ lambda { @parser.registrant_contacts }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#admin_contacts" do
+ it do
+ @parser.admin_contacts.should be_a(Array)
+ @parser.admin_contacts.should have(1).items
+ @parser.admin_contacts[0].should be_a(Whois::Record::Contact)
+ @parser.admin_contacts[0].type.should == Whois::Record::Contact::TYPE_ADMIN
+ @parser.admin_contacts[0].id.should == "N/A"
+ @parser.admin_contacts[0].name.should == nil
+ @parser.admin_contacts[0].organization.should == "Google Inc."
+ @parser.admin_contacts[0].address.should == "1600 Amphitheatre Parkway"
+ @parser.admin_contacts[0].city.should == "Mountain View"
+ @parser.admin_contacts[0].zip.should == "94043"
+ @parser.admin_contacts[0].state.should == "CA"
+ @parser.admin_contacts[0].country.should == "US"
+ @parser.admin_contacts[0].country_code.should == nil
+ @parser.admin_contacts[0].phone.should == "+1 6503300100"
+ @parser.admin_contacts[0].fax.should == "+1 6506188571"
+ @parser.admin_contacts[0].email.should == "dns-admin@google.com"
+ @parser.admin_contacts[0].created_on.should == nil
+ @parser.admin_contacts[0].updated_on.should == Time.parse("2012-02-01 21:09:42")
+ end
+ end
+ describe "#technical_contacts" do
+ it do
+ @parser.technical_contacts.should be_a(Array)
+ @parser.technical_contacts.should have(1).items
+ @parser.technical_contacts[0].should be_a(Whois::Record::Contact)
+ @parser.technical_contacts[0].type.should == Whois::Record::Contact::TYPE_TECHNICAL
+ @parser.technical_contacts[0].id.should == "N/A"
+ @parser.technical_contacts[0].name.should == nil
+ @parser.technical_contacts[0].organization.should == "Google Inc."
+ @parser.technical_contacts[0].address.should == "1600 Amphitheatre Parkway"
+ @parser.technical_contacts[0].city.should == "Mountain View"
+ @parser.technical_contacts[0].zip.should == "94043"
+ @parser.technical_contacts[0].state.should == "CA"
+ @parser.technical_contacts[0].country.should == "US"
+ @parser.technical_contacts[0].country_code.should == nil
+ @parser.technical_contacts[0].phone.should == "+1 6503300100"
+ @parser.technical_contacts[0].fax.should == "+1 6506188571"
+ @parser.technical_contacts[0].email.should == "dns-admin@google.com"
+ @parser.technical_contacts[0].created_on.should == nil
+ @parser.technical_contacts[0].updated_on.should == Time.parse("2012-02-01 21:09:42")
+ end
+ end
describe "#nameservers" do
it do
@parser.nameservers.should be_a(Array)
@@ -71,6 +71,23 @@
@parser.expires_on.should == nil
end
end
+ describe "#registrant_contacts" do
+ it do
+ lambda { @parser.registrant_contacts }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#admin_contacts" do
+ it do
+ @parser.admin_contacts.should be_a(Array)
+ @parser.admin_contacts.should == []
+ end
+ end
+ describe "#technical_contacts" do
+ it do
+ @parser.technical_contacts.should be_a(Array)
+ @parser.technical_contacts.should == []
+ end
+ end
describe "#registrar" do
it do
lambda { @parser.registrar }.should raise_error(Whois::PropertyNotSupported)
@@ -79,6 +79,55 @@
lambda { @parser.registrar }.should raise_error(Whois::PropertyNotSupported)
end
end
+ describe "#registrant_contacts" do
+ it do
+ lambda { @parser.registrant_contacts }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#admin_contacts" do
+ it do
+ @parser.admin_contacts.should be_a(Array)
+ @parser.admin_contacts.should have(1).items
+ @parser.admin_contacts[0].should be_a(Whois::Record::Contact)
+ @parser.admin_contacts[0].type.should == Whois::Record::Contact::TYPE_ADMIN
+ @parser.admin_contacts[0].id.should == "N/A"
+ @parser.admin_contacts[0].name.should == nil
+ @parser.admin_contacts[0].organization.should == "Google Inc."
+ @parser.admin_contacts[0].address.should == "1600 Amphitheatre Parkway"
+ @parser.admin_contacts[0].city.should == "Mountain View"
+ @parser.admin_contacts[0].zip.should == "94043"
+ @parser.admin_contacts[0].state.should == "CA"
+ @parser.admin_contacts[0].country.should == "US"
+ @parser.admin_contacts[0].country_code.should == nil
+ @parser.admin_contacts[0].phone.should == "+1 6503300100"
+ @parser.admin_contacts[0].fax.should == "+1 6506188571"
+ @parser.admin_contacts[0].email.should == "dns-admin@google.com"
+ @parser.admin_contacts[0].created_on.should == nil
+ @parser.admin_contacts[0].updated_on.should == Time.parse("2012-02-01 21:09:42")
+ end
+ end
+ describe "#technical_contacts" do
+ it do
+ @parser.technical_contacts.should be_a(Array)
+ @parser.technical_contacts.should have(1).items
+ @parser.technical_contacts[0].should be_a(Whois::Record::Contact)
+ @parser.technical_contacts[0].type.should == Whois::Record::Contact::TYPE_TECHNICAL
+ @parser.technical_contacts[0].id.should == "N/A"
+ @parser.technical_contacts[0].name.should == nil
+ @parser.technical_contacts[0].organization.should == "Google Inc."
+ @parser.technical_contacts[0].address.should == "1600 Amphitheatre Parkway"
+ @parser.technical_contacts[0].city.should == "Mountain View"
+ @parser.technical_contacts[0].zip.should == "94043"
+ @parser.technical_contacts[0].state.should == "CA"
+ @parser.technical_contacts[0].country.should == "US"
+ @parser.technical_contacts[0].country_code.should == nil
+ @parser.technical_contacts[0].phone.should == "+1 6503300100"
+ @parser.technical_contacts[0].fax.should == "+1 6506188571"
+ @parser.technical_contacts[0].email.should == "dns-admin@google.com"
+ @parser.technical_contacts[0].created_on.should == nil
+ @parser.technical_contacts[0].updated_on.should == Time.parse("2012-02-01 21:09:42")
+ end
+ end
describe "#nameservers" do
it do
@parser.nameservers.should be_a(Array)

0 comments on commit b7a1bd8

Please sign in to comment.