Permalink
Browse files

Update whois.sx parser to the new response format.

  • Loading branch information...
1 parent b73890a commit 65a661a0436861283924865c4ee3e0cd627c874f @weppos committed Nov 22, 2012
View
@@ -61,6 +61,8 @@
- CHANGED: Updated whois.nic.pr parser to the new response format.
+- CHANGED: Updated whois.sx parser to the new response format.
+
- FIXED: whois.domainregistry.ie should support status `Active - LOCKED`.
- FIXED: whois.nic.uk fails to parse registrars without URL (GH-188).
@@ -24,21 +24,26 @@ class Parser
class WhoisSx < Base
include Scanners::Nodable
- property_not_supported :disclaimer
+ property_supported :disclaimer do
+ node("field:disclaimer")
+ end
property_supported :domain do
- "#{node('Domain')}.sx"
+ node("Domain Name", &:downcase)
end
- property_not_supported :domain_id
+ property_supported :domain_id do
+ node("Domain ID")
+ end
property_supported :status do
- case (s = node('Status'))
- when /free/
+ s = node("Domain Status")
+ case
+ when node("status:available")
:available
- when 'active'
+ when s == "ok"
:registered
else
Whois.bug!(ParserError, "Unknown status `#{s}'.")
@@ -54,37 +59,44 @@ class WhoisSx < Base
end
- property_not_supported :created_on
+ property_supported :created_on do
+ node("Creation Date") { |value| parse_time(value) }
+ end
- property_not_supported :updated_on
+ property_supported :updated_on do
+ node("Updated Date") { |value| parse_time(value) }
+ end
- property_not_supported :expires_on
+ property_supported :expires_on do
+ node("Registry Expiry Date") { |value| parse_time(value) }
+ end
property_supported :registrar do
- node('Registrar') do |hash|
+ node("Sponsoring Registrar") do |value|
Record::Registrar.new(
- :name => hash['Name'],
- :url => hash['Website']
+ :name => value
)
end
end
property_supported :registrant_contacts do
- build_contact('Registrant', Whois::Record::Contact::TYPE_REGISTRANT)
+ build_contact("Registrant", Whois::Record::Contact::TYPE_REGISTRANT)
end
- property_not_supported :admin_contacts
+ property_supported :admin_contacts do
+ build_contact("Admin", Whois::Record::Contact::TYPE_ADMIN)
+ end
- property_not_supported :technical_contacts
+ property_supported :technical_contacts do
+ build_contact("Tech", Whois::Record::Contact::TYPE_TECHNICAL)
+ end
property_supported :nameservers do
- node('Name servers') do |names|
- names.map do |name|
- Record::Nameserver.new(:name => name)
- end
+ Array.wrap(node("Name Server")).map do |name|
+ Record::Nameserver.new(:name => name)
end
end
@@ -101,13 +113,23 @@ def parse
private
+ def parse_time(value)
+ # Hack to remove usec. Do you know a better way?
+ Time.utc(*Time.parse(value).to_a)
+ end
+
def build_contact(element, type)
- node("#{element}") do |array|
+ node("#{element} ID") do |id|
Record::Contact.new(
:type => type,
- :id => nil,
- :name => array[0],
- :email => nil
+ :id => id,
+ :name => node("#{element} Name"),
+ :organization => node("#{element} Organization"),
+ :address => node("#{element} Street"),
+ :city => node("#{element} City"),
+ :zip => node("#{element} Postal Code"),
+ :country => node("#{element} Country"),
+ :email => node("#{element} Email")
)
end
end
@@ -8,7 +8,6 @@
require 'whois/record/scanners/base'
-require 'whois/record/scanners/base_shared2'
module Whois
@@ -14,63 +14,31 @@ module Whois
class Record
module Scanners
- # Scanner for the whois.sx record.
- #
- # @since 2.6.2
class WhoisSx < Base
self.tokenizers += [
- :skip_header,
- :skip_comments,
- :skip_empty_line,
- :flag_section_start,
- :flag_section_end,
- :scan_section,
+ :skip_blank_line,
+ :scan_available,
:scan_keyvalue,
+ :skip_lastupdate,
+ :scan_disclaimer,
]
- tokenizer :skip_header do
- if @input.pos == 0 && @input.match?(/^\[/)
- @input.skip_until(/\n/)
+ tokenizer :scan_available do
+ if @input.scan(/^Status: AVAILABLE \(No match for domain "(.+)"\)\n/)
+ @ast["Domain Name"] = @input[1]
+ @ast["status:available"] = true
end
end
- tokenizer :skip_comments do
- if @input.match?(/^%/)
- @input.skip_until(/\n/)
- end
+ tokenizer :skip_lastupdate do
+ @input.skip(/>>>(.+?)<<<\n/)
end
- tokenizer :flag_section_start do
- if @input.scan(/(.+?):\n/)
- @tmp['section'] = @input[1].strip
- end
- end
-
- tokenizer :flag_section_end do
- # if @input.match?(/^\n/)
- # @tmp.delete('section')
- # end
- end
-
- tokenizer :scan_section do
- if @tmp['section']
- lines = _scan_lines_to_array(/^(.+)\n/)
-
- # Check all lines to be sure there is no case where a value containing a :
- # is misinterpreted as key : value.
-
- # The section is a hash
- value = if lines.all? { |line| line.index(':', 1) }
- Hash[lines.map { |line| line.split(':', 2).map(&:strip) }]
- # The section is an array of values
- else
- lines
- end
-
- @ast[@tmp['section']] = value
- @tmp.delete('section')
+ tokenizer :scan_disclaimer do
+ if @input.match?(/^% WHOIS LEGAL STATEMENT/)
+ @ast["field:disclaimer"] = _scan_lines_to_array(/%(.*)\n/).map(&:strip).join("\n")
end
end
@@ -1,12 +1,12 @@
#disclaimer
- should: %s raise_error(Whois::PropertyNotSupported)
+ should: %s == "WHOIS LEGAL STATEMENT AND TERMS & CONDITIONS\nThe WHOIS service offered by OpenRegistry and the access to the\nrecords in the OpenRegistry WHOIS database are provided for information\npurposes only. It allows persons to check whether a specific domain name\nis still available or not and to obtain information related to the\nregistration records of existing domain names. You are not authorized to\naccess or query our WHOIS database through the use of electronic\nprocesses that are high-volume and automated except as reasonably\nnecessary to register domain names or modify existing registrations.\n\nOpenRegistry cannot, under any circumstances, be held liable should the\nstored information prove to be wrong, incomplete or inaccurate in any sense.\n\nBy submitting a WHOIS query you agree not to use the information made\navailable to:\n- Allow, enable or otherwise support the transmission of unsolicited,\ncommercial advertising or other solicitations whether via email, telephone\nor otherwise;\n- Target advertising in any possible way;\n- Cause nuisance in any possible way to the registrants by sending (whether\nby automated, electronic processes capable of enabling high volumes or\nother possible means) messages to them.\n\nWithout prejudice to the above, it is explicitly forbidden to extract, copy\nand/or use or re-utilise in any form and by any means (electronically or\nnot) the whole or a quantitatively or qualitatively substantial part of the\ncontents of the WHOIS database without prior and explicit permission by\nOpenRegistry, nor in any attempt hereof, to apply automated, electronic\nprocesses to OpenRegistry (or its systems).\n\nBy submitting the query you agree that any reproduction and/or transmission\nof data for commercial purposes will always be considered as the extraction\nof a substantial part of the content of the WHOIS database. You also agree\nto abide by this policy and accept that OpenRegistry can take measures to\nlimit the use of its WHOIS services in order to protect the privacy of its\nregistrants and/or the integrity of the database. OpenRegistry reserves the\nright to restrict your access to the WHOIS database in its sole discretion\nto ensure operational stability. OpenRegistry may restrict or terminate your\naccess to the WHOIS database for failure to abide by these terms of use.\n\nOpenRegistry reserves the right to modify these terms at any time."
#domain
should: %s == "u34jedzcq.sx"
#domain_id
- should: %s raise_error(Whois::PropertyNotSupported)
+ should: %s == nil
#status
@@ -20,13 +20,13 @@
#created_on
- should: %s raise_error(Whois::PropertyNotSupported)
+ should: %s == nil
#updated_on
- should: %s raise_error(Whois::PropertyNotSupported)
+ should: %s == nil
#expires_on
- should: %s raise_error(Whois::PropertyNotSupported)
+ should: %s == nil
#registrar
@@ -37,10 +37,12 @@
should: %s == []
#admin_contacts
- should: %s raise_error(Whois::PropertyNotSupported)
+ should: %s CLASS(array)
+ should: %s == []
#technical_contacts
- should: %s raise_error(Whois::PropertyNotSupported)
+ should: %s CLASS(array)
+ should: %s == []
#nameservers
@@ -1,9 +1,46 @@
-[whois.sx]
+
+Status: AVAILABLE (No match for domain "u34jedzcq.sx")
+>>> Last update of WHOIS database: 2012-11-22T11:54:04.786Z <<<
+
+% WHOIS LEGAL STATEMENT AND TERMS & CONDITIONS
+% The WHOIS service offered by OpenRegistry and the access to the
+% records in the OpenRegistry WHOIS database are provided for information
+% purposes only. It allows persons to check whether a specific domain name
+% is still available or not and to obtain information related to the
+% registration records of existing domain names. You are not authorized to
+% access or query our WHOIS database through the use of electronic
+% processes that are high-volume and automated except as reasonably
+% necessary to register domain names or modify existing registrations.
%
-% Copyright 2011 SX Registry S.A.
+% OpenRegistry cannot, under any circumstances, be held liable should the
+% stored information prove to be wrong, incomplete or inaccurate in any sense.
%
-% WHOIS u34jedzcq
-Domain: u34jedzcq
-
-Status: reserved/free (policy pending)
+% By submitting a WHOIS query you agree not to use the information made
+% available to:
+% - Allow, enable or otherwise support the transmission of unsolicited,
+% commercial advertising or other solicitations whether via email, telephone
+% or otherwise;
+% - Target advertising in any possible way;
+% - Cause nuisance in any possible way to the registrants by sending (whether
+% by automated, electronic processes capable of enabling high volumes or
+% other possible means) messages to them.
+%
+% Without prejudice to the above, it is explicitly forbidden to extract, copy
+% and/or use or re-utilise in any form and by any means (electronically or
+% not) the whole or a quantitatively or qualitatively substantial part of the
+% contents of the WHOIS database without prior and explicit permission by
+% OpenRegistry, nor in any attempt hereof, to apply automated, electronic
+% processes to OpenRegistry (or its systems).
+%
+% By submitting the query you agree that any reproduction and/or transmission
+% of data for commercial purposes will always be considered as the extraction
+% of a substantial part of the content of the WHOIS database. You also agree
+% to abide by this policy and accept that OpenRegistry can take measures to
+% limit the use of its WHOIS services in order to protect the privacy of its
+% registrants and/or the integrity of the database. OpenRegistry reserves the
+% right to restrict your access to the WHOIS database in its sole discretion
+% to ensure operational stability. OpenRegistry may restrict or terminate your
+% access to the WHOIS database for failure to abide by these terms of use.
+%
+% OpenRegistry reserves the right to modify these terms at any time.
Oops, something went wrong.

0 comments on commit 65a661a

Please sign in to comment.