Skip to content

Commit

Permalink
Update whois.sx parser to the new response format.
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Nov 22, 2012
1 parent b73890a commit 65a661a
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 141 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -61,6 +61,8 @@


- CHANGED: Updated whois.nic.pr parser to the new response format. - 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.domainregistry.ie should support status `Active - LOCKED`.


- FIXED: whois.nic.uk fails to parse registrars without URL (GH-188). - FIXED: whois.nic.uk fails to parse registrars without URL (GH-188).
Expand Down
68 changes: 45 additions & 23 deletions lib/whois/record/parser/whois.sx.rb
Expand Up @@ -24,21 +24,26 @@ class Parser
class WhoisSx < Base class WhoisSx < Base
include Scanners::Nodable include Scanners::Nodable


property_not_supported :disclaimer property_supported :disclaimer do
node("field:disclaimer")
end




property_supported :domain do property_supported :domain do
"#{node('Domain')}.sx" node("Domain Name", &:downcase)
end end


property_not_supported :domain_id property_supported :domain_id do
node("Domain ID")
end




property_supported :status do property_supported :status do
case (s = node('Status')) s = node("Domain Status")
when /free/ case
when node("status:available")
:available :available
when 'active' when s == "ok"
:registered :registered
else else
Whois.bug!(ParserError, "Unknown status `#{s}'.") Whois.bug!(ParserError, "Unknown status `#{s}'.")
Expand All @@ -54,37 +59,44 @@ class WhoisSx < Base
end 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 property_supported :registrar do
node('Registrar') do |hash| node("Sponsoring Registrar") do |value|
Record::Registrar.new( Record::Registrar.new(
:name => hash['Name'], :name => value
:url => hash['Website']
) )
end end
end end




property_supported :registrant_contacts do property_supported :registrant_contacts do
build_contact('Registrant', Whois::Record::Contact::TYPE_REGISTRANT) build_contact("Registrant", Whois::Record::Contact::TYPE_REGISTRANT)
end 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 property_supported :nameservers do
node('Name servers') do |names| Array.wrap(node("Name Server")).map do |name|
names.map do |name| Record::Nameserver.new(:name => name)
Record::Nameserver.new(:name => name)
end
end end
end end


Expand All @@ -101,13 +113,23 @@ def parse


private 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) def build_contact(element, type)
node("#{element}") do |array| node("#{element} ID") do |id|
Record::Contact.new( Record::Contact.new(
:type => type, :type => type,
:id => nil, :id => id,
:name => array[0], :name => node("#{element} Name"),
:email => nil :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
end end
Expand Down
1 change: 0 additions & 1 deletion lib/whois/record/scanners/base_shared2.rb
Expand Up @@ -8,7 +8,6 @@




require 'whois/record/scanners/base' require 'whois/record/scanners/base'
require 'whois/record/scanners/base_shared2'




module Whois module Whois
Expand Down
58 changes: 13 additions & 45 deletions lib/whois/record/scanners/whois.sx.rb
Expand Up @@ -14,63 +14,31 @@ module Whois
class Record class Record
module Scanners module Scanners


# Scanner for the whois.sx record.
#
# @since 2.6.2
class WhoisSx < Base class WhoisSx < Base


self.tokenizers += [ self.tokenizers += [
:skip_header, :skip_blank_line,
:skip_comments, :scan_available,
:skip_empty_line,
:flag_section_start,
:flag_section_end,
:scan_section,
:scan_keyvalue, :scan_keyvalue,
:skip_lastupdate,
:scan_disclaimer,
] ]




tokenizer :skip_header do tokenizer :scan_available do
if @input.pos == 0 && @input.match?(/^\[/) if @input.scan(/^Status: AVAILABLE \(No match for domain "(.+)"\)\n/)
@input.skip_until(/\n/) @ast["Domain Name"] = @input[1]
@ast["status:available"] = true
end end
end end


tokenizer :skip_comments do tokenizer :skip_lastupdate do
if @input.match?(/^%/) @input.skip(/>>>(.+?)<<<\n/)
@input.skip_until(/\n/)
end
end end


tokenizer :flag_section_start do tokenizer :scan_disclaimer do
if @input.scan(/(.+?):\n/) if @input.match?(/^% WHOIS LEGAL STATEMENT/)
@tmp['section'] = @input[1].strip @ast["field:disclaimer"] = _scan_lines_to_array(/%(.*)\n/).map(&:strip).join("\n")
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')
end end
end end


Expand Down
16 changes: 9 additions & 7 deletions spec/fixtures/responses/whois.sx/status_available.expected
@@ -1,12 +1,12 @@
#disclaimer #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 #domain
should: %s == "u34jedzcq.sx" should: %s == "u34jedzcq.sx"


#domain_id #domain_id
should: %s raise_error(Whois::PropertyNotSupported) should: %s == nil




#status #status
Expand All @@ -20,13 +20,13 @@




#created_on #created_on
should: %s raise_error(Whois::PropertyNotSupported) should: %s == nil


#updated_on #updated_on
should: %s raise_error(Whois::PropertyNotSupported) should: %s == nil


#expires_on #expires_on
should: %s raise_error(Whois::PropertyNotSupported) should: %s == nil




#registrar #registrar
Expand All @@ -37,10 +37,12 @@
should: %s == [] should: %s == []


#admin_contacts #admin_contacts
should: %s raise_error(Whois::PropertyNotSupported) should: %s CLASS(array)
should: %s == []


#technical_contacts #technical_contacts
should: %s raise_error(Whois::PropertyNotSupported) should: %s CLASS(array)
should: %s == []




#nameservers #nameservers
Expand Down
49 changes: 43 additions & 6 deletions spec/fixtures/responses/whois.sx/status_available.txt
@@ -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 % By submitting a WHOIS query you agree not to use the information made
Domain: u34jedzcq % available to:

% - Allow, enable or otherwise support the transmission of unsolicited,
Status: reserved/free (policy pending) % 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.


0 comments on commit 65a661a

Please sign in to comment.