Permalink
Browse files

Add .DM server and parser (closes GH-43)

  • Loading branch information...
1 parent 7e2a99a commit ee05af985b22586cd3b512d033f026a7e9cb02d5 @weppos committed Sep 9, 2012
View
@@ -8,6 +8,8 @@
* SERVER: Added .BI TLD server (GH-113).
+* SERVER: Added .DM TLD server (GH-43).
+
* NEW: Added full whois.register.com parser.
* NEW: Added full whois.tucows.com parser.
@@ -18,6 +20,8 @@
* NEW: Added full whois1.nic.bi parser (GH-113).
+* NEW: Added full whois.nic.dm parser (GH-43).
+
* FIXED: Fixed whois.register.com parser for enom formats (GH-181). [Thanks @JustinCampbell]
* FIXED: whois.jprs.js parser should support status `Suspended`.
@@ -0,0 +1,142 @@
+#--
+# Ruby Whois
+#
+# An intelligent pure Ruby WHOIS client and parser.
+#
+# Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
+#++
+
+
+require 'whois/record/parser/base'
+require 'whois/record/scanners/whois.nic.dm.rb'
+
+
+module Whois
+ class Record
+ class Parser
+
+ # Parser for the whois.nic.dm server.
+ #
+ # @see Whois::Record::Parser::Example
+ # The Example parser for the list of all available methods.
+ #
+ # @since RELEASE
+ class WhoisNicDm < Base
+ include Scanners::Ast
+
+ property_supported :disclaimer do
+ node("field:disclaimer")
+ end
+
+
+ property_supported :domain do
+ node("domain name", &:downcase)
+ end
+
+ property_not_supported :domain_id
+
+
+ property_not_supported :referral_whois
+
+ property_not_supported :referral_url
+
+
+ property_supported :status do
+ if available?
+ :available
+ else
+ :registered
+ end
+ end
+
+ property_supported :available? do
+ !!node("status:available")
+ end
+
+ property_supported :registered? do
+ !available?
+ end
+
+
+ property_supported :created_on do
+ node("created date") { |value| Time.parse(value) }
+ end
+
+ property_supported :updated_on do
+ node("updated date") { |value| Time.parse(value) }
+ end
+
+ property_supported :expires_on do
+ node("expiration date") { |value| Time.parse(value) }
+ end
+
+
+ property_supported :registrar do
+ node("registrar") do |raw|
+ Record::Registrar.new(
+ :id => nil,
+ :name => node("registrar"),
+ :organization => nil,
+ :url => node("url")
+ )
+ end
+ end
+
+ property_supported :registrant_contacts do
+ build_contact("owner", Whois::Record::Contact::TYPE_REGISTRANT)
+ end
+
+ property_supported :admin_contacts do
+ build_contact("admin", Whois::Record::Contact::TYPE_ADMIN)
+ end
+
+ property_supported :technical_contacts do
+ build_contact("tech", Whois::Record::Contact::TYPE_TECHNICAL)
+ end
+
+
+ property_supported :nameservers do
+ node("nameserver") do |array|
+ array.map do |name|
+ Nameserver.new(:name => name)
+ end
+ end
+ end
+
+
+ # Initializes a new {Scanners::WhoisDnsHr} instance
+ # passing the {#content_for_scanner}
+ # and calls +parse+ on it.
+ #
+ # @return [Hash]
+ def parse
+ Scanners::WhoisNicDm.new(content_for_scanner).parse
+ end
+
+
+ private
+
+ def build_contact(element, type)
+ node("#{element}-contact") do |raw|
+ Record::Contact.new(
+ :type => type,
+ :id => node("#{element}-contact"),
+ :name => node("#{element}-name"),
+ :organization => node("#{element}-organization"),
+ :address => node("#{element}-street"),
+ :city => node("#{element}-city"),
+ :zip => node("#{element}-zip"),
+ :state => nil,
+ :country_code => node("#{element}-country"),
+ :phone => nil,
+ :fax => nil,
+ :email => nil
+ )
+ end
+ end
+
+ end
+
+ end
+ end
+end
@@ -66,7 +66,6 @@ class WhoisRegistryQa < Base
end
end
-
property_supported :registrant_contacts do
build_contact("Registrant Contact", Whois::Record::Contact::TYPE_REGISTRANT)
end
@@ -0,0 +1,52 @@
+#--
+# Ruby Whois
+#
+# An intelligent pure Ruby WHOIS client and parser.
+#
+# Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
+#++
+
+
+require 'whois/record/scanners/base'
+
+
+module Whois
+ class Record
+ module Scanners
+
+ # Scanner for the whois.nic.dm record.
+ #
+ # @since RELEASE
+ class WhoisNicDm < Base
+
+ self.tokenizers += [
+ :scan_disclaimer,
+ :skip_empty_line,
+ :skip_comment,
+ :scan_available,
+ :scan_keyvalue,
+ ]
+
+
+ tokenizer :skip_comment do
+ @input.skip(/^;.*\n/)
+ end
+
+ tokenizer :scan_available do
+ if @input.skip(/^not found.+\n/)
+ @ast["status:available"] = true
+ end
+ end
+
+ tokenizer :scan_disclaimer do
+ if @input.pos == 0 && @input.match?(/^;.*/)
+ @ast["field:disclaimer"] = _scan_lines_to_array(/^;(.*)\n/).join(" ")
+ @ast["field:disclaimer"].gsub!(" ", "\n")
+ end
+ end
+
+ end
+
+ end
+ end
+end
@@ -0,0 +1,57 @@
+#disclaimer
+ should: %s == nil
+
+
+#domain
+ should: %s == nil
+
+#domain_id
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+
+#referral_whois
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+#referral_url
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+
+#status
+ should: %s == :available
+
+#available?
+ should: %s == true
+
+#registered?
+ should: %s == false
+
+
+#created_on
+ should: %s == nil
+
+#updated_on
+ should: %s == nil
+
+#expires_on
+ should: %s == nil
+
+
+#registrar
+ should: %s == nil
+
+#registrant_contacts
+ should: %s CLASS(array)
+ should: %s == []
+
+#admin_contacts
+ should: %s CLASS(array)
+ should: %s == []
+
+#technical_contacts
+ should: %s CLASS(array)
+ should: %s == []
+
+
+#nameservers
+ should: %s CLASS(array)
+ should: %s == []
@@ -0,0 +1,2 @@
+
+not found...
@@ -0,0 +1,111 @@
+#disclaimer
+ should: %s == "This data is provided by DM REGISTRY for information purposes only in accordance with the DM REGISTRY TLD Privacy Policy. It is intended to assist persons to obtain information about or related to domain name registration records. DM REGISTRY does not guarantee its accuracy. By submitting this query, you agree to abide as follows:\nYou agree to use this data only for lawful purposes and that under no circumstances will you permit this data to 1) allow, enable, or otherwise support the transmission of mass unsolicited, commercial advertising or solicitations via e-mail, telephone or fax (spam); nor 2) enable high volume, automated, electronic processes to the systems of DM REGISTRY or Registrars, except as reasonably required to register new domain names or modify existing registrations; nor 3) will you generate a database of registered domain names and registrant data.\nThese terms may be changed without prior notice. By submitting this query, you agree to abide by this policy."
+
+
+#domain
+ should: %s == "google.dm"
+
+#domain_id
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+
+#referral_whois
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+#referral_url
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+
+#status
+ should: %s == :registered
+
+#available?
+ should: %s == false
+
+#registered?
+ should: %s == true
+
+
+#created_on
+ should: %s CLASS(time)
+ should: %s == Time.parse("2004-08-23 23:00:00")
+
+#updated_on
+ should: %s CLASS(time)
+ should: %s == Time.parse("2012-07-25 19:49:18")
+
+#expires_on
+ should: %s CLASS(time)
+ should: %s == Time.parse("2013-08-23 23:00:00")
+
+
+#registrar
+ should: %s CLASS(registrar)
+ should: %s.id == nil
+ should: %s.name == "MarkMonitor Inc."
+ should: %s.organization == nil
+ should: %s.url == "www.markmonitor.com"
+
+#registrant_contacts
+ should: %s CLASS(array)
+ should: %s SIZE(1)
+ should: %s[0] CLASS(contact)
+ should: %s[0].type == Whois::Record::Contact::TYPE_REGISTRANT
+ should: %s[0].id == "P-CQG21"
+ should: %s[0].name == "Company Google Inc."
+ should: %s[0].organization == nil
+ should: %s[0].address == "1600 Amphitheatre Parkway"
+ should: %s[0].city == "Mountain View"
+ should: %s[0].zip == "94043"
+ should: %s[0].state == nil
+ should: %s[0].country_code == "US"
+ should: %s[0].phone == nil
+ should: %s[0].fax == nil
+ should: %s[0].email == nil
+
+#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 == "P-DNA22"
+ should: %s[0].name == "DNS Admin"
+ should: %s[0].organization == "Google Inc."
+ should: %s[0].address == "1600 Amphitheatre"
+ should: %s[0].city == "Mountain View"
+ should: %s[0].zip == "94043"
+ should: %s[0].state == nil
+ should: %s[0].country_code == "US"
+ should: %s[0].phone == nil
+ should: %s[0].fax == nil
+ should: %s[0].email == nil
+
+#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 == "P-DXA21"
+ should: %s[0].name == "DNS Admin"
+ should: %s[0].organization == "Google Inc."
+ should: %s[0].address == "1600 Amphitheatre"
+ should: %s[0].city == "Mountain View"
+ should: %s[0].zip == "94043"
+ should: %s[0].state == nil
+ should: %s[0].country_code == "US"
+ should: %s[0].phone == nil
+ should: %s[0].fax == nil
+ should: %s[0].email == nil
+
+
+#nameservers
+ should: %s CLASS(array)
+ should: %s SIZE(4)
+ should: %s[0] CLASS(nameserver)
+ should: %s[0].name == "ns1.google.com"
+ should: %s[1] CLASS(nameserver)
+ should: %s[1].name == "ns2.google.com"
+ should: %s[2] CLASS(nameserver)
+ should: %s[2].name == "ns3.google.com"
+ should: %s[3] CLASS(nameserver)
+ should: %s[3].name == "ns4.google.com"
Oops, something went wrong.

0 comments on commit ee05af9

Please sign in to comment.