Skip to content

Commit

Permalink
Merge branch 'whois.cira.ca'
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Mar 28, 2012
2 parents 487dbe9 + c7bb7e9 commit 675b405
Show file tree
Hide file tree
Showing 12 changed files with 409 additions and 37 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Expand Up @@ -7,9 +7,11 @@

* NEW: Added full whois.audns.net.au parser.

* NEW: Added full whois.cctld.by server (GH-154).
* NEW: Added full whois.cctld.by parser (GH-154).

* NEW: Added full whois.domainregistry.ie server.
* NEW: Added full whois.domainregistry.ie parser.

* NEW: Added full whois.cira.ca parser.

* CHANGED: Moved scanners from Whois::Record::Parser::Scanners to Whois::Record::Scanners.

Expand Down
2 changes: 1 addition & 1 deletion lib/whois/record/parser/base_afilias.rb
Expand Up @@ -24,7 +24,7 @@ class BaseAfilias < Base


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


Expand Down
118 changes: 89 additions & 29 deletions lib/whois/record/parser/whois.cira.ca.rb
Expand Up @@ -8,28 +8,42 @@


require 'whois/record/parser/base'
require 'whois/record/scanners/whois.cira.ca.rb'


module Whois
class Record
class Parser

#
# = whois.cira.ca parser
#
# Parser for the whois.cira.ca server.
#
# @see Whois::Record::Parser::Example
# The Example parser for the list of all available methods.
#
# NOTE: This parser is just a stub and provides only a few basic methods
# to check for domain availability and get domain status.
# Please consider to contribute implementing missing methods.
# See WhoisNicIt parser for an explanation of all available methods
# and examples.
#
# @since RELEASE
class WhoisCiraCa < Base
include Scanners::Ast

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


property_supported :domain do
node("Domain name")
end

property_not_supported :domain_id


property_not_supported :referral_whois

property_not_supported :referral_url


property_supported :status do
if content_for_scanner =~ /Domain status:\s+(.+?)\n/
case $1.downcase
case node("Domain status", &:downcase)
when "registered"
:registered
when "redemption"
Expand Down Expand Up @@ -60,30 +74,46 @@ class WhoisCiraCa < Base


property_supported :created_on do
if content_for_scanner =~ /Creation date:\s+(.+?)\n/
Time.parse($1)
end
node("Creation date") { |str| Time.parse(str) }
end

property_supported :updated_on do
if content_for_scanner =~ /Updated date:\s+(.+?)\n/
Time.parse($1)
end
node("Updated date") { |str| Time.parse(str) }
end

property_supported :expires_on do
if content_for_scanner =~ /Expiry date:\s+(.+?)\n/
Time.parse($1)
end
node("Expiry date") { |str| Time.parse(str) }
end


property_supported :registrar do
if content_for_scanner =~ /^Registrar:\n(.+\n?)^\n/m
match = $1
id = match =~ /Number:\s+(.+)$/ ? $1.strip : nil
name = match =~ /Name:\s+(.+)$/ ? $1.strip : nil
Whois::Record::Registrar.new(:id => id, :name => name, :organization => name)
node("Registrar") do |hash|
Record::Registrar.new(
:id => hash["Number"],
:name => hash["Name"],
:organization => hash["Name"]
)
end
end


property_supported :registrant_contacts do
build_contact("Registrant", Whois::Record::Contact::TYPE_REGISTRANT)
end

property_supported :admin_contacts do
build_contact("Administrative contact", Whois::Record::Contact::TYPE_ADMIN)
end

property_supported :technical_contacts do
build_contact("Technical contact", Whois::Record::Contact::TYPE_TECHNICAL)
end


property_supported :nameservers do
Array.wrap(node("nserver")).map do |line|
name, ipv4 = line.split(/\s+/)
Record::Nameserver.new(:name => name, :ipv4 => ipv4)
end
end

Expand All @@ -97,11 +127,9 @@ class WhoisCiraCa < Base
# ns2.google.com 216.239.34.10
#
property_supported :nameservers do
if content_for_scanner =~ /Name servers:\n((?:\s+([^\s]+)\s+([^\s]+)\n)+)/
$1.split("\n").map do |line|
name, ipv4 = line.strip.split(/\s+/)
Record::Nameserver.new(:name => name, :ipv4 => ipv4)
end
Array.wrap(node("field:nameservers")).map do |line|
name, ipv4 = line.strip.split(/\s+/)
Record::Nameserver.new(:name => name, :ipv4 => ipv4)
end
end

Expand Down Expand Up @@ -135,6 +163,38 @@ def invalid?
end
end


# Initializes a new {Scanners::WhoisCiraCa} instance
# passing the {#content_for_scanner}
# and calls +parse+ on it.
#
# @return [Hash]
def parse
Scanners::WhoisCiraCa.new(content_for_scanner).parse
end


private

def build_contact(element, type)
node(element) do |hash|
Record::Contact.new(
:type => type,
:id => nil,
:name => hash["Name"],
:organization => nil,
:address => hash["Postal address"],
:city => nil,
:zip => nil,
:state => nil,
:country => nil,
:phone => hash["Phone"],
:fax => hash["Fax"],
:email => hash["Email"]
)
end
end

end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/whois/record/scanners/afilias.rb
Expand Up @@ -50,7 +50,7 @@ class Afilias < Base

tokenizer :scan_disclaimer do
if @input.pos == 0 && @input.match?(/^(.+\n){3,}\n/)
@ast["property:disclaimer"] = _scan_lines_to_array(/^(.+)\n/).join(" ")
@ast["field:disclaimer"] = _scan_lines_to_array(/^(.+)\n/).join(" ")
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/whois/record/scanners/base.rb
Expand Up @@ -53,7 +53,7 @@ def parse
if @ast[key].nil?
@ast[key] = value
else
@ast[key] = [@ast[key]] unless @ast[key].is_a?(Array)
@ast[key] = Array.wrap(@ast[key])
@ast[key] << value
end
end
Expand All @@ -64,6 +64,7 @@ def parse
def _scan_lines_to_array(pattern)
lines = []
while @input.scan(pattern)
@input[1].strip
lines << @input[1].strip
end
lines
Expand Down
86 changes: 86 additions & 0 deletions lib/whois/record/scanners/whois.cira.ca.rb
@@ -0,0 +1,86 @@
#--
# 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.cira.ca record.
#
# @since RELEASE
class WhoisCiraCa < Base

self.tokenizers += [
:skip_empty_line,
:scan_disclaimer,
:skip_comment,
:scan_header,
:scan_keyvalue,
:scan_nameserver,
]



tokenizer :scan_disclaimer do
if @input.match?(/^% Use of CIRA/)
@ast["field:disclaimer"] = _scan_lines_to_array(/^%(.*)\n/).join("\n")
end
end

tokenizer :scan_header do
if @input.scan(/^(.+?):\n/)
@tmp["group"] = @input[1]
end
end

tokenizer :scan_keyvalue do
if @input.scan(/^(.+?):(.*?)\n/)
start = @input[1]
key, value = start.strip, @input[2].strip

# This is a nested key
target = if start[0] == " "
error!("Expected group.") if @tmp["group"].nil?
@ast[@tmp["group"]] ||= {}
else
@tmp.delete("group")
@ast
end

more = _scan_lines_to_array(/^\s{#{start.size}}(.+)\n/)
value = more.unshift(value).join("\n") unless more.empty?

if target[key].nil?
target[key] = value
else
target[key] = Array.wrap(target[key])
target[key] << value
end
end
end

tokenizer :scan_nameserver do
if @input.scan(/^\s+(.+?)\n/) && @tmp["group"] == "Name servers"
@ast["field:nameservers"] ||= []
@ast["field:nameservers"] << @input[1].strip
end
end

tokenizer :skip_comment do
@input.skip(/^%.*\n/)
end

end

end
end
end
4 changes: 2 additions & 2 deletions lib/whois/record/scanners/whois.domainregistry.ie.rb
Expand Up @@ -19,7 +19,7 @@ class WhoisDomainregistryIe < Base

self.tokenizers += [
:skip_empty_line,
:scan_copyright,
:scan_disclaimer,
:scan_contact,
:scan_keyvalue,
:scan_available,
Expand All @@ -31,7 +31,7 @@ class WhoisDomainregistryIe < Base
end
end

tokenizer :scan_copyright do
tokenizer :scan_disclaimer do
if @input.match?(/^% Rights restricted by copyright/)
@ast["field:disclaimer"] = _scan_lines_to_array(/^%(.+)\n/).join("\n")
end
Expand Down
1 change: 0 additions & 1 deletion lib/whois/record/scanners/whois.rnids.rs.rb
Expand Up @@ -53,7 +53,6 @@ class WhoisRnidsRs < Base
tokenizer :scan_group_keyvalue do
if @input.scan(/(.+?):(.*?)\n/)
key, value = @input[1].strip, @input[2].strip

target = @tmp["group"] ? (@ast[@tmp["group"]] ||= {}) : @ast

if target[key].nil?
Expand Down
30 changes: 30 additions & 0 deletions spec/fixtures/responses/whois.cira.ca/status_available.expected
@@ -1,3 +1,21 @@
#disclaimer
should: %s == "Use of CIRA's WHOIS service is governed by the Terms of Use in its Legal\nNotice, available at http://www.cira.ca/legal-notice/?lang=en\n\n(c) 2010 Canadian Internet Registration Authority, (http://www.cira.ca/)"


#domain
should: %s == "u34jedzcq.ca"

#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

Expand All @@ -21,6 +39,18 @@
#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)
Expand Down

0 comments on commit 675b405

Please sign in to comment.