Skip to content

Commit

Permalink
Merge branch 'whois.nic.co'
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Sep 19, 2012
2 parents c37586c + c442604 commit 969d9d8
Show file tree
Hide file tree
Showing 17 changed files with 624 additions and 278 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -20,6 +20,8 @@

* NEW: Added full whois.nic.dm parser (GH-43).

* NEW: Added full whois.nic.co parser.

* FIXED: Fixed whois.register.com parser for enom formats (GH-181). [Thanks @JustinCampbell]

* FIXED: whois.jprs.js parser should support status `Suspended`.
Expand Down
2 changes: 1 addition & 1 deletion lib/whois/record/parser/base_shared1.rb
Expand Up @@ -90,7 +90,7 @@ class BaseShared1 < Base
end


# Initializes a new {Scanners::WhoisRegistryOm} instance
# Initializes a new {Scanners::BaseShared1} instance
# passing the {#content_for_scanner}
# and calls +parse+ on it.
#
Expand Down
143 changes: 143 additions & 0 deletions lib/whois/record/parser/base_shared2.rb
@@ -0,0 +1,143 @@
#--
# 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/base_shared2'


module Whois
class Record
class Parser

# Shared parser 2.
#
# @abstract
#
# @since RELEASE
class BaseShared2 < Base
include Scanners::Ast

# Actually the :disclaimer is supported,
# but extracting it with the current scanner
# would require too much effort.
# property_supported :disclaimer


property_supported :domain do
node("Domain Name", &:downcase)
end

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


property_not_supported :referral_whois

property_not_supported :referral_url


property_supported :status do
node("Domain Status")
end

property_supported :available? do
!!node("status:available")
end

property_supported :registered? do
!available?
end


property_supported :created_on do
node("Domain Registration Date") { |value| Time.parse(value) }
end

property_supported :updated_on do
node("Domain Last Updated Date") { |value| Time.parse(value) }
end

property_supported :expires_on do
node("Domain Expiration Date") { |value| Time.parse(value) }
end


property_supported :registrar do
node("Sponsoring Registrar") do |str|
Record::Registrar.new(
:id => node("Sponsoring Registrar IANA ID"),
:name => node("Sponsoring Registrar")
)
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("Name Server")).map do |name|
Nameserver.new(:name => name.downcase)
end
end


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


private

def build_contact(element, type)
node("#{element} ID") do |str|
address = (1..3).
map { |i| node("#{element} Address#{i}") }.
delete_if(&:nil?).
join("\n")

Record::Contact.new(
:type => type,
:id => node("#{element} ID"),
:name => node("#{element} Name"),
:organization => node("#{element} Organization"),
:address => address,
:city => node("#{element} City"),
:zip => node("#{element} Postal Code"),
:state => node("#{element} State/Province"),
:country => node("#{element} Country"),
:country_code => node("#{element} Country Code"),
:phone => node("#{element} Phone Number"),
:fax => node("#{element} Facsimile Number"),
:email => node("#{element} Email")
)
end
end

end

end
end
end
119 changes: 6 additions & 113 deletions lib/whois/record/parser/whois.biz.rb
Expand Up @@ -7,126 +7,19 @@
#++


require 'whois/record/parser/base'
require 'whois/record/scanners/whois.biz.rb'
require 'whois/record/parser/base_shared2'


module Whois
class Record
class Parser

# Parser for the whois.biz server.
class WhoisBiz < Base
include Scanners::Ast

# Actually the :disclaimer is supported,
# but extracting it with the current scanner
# would require too much effort.
# property_supported :disclaimer


property_supported :domain do
node("Domain Name", &:downcase)
end

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


property_not_supported :referral_whois

property_not_supported :referral_url


property_supported :status do
node("Domain Status")
end

property_supported :available? do
!!node("status:available")
end

property_supported :registered? do
!available?
end


property_supported :created_on do
node("Domain Registration Date") { |value| Time.parse(value) }
end

property_supported :updated_on do
node("Domain Last Updated Date") { |value| Time.parse(value) }
end

property_supported :expires_on do
node("Domain Expiration Date") { |value| Time.parse(value) }
end


property_supported :registrar do
node("Sponsoring Registrar") do |str|
Record::Registrar.new(
:id => node("Sponsoring Registrar IANA ID"),
:name => node("Sponsoring Registrar")
)
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("Name Server")).map do |name|
Nameserver.new(:name => name.downcase)
end
end


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


private

def build_contact(element, type)
node("#{element} ID") do |str|
Record::Contact.new(
:type => type,
:id => node("#{element} ID"),
:name => node("#{element} Name"),
:organization => node("#{element} Organization"),
:address => node("#{element} Address1"),
:city => node("#{element} City"),
:zip => node("#{element} Postal Code"),
:state => node("#{element} State/Province"),
:country => node("#{element} Country"),
:country_code => node("#{element} Country Code"),
:phone => node("#{element} Phone Number"),
:fax => node("#{element} Facsimile Number"),
:email => node("#{element} Email")
)
end
end

#
# @see Whois::Record::Parser::Example
# The Example parser for the list of all available methods.
#
class WhoisBiz < BaseShared2
end

end
Expand Down
53 changes: 4 additions & 49 deletions lib/whois/record/parser/whois.nic.co.rb
Expand Up @@ -7,64 +7,19 @@
#++


require 'whois/record/parser/base'
require 'whois/record/parser/base_shared2'


module Whois
class Record
class Parser

#
# = whois.nic.co parser
#
# Parser for the whois.nic.co server.
#
# 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.
# @see Whois::Record::Parser::Example
# The Example parser for the list of all available methods.
#
class WhoisNicCo < Base

property_supported :status do
content_for_scanner.scan(/Domain Status:\s+(.*?)\n/).flatten
end

property_supported :available? do
!!(content_for_scanner =~ /Not found:/)
end

property_supported :registered? do
!available?
end


property_supported :created_on do
if content_for_scanner =~ /Domain Registration Date:\s+(.*)\n/
Time.parse($1)
end
end

property_supported :updated_on do
if content_for_scanner =~ /Domain Last Updated Date:\s+(.*)\n/
Time.parse($1)
end
end

property_supported :expires_on do
if content_for_scanner =~ /Domain Expiration Date:\s+(.*)\n/
Time.parse($1)
end
end


property_supported :nameservers do
content_for_scanner.scan(/Name Server:\s+(.+)\n/).flatten.map do |name|
Record::Nameserver.new(:name => name.downcase)
end
end

class WhoisNicCo < BaseShared2
end

end
Expand Down
3 changes: 3 additions & 0 deletions lib/whois/record/parser/whois.registry.qa.rb
Expand Up @@ -16,6 +16,9 @@ class Parser

# Parser for the whois.registry.qa server.
#
# @see Whois::Record::Parser::Example
# The Example parser for the list of all available methods.
#
# @since 2.1.0
class WhoisRegistryQa < BaseShared1
end
Expand Down
4 changes: 4 additions & 0 deletions lib/whois/record/scanners/base.rb
Expand Up @@ -43,6 +43,10 @@ def parse
@input.skip(/^\n/)
end

tokenizer :skip_blank_line do
@input.skip(/^[\s]*\n/)
end

tokenizer :skip_newline do
@input.skip(/\n/)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/whois/record/scanners/base_shared1.rb
Expand Up @@ -25,7 +25,7 @@ class BaseShared1 < Base

tokenizer :scan_available do
if @input.skip(/^No Data Found\n/)
@ast['status:available'] = true
@ast["status:available"] = true
end
end

Expand Down

0 comments on commit 969d9d8

Please sign in to comment.