/
base_afilias.rb
150 lines (115 loc) · 3.75 KB
/
base_afilias.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#--
# Ruby Whois
#
# An intelligent pure Ruby WHOIS client and parser.
#
# Copyright (c) 2009-2013 Simone Carletti <weppos@weppos.net>
#++
require 'whois/record/parser/base'
require 'whois/record/scanners/base_afilias'
module Whois
class Record
class Parser
# Base parser for Afilias servers.
#
# @abstract
class BaseAfilias < Base
include Scanners::Nodable
property_supported :disclaimer do
node("field:disclaimer")
end
property_supported :domain do
node("Domain Name", &:downcase)
end
property_supported :domain_id do
node("Domain ID")
end
property_supported :status do
Array.wrap(node("Status"))
end
property_supported :available? do
!!node("status:available")
end
property_supported :registered? do
!available?
end
property_supported :created_on do
node("Created On") do |value|
Time.parse(value)
end
end
property_supported :updated_on do
node("Last Updated On") do |value|
Time.parse(value)
end
end
property_supported :expires_on do
node("Expiration Date") do |value|
Time.parse(value)
end
end
property_supported :registrar do
node("Sponsoring Registrar") do |value|
parts = decompose_registrar(value) ||
Whois.bug!(ParserError, "Unknown registrar format `#{value}'")
Record::Registrar.new(
:id => parts[0],
:name => parts[1],
:organization => parts[1]
)
end
end
property_supported :registrant_contacts do
build_contact("Registrant", Whois::Record::Contact::TYPE_REGISTRANT)
end
property_supported :admin_contacts do
build_contact("Admin", Whois::Record::Contact::TYPE_ADMIN)
end
property_supported :technical_contacts do
build_contact("Tech", Whois::Record::Contact::TYPE_TECHNICAL)
end
property_supported :nameservers do
Array.wrap(node("Name Server")).reject(&:empty?).map do |name|
Nameserver.new(:name => name.downcase)
end
end
# Initializes a new {Scanners::Afilias} instance
# passing the {#content_for_scanner}
# and calls +parse+ on it.
#
# @return [Hash]
def parse
Scanners::BaseAfilias.new(content_for_scanner).parse
end
private
def build_contact(element, type)
node("#{element} ID") do
address = (1..3).
map { |i| node("#{element} Street#{i}") }.
delete_if { |i| i.nil? || i.empty? }.
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_code => node("#{element} Country"),
:phone => node("#{element} Phone"),
:fax => node("#{element} FAX"),
:email => node("#{element} Email")
)
end
end
def decompose_registrar(value)
if value =~ /(.+?) \((.+?)\)/
[$2, $1]
end
end
end
end
end
end