Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add .SX (whois.sx) support (closes GH-170)

  • Loading branch information...
commit 95e211244b81bd93ee5a1119b72d3ea9d472f66a 2 parents b31e132 + d46da8f
@weppos authored
View
2  CHANGELOG.md
@@ -17,6 +17,8 @@
* SERVER: Added .TN TLD server.
+* SERVER: Added .SX TLD server.
+
* NEW: whois.srs.net.nz parser now recognizes throttled responses.
* NEW: Added full whois.registry.om parser.
View
1  lib/whois/definitions/tlds.rb
@@ -273,6 +273,7 @@
Whois::Server.define :tld, ".st", "whois.nic.st"
Whois::Server.define :tld, ".su", "whois.tcinet.ru"
Whois::Server.define :tld, ".sv", nil, { :adapter => Whois::Server::Adapters::Web, :web => "http://www.uca.edu.sv/dns/" }
+Whois::Server.define :tld, ".sx", "whois.sx"
Whois::Server.define :tld, ".sy", nil, { :adapter => Whois::Server::Adapters::None }
Whois::Server.define :tld, ".sz", nil, { :adapter => Whois::Server::Adapters::None }
Whois::Server.define :tld, ".tc", "whois.adamsnames.tc"
View
124 lib/whois/record/parser/whois.sx.rb
@@ -0,0 +1,124 @@
+#--
+# 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.sx.rb'
+
+
+module Whois
+ class Record
+ class Parser
+
+ # Parser for the whois.sx server.
+ #
+ # @see Whois::Record::Parser::Example
+ # The Example parser for the list of all available methods.
+ #
+ # @since RELEASE
+ class WhoisSx < Base
+ include Scanners::Ast
+
+ property_not_supported :disclaimer
+
+
+ property_supported :domain do
+ "#{node('Domain')}.sx"
+ end
+
+ property_not_supported :domain_id
+
+
+ property_not_supported :referral_whois
+
+ property_not_supported :referral_url
+
+
+ property_supported :status do
+ case (s = node('Status'))
+ when /free/
+ :available
+ when 'active'
+ :registered
+ else
+ Whois.bug!(ParserError, "Unknown status `#{s}'.")
+ end
+ end
+
+ property_supported :available? do
+ status == :available
+ end
+
+ property_supported :registered? do
+ !available?
+ end
+
+
+ property_not_supported :created_on
+
+ property_not_supported :updated_on
+
+ property_not_supported :expires_on
+
+
+ property_supported :registrar do
+ node('Registrar') do |hash|
+ Record::Registrar.new(
+ :name => hash['Name'],
+ :url => hash['Website']
+ )
+ end
+ end
+
+
+ property_supported :registrant_contacts do
+ build_contact('Registrant', Whois::Record::Contact::TYPE_REGISTRANT)
+ end
+
+ property_not_supported :admin_contacts
+
+ property_not_supported :technical_contacts
+
+
+ property_supported :nameservers do
+ node('Name servers') do |names|
+ names.map do |name|
+ Record::Nameserver.new(:name => name)
+ end
+ end
+ end
+
+
+ # Initializes a new {Scanners::WhoisSx} instance
+ # passing the {#content_for_scanner}
+ # and calls +parse+ on it.
+ #
+ # @return [Hash]
+ def parse
+ Scanners::WhoisSx.new(content_for_scanner).parse
+ end
+
+
+ private
+
+ def build_contact(element, type)
+ node("#{element}") do |array|
+ Record::Contact.new(
+ :type => type,
+ :id => nil,
+ :name => array[0],
+ :email => nil
+ )
+ end
+ end
+
+ end
+
+ end
+ end
+end
View
25 lib/whois/record/scanners/base.rb
@@ -62,20 +62,33 @@ def parse
protected
def _scan_lines_to_array(pattern)
- lines = []
+ results = []
while @input.scan(pattern)
@input[1].strip
- lines << @input[1].strip
+ results << @input[1].strip
end
- lines
+ results
end
def _scan_lines_to_hash(pattern)
- lines = {}
+ results = {}
while @input.scan(pattern)
- lines.merge! @input[1].strip => @input[2].strip
+ results.merge! @input[1].strip => @input[2].strip
+ end
+ results
+ end
+
+ def _scan_keyvalues(pattern)
+ results = []
+ while @input.scan(/(.+?):(.*?)\n/)
+ key, value = @input[1].strip, @input[2].strip
+ if results[key].nil?
+ results[key] = value
+ else
+ results[key] = Array.wrap(results[key])
+ results[key] << value
+ end
end
- lines
end
private
View
22 lib/whois/record/scanners/whois.rnids.rs.rb
@@ -22,15 +22,15 @@ class WhoisRnidsRs < Base
self.tokenizers += [
:scan_available,
:skip_comment,
- :flag_group_start,
- :scan_group_keyvalue,
- :flag_group_end,
+ :flag_section_start,
+ :scan_section_keyvalue,
+ :flag_section_end,
:skip_empty_line,
:skip_privacy,
]
- GROUPS = ["Owner", "Administrative contact", "Technical contact"]
+ SECTIONS = ["Owner", "Administrative contact", "Technical contact"]
tokenizer :scan_available do
if @input.scan(/^%ERROR:103: Domain is not registered/)
@@ -38,23 +38,23 @@ class WhoisRnidsRs < Base
end
end
- tokenizer :flag_group_start do
- if GROUPS.any? { |group| @input.check(/^(#{group}):/) }
- @tmp["group"] = @input[1]
+ tokenizer :flag_section_start do
+ if SECTIONS.any? { |section| @input.check(/^(#{section}):/) }
+ @tmp["section"] = @input[1]
end
false
end
- tokenizer :flag_group_end do
+ tokenizer :flag_section_end do
if @input.match?(/^\n/)
- @tmp.delete("group")
+ @tmp.delete("section")
end
end
- tokenizer :scan_group_keyvalue do
+ tokenizer :scan_section_keyvalue do
if @input.scan(/(.+?):(.*?)\n/)
key, value = @input[1].strip, @input[2].strip
- target = @tmp["group"] ? (@ast[@tmp["group"]] ||= {}) : @ast
+ target = @tmp["section"] ? (@ast[@tmp["section"]] ||= {}) : @ast
if target[key].nil?
target[key] = value
View
81 lib/whois/record/scanners/whois.sx.rb
@@ -0,0 +1,81 @@
+#--
+# 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.sx record.
+ #
+ # @since RELEASE
+ class WhoisSx < Base
+
+ self.tokenizers += [
+ :skip_header,
+ :skip_comments,
+ :skip_empty_line,
+ :flag_section_start,
+ :flag_section_end,
+ :scan_section,
+ :scan_keyvalue,
+ ]
+
+
+ tokenizer :skip_header do
+ if @input.pos == 0 && @input.match?(/^\[/)
+ @input.skip_until(/\n/)
+ end
+ end
+
+ tokenizer :skip_comments do
+ if @input.match?(/^%/)
+ @input.skip_until(/\n/)
+ end
+ 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')
+ end
+ end
+
+ end
+
+ end
+ end
+end
View
55 spec/fixtures/responses/whois.sx/status_available.expected
@@ -0,0 +1,55 @@
+#disclaimer
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+
+#domain
+ should: %s == "u34jedzcq.sx"
+
+#domain_id
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+
+#referral_url
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+#referral_whois
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+
+#status
+ should: %s == :available
+
+#available?
+ should: %s == true
+
+#registered?
+ should: %s == false
+
+
+#created_on
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+#updated_on
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+#expires_on
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+
+#registrar
+ should: %s == nil
+
+#registrant_contacts
+ should: %s CLASS(array)
+ should: %s == []
+
+#admin_contacts
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+#technical_contacts
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+
+#nameservers
+ should: %s CLASS(array)
+ should: %s == []
View
9 spec/fixtures/responses/whois.sx/status_available.txt
@@ -0,0 +1,9 @@
+[whois.sx]
+%
+% Copyright 2011 SX Registry S.A.
+%
+% WHOIS u34jedzcq
+Domain: u34jedzcq
+
+Status: reserved/free (policy pending)
+
View
85 spec/fixtures/responses/whois.sx/status_registered.expected
@@ -0,0 +1,85 @@
+#disclaimer
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+
+#domain
+ should: %s == "whois.sx"
+
+#domain_id
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+
+#referral_url
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+#referral_whois
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+
+#status
+ should: %s == :registered
+
+#available?
+ should: %s == false
+
+#registered?
+ should: %s == true
+
+
+#created_on
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+#updated_on
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+#expires_on
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+
+#registrar
+ should: %s CLASS(registrar)
+ should: %s.id == nil
+ should: %s.name == "SX Registry S.A."
+ should: %s.organization == nil
+ should: %s.url == "http://registry.sx"
+
+#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 == nil
+ should: %s[0].name == "SX Registry S.A."
+ should: %s[0].organization == nil
+ should: %s[0].address == nil
+ should: %s[0].city == nil
+ should: %s[0].zip == nil
+ should: %s[0].state == nil
+ should: %s[0].country == nil
+ should: %s[0].country_code == nil
+ should: %s[0].phone == nil
+ should: %s[0].fax == nil
+ should: %s[0].email == nil
+
+#admin_contacts
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+#technical_contacts
+ should: %s raise_error(Whois::PropertyNotSupported)
+
+
+#nameservers
+ should: %s CLASS(array)
+ should: %s SIZE(3)
+ should: %s[0] CLASS(nameserver)
+ should: %s[0].name == "a.ns.sx"
+ should: %s[0].ipv4 == nil
+ should: %s[0].ipv6 == nil
+ should: %s[1] CLASS(nameserver)
+ should: %s[1].name == "b.ns.sx"
+ should: %s[1].ipv4 == nil
+ should: %s[1].ipv6 == nil
+ should: %s[2] CLASS(nameserver)
+ should: %s[2].name == "c.ns.sx"
+ should: %s[2].ipv4 == nil
+ should: %s[2].ipv6 == nil
View
21 spec/fixtures/responses/whois.sx/status_registered.txt
@@ -0,0 +1,21 @@
+[whois.sx]
+%
+% Copyright 2011 SX Registry S.A.
+%
+% WHOIS whois
+Domain: whois
+
+Status: active
+
+Registrant:
+ SX Registry S.A.
+
+Registrar:
+ Name: SX Registry S.A.
+ Website: http://registry.sx
+
+Name servers:
+ a.ns.sx
+ b.ns.sx
+ c.ns.sx
+
View
1  spec/tlds
@@ -266,6 +266,7 @@ sr;;;
st;whois.nic.st;google.st;u34jedzcq.st
su;whois.ripn.net;google.su;u34jedzcq.su
sv;;;
+sx;whois.sx;whois.sx;u34jedzcq.sx
sy;;;
sz;;;
tc;whois.adamsnames.tc;google.tc;u34jedzcq.tc
View
106 spec/whois/record/parser/responses/whois.sx/status_available_spec.rb
@@ -0,0 +1,106 @@
+# encoding: utf-8
+
+# This file is autogenerated. Do not edit it manually.
+# If you want change the content of this file, edit
+#
+# /spec/fixtures/responses/whois.sx/status_available.expected
+#
+# and regenerate the tests with the following rake task
+#
+# $ rake spec:generate
+#
+
+require 'spec_helper'
+require 'whois/record/parser/whois.sx.rb'
+
+describe Whois::Record::Parser::WhoisSx, "status_available.expected" do
+
+ before(:each) do
+ file = fixture("responses", "whois.sx/status_available.txt")
+ part = Whois::Record::Part.new(:body => File.read(file))
+ @parser = klass.new(part)
+ end
+
+ describe "#disclaimer" do
+ it do
+ lambda { @parser.disclaimer }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#domain" do
+ it do
+ @parser.domain.should == "u34jedzcq.sx"
+ end
+ end
+ describe "#domain_id" do
+ it do
+ lambda { @parser.domain_id }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#referral_url" do
+ it do
+ lambda { @parser.referral_url }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#referral_whois" do
+ it do
+ lambda { @parser.referral_whois }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#status" do
+ it do
+ @parser.status.should == :available
+ end
+ end
+ describe "#available?" do
+ it do
+ @parser.available?.should == true
+ end
+ end
+ describe "#registered?" do
+ it do
+ @parser.registered?.should == false
+ end
+ end
+ describe "#created_on" do
+ it do
+ lambda { @parser.created_on }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#updated_on" do
+ it do
+ lambda { @parser.updated_on }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#expires_on" do
+ it do
+ lambda { @parser.expires_on }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#registrar" do
+ it do
+ @parser.registrar.should == nil
+ end
+ end
+ describe "#registrant_contacts" do
+ it do
+ @parser.registrant_contacts.should be_a(Array)
+ @parser.registrant_contacts.should == []
+ end
+ end
+ describe "#admin_contacts" do
+ it do
+ lambda { @parser.admin_contacts }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#technical_contacts" do
+ it do
+ lambda { @parser.technical_contacts }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#nameservers" do
+ it do
+ @parser.nameservers.should be_a(Array)
+ @parser.nameservers.should == []
+ end
+ end
+end
View
136 spec/whois/record/parser/responses/whois.sx/status_registered_spec.rb
@@ -0,0 +1,136 @@
+# encoding: utf-8
+
+# This file is autogenerated. Do not edit it manually.
+# If you want change the content of this file, edit
+#
+# /spec/fixtures/responses/whois.sx/status_registered.expected
+#
+# and regenerate the tests with the following rake task
+#
+# $ rake spec:generate
+#
+
+require 'spec_helper'
+require 'whois/record/parser/whois.sx.rb'
+
+describe Whois::Record::Parser::WhoisSx, "status_registered.expected" do
+
+ before(:each) do
+ file = fixture("responses", "whois.sx/status_registered.txt")
+ part = Whois::Record::Part.new(:body => File.read(file))
+ @parser = klass.new(part)
+ end
+
+ describe "#disclaimer" do
+ it do
+ lambda { @parser.disclaimer }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#domain" do
+ it do
+ @parser.domain.should == "whois.sx"
+ end
+ end
+ describe "#domain_id" do
+ it do
+ lambda { @parser.domain_id }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#referral_url" do
+ it do
+ lambda { @parser.referral_url }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#referral_whois" do
+ it do
+ lambda { @parser.referral_whois }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#status" do
+ it do
+ @parser.status.should == :registered
+ end
+ end
+ describe "#available?" do
+ it do
+ @parser.available?.should == false
+ end
+ end
+ describe "#registered?" do
+ it do
+ @parser.registered?.should == true
+ end
+ end
+ describe "#created_on" do
+ it do
+ lambda { @parser.created_on }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#updated_on" do
+ it do
+ lambda { @parser.updated_on }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#expires_on" do
+ it do
+ lambda { @parser.expires_on }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#registrar" do
+ it do
+ @parser.registrar.should be_a(Whois::Record::Registrar)
+ @parser.registrar.id.should == nil
+ @parser.registrar.name.should == "SX Registry S.A."
+ @parser.registrar.organization.should == nil
+ @parser.registrar.url.should == "http://registry.sx"
+ end
+ end
+ describe "#registrant_contacts" do
+ it do
+ @parser.registrant_contacts.should be_a(Array)
+ @parser.registrant_contacts.should have(1).items
+ @parser.registrant_contacts[0].should be_a(Whois::Record::Contact)
+ @parser.registrant_contacts[0].type.should == Whois::Record::Contact::TYPE_REGISTRANT
+ @parser.registrant_contacts[0].id.should == nil
+ @parser.registrant_contacts[0].name.should == "SX Registry S.A."
+ @parser.registrant_contacts[0].organization.should == nil
+ @parser.registrant_contacts[0].address.should == nil
+ @parser.registrant_contacts[0].city.should == nil
+ @parser.registrant_contacts[0].zip.should == nil
+ @parser.registrant_contacts[0].state.should == nil
+ @parser.registrant_contacts[0].country.should == nil
+ @parser.registrant_contacts[0].country_code.should == nil
+ @parser.registrant_contacts[0].phone.should == nil
+ @parser.registrant_contacts[0].fax.should == nil
+ @parser.registrant_contacts[0].email.should == nil
+ end
+ end
+ describe "#admin_contacts" do
+ it do
+ lambda { @parser.admin_contacts }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#technical_contacts" do
+ it do
+ lambda { @parser.technical_contacts }.should raise_error(Whois::PropertyNotSupported)
+ end
+ end
+ describe "#nameservers" do
+ it do
+ @parser.nameservers.should be_a(Array)
+ @parser.nameservers.should have(3).items
+ @parser.nameservers[0].should be_a(Whois::Record::Nameserver)
+ @parser.nameservers[0].name.should == "a.ns.sx"
+ @parser.nameservers[0].ipv4.should == nil
+ @parser.nameservers[0].ipv6.should == nil
+ @parser.nameservers[1].should be_a(Whois::Record::Nameserver)
+ @parser.nameservers[1].name.should == "b.ns.sx"
+ @parser.nameservers[1].ipv4.should == nil
+ @parser.nameservers[1].ipv6.should == nil
+ @parser.nameservers[2].should be_a(Whois::Record::Nameserver)
+ @parser.nameservers[2].name.should == "c.ns.sx"
+ @parser.nameservers[2].ipv4.should == nil
+ @parser.nameservers[2].ipv6.should == nil
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.