whois 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,6 +1,13 @@
1
1
  = Changelog
2
2
 
3
3
 
4
+ == Release 1.1.2
5
+
6
+ * NEW: Whois::Answer::Contact#type property returns the type of the contact (ADMIN, TECHNICAL, ...).
7
+
8
+ * FIXED: Whois::Answer::Parser::Base#contacts decomposes each Contact property in a single contact.
9
+
10
+
4
11
  == Release 1.1.1
5
12
 
6
13
  * FIXED: Deprecated methods Whois::Answer::Parser::Base#(admin|technical|registrant) didn't figure as supported with Whois::Answer#property_supported?(:method)
data/Manifest CHANGED
@@ -375,10 +375,10 @@ test/testcases/responses/whois.nic.io/registered.txt
375
375
  test/testcases/responses/whois.nic.it/available.txt
376
376
  test/testcases/responses/whois.nic.it/property_admin_contact.txt
377
377
  test/testcases/responses/whois.nic.it/property_registrant_contact.txt
378
+ test/testcases/responses/whois.nic.it/property_status_active.txt
379
+ test/testcases/responses/whois.nic.it/property_status_available.txt
378
380
  test/testcases/responses/whois.nic.it/property_technical_contact.txt
379
381
  test/testcases/responses/whois.nic.it/registered.txt
380
- test/testcases/responses/whois.nic.it/status_active.txt
381
- test/testcases/responses/whois.nic.it/status_available.txt
382
382
  test/testcases/responses/whois.nic.lv/available.txt
383
383
  test/testcases/responses/whois.nic.lv/registered.txt
384
384
  test/testcases/responses/whois.nic.ly/available.txt
@@ -28,7 +28,7 @@ module Whois
28
28
  # A <tt>Contact</tt> is composed by the following attributes:
29
29
  #
30
30
  # * <tt>:id</tt>:
31
- # * <tt>:type</tt>: the contact type.
31
+ # * <tt>:type</tt>: the contact type (1 = registrant, 2 = admin, 3 = technical).
32
32
  # * <tt>:name</tt>:
33
33
  # * <tt>:organization</tt>:
34
34
  # * <tt>:address</tt>:
@@ -46,10 +46,15 @@ module Whois
46
46
  # Be aware that every WHOIS server can return a different number of details
47
47
  # or no details at all.
48
48
  #
49
- class Contact < SuperStruct.new(:id, :name, :organization, :type,
49
+ class Contact < SuperStruct.new(:id, :type, :name, :organization,
50
50
  :address, :city, :zip, :state, :country, :country_code,
51
51
  :phone, :fax, :email,
52
52
  :created_on, :updated_on)
53
+
54
+ TYPE_REGISTRANT = 1
55
+ TYPE_ADMIN = 2
56
+ TYPE_TECHNICAL = 3
57
+
53
58
  end
54
59
 
55
60
  end
@@ -224,9 +224,9 @@ module Whois
224
224
  # Returns an array of all supported contacts.
225
225
  def contacts
226
226
  contacts = []
227
- contacts.concat([*registrant_contact]) if property_supported?(:registrant_contact)
228
- contacts.concat([*admin_contact]) if property_supported?(:admin_contact)
229
- contacts.concat([*technical_contact]) if property_supported?(:technical_contact)
227
+ contacts.concat(registrant_contact.is_a?(Array) ? registrant_contact : [registrant_contact]) if property_supported?(:registrant_contact)
228
+ contacts.concat(admin_contact.is_a?(Array) ? admin_contact : [admin_contact]) if property_supported?(:admin_contact)
229
+ contacts.concat(technical_contact.is_a?(Array) ? technical_contact : [technical_contact]) if property_supported?(:technical_contact)
230
230
  contacts.compact
231
231
  end
232
232
 
@@ -61,23 +61,23 @@ module Whois
61
61
  node("Zone-C") do |raw|
62
62
  Answer::Registrar.new(
63
63
  :id => nil,
64
- :name => raw.name,
65
- :organization => raw.organization,
64
+ :name => raw["name"],
65
+ :organization => raw["organization"],
66
66
  :url => nil
67
67
  )
68
68
  end
69
69
  end
70
70
 
71
71
  property_supported :registrant_contact do
72
- @registrant_contact ||= node("Holder")
72
+ @registrant_contact ||= contact("Holder", Whois::Answer::Contact::TYPE_REGISTRANT)
73
73
  end
74
74
 
75
75
  property_supported :admin_contact do
76
- @admin_contact ||= node("Admin-C")
76
+ @admin_contact ||= contact("Admin-C", Whois::Answer::Contact::TYPE_ADMIN)
77
77
  end
78
78
 
79
79
  property_supported :technical_contact do
80
- @technical_contact ||= node("Tech-C")
80
+ @technical_contact ||= contact("Tech-C", Whois::Answer::Contact::TYPE_TECHNICAL)
81
81
  end
82
82
 
83
83
  # @deprecated
@@ -110,6 +110,14 @@ module Whois
110
110
  Scanner.new(content_for_scanner).parse
111
111
  end
112
112
 
113
+ def contact(element, type)
114
+ node(element) do |raw|
115
+ Answer::Contact.new(raw) do |c|
116
+ c.type = type
117
+ end
118
+ end
119
+ end
120
+
113
121
 
114
122
  class Scanner
115
123
 
@@ -176,22 +184,22 @@ module Whois
176
184
  contact = {}
177
185
  while parse_pair(contact)
178
186
  end
179
- @ast[contact_name] = Answer::Contact.new(
180
- :id => nil,
181
- :name => contact['Name'],
182
- :organization => contact['Organisation'],
183
- :address => contact['Address'],
184
- :city => contact['City'],
185
- :zip => contact['Pcode'],
186
- :state => nil,
187
- :country => nil,
188
- :country_code => contact['Country'],
189
- :phone => contact['Phone'],
190
- :fax => contact['Fax'],
191
- :email => contact['Email'],
192
- :created_on => nil,
193
- :updated_on => contact['Changed']
194
- )
187
+ @ast[contact_name] = {
188
+ "id" => nil,
189
+ "name" => contact['Name'],
190
+ "organization" => contact['Organisation'],
191
+ "address" => contact['Address'],
192
+ "city" => contact['City'],
193
+ "zip" => contact['Pcode'],
194
+ "state" => nil,
195
+ "country" => nil,
196
+ "country_code" => contact['Country'],
197
+ "phone" => contact['Phone'],
198
+ "fax" => contact['Fax'],
199
+ "email" => contact['Email'],
200
+ "created_on" => nil,
201
+ "updated_on" => contact['Changed']
202
+ }
195
203
  true
196
204
  else
197
205
  false
@@ -87,26 +87,27 @@ module Whois
87
87
  return unless registered?
88
88
  return @registrant_contact if @registrant_contact
89
89
 
90
- address, city, zip, country_code = decompose_address(node('address'))
90
+ address, city, zip, country_code = decompose_address(node("address"))
91
91
 
92
- @registrant_contact = Answer::Contact.new(
93
- :name => node('name'),
94
- :organization => node('org'),
92
+ @registrant_contact = Whois::Answer::Contact.new(
93
+ :type => Whois::Answer::Contact::TYPE_REGISTRANT,
94
+ :name => node("name"),
95
+ :organization => node("org"),
95
96
  :address => address,
96
97
  :city => city,
97
98
  :zip => zip,
98
99
  :country_code => country_code,
99
- :phone => node('phone'),
100
- :fax => node('fax-no')
100
+ :phone => node("phone"),
101
+ :fax => node("fax-no")
101
102
  )
102
103
  end
103
104
 
104
105
  property_supported :admin_contact do
105
- @admin_contact ||= contact('admin-c')
106
+ @admin_contact ||= contact("admin-c", Whois::Answer::Contact::TYPE_ADMIN)
106
107
  end
107
108
 
108
109
  property_supported :technical_contact do
109
- @tecnical_contact ||= contact('tech-c')
110
+ @tecnical_contact ||= contact("tech-c", Whois::Answer::Contact::TYPE_TECHNICAL)
110
111
  end
111
112
 
112
113
  # @deprecated
@@ -118,16 +119,16 @@ module Whois
118
119
 
119
120
 
120
121
  property_supported :nameservers do
121
- @nameservers ||= node('nameserver') || []
122
+ @nameservers ||= node("nameserver") || []
122
123
  end
123
124
 
124
125
 
125
126
  def registrar_contact
126
- contact('registrar')
127
+ contact("registrar", nil)
127
128
  end
128
129
 
129
130
  def zone_contact
130
- contact('zone-c')
131
+ contact("zone-c", nil)
131
132
  end
132
133
 
133
134
 
@@ -137,9 +138,10 @@ module Whois
137
138
  Scanner.new(content_for_scanner).parse
138
139
  end
139
140
 
140
- def contact(element)
141
+ def contact(element, type)
141
142
  node(node(element)) do |raw|
142
- Answer::Contact.new do |c|
143
+ Whois::Answer::Contact.new do |c|
144
+ c.type = type
143
145
  raw.each { |k,v| c[k.to_sym] = v }
144
146
  end
145
147
  end
@@ -31,13 +31,13 @@ module Whois
31
31
 
32
32
  # Returns the registry disclaimer that comes with the answer.
33
33
  property_supported :disclaimer do
34
- node("Disclaimer")
34
+ @disclaimer ||= node("Disclaimer")
35
35
  end
36
36
 
37
37
 
38
38
  # If available, returns the domain name as stored by the registry.
39
39
  property_supported :domain do
40
- node("Domain") { |raw| raw.downcase }
40
+ @domain ||= node("Domain") { |raw| raw.downcase }
41
41
  end
42
42
 
43
43
  # If available, returns the unique domain ID set by the registry.
@@ -47,7 +47,7 @@ module Whois
47
47
  # Returns the record status or an array of status,
48
48
  # in case the registry supports it.
49
49
  property_supported :status do
50
- node("Status") { |raw| raw.downcase.to_sym }
50
+ @status ||= node("Status") { |raw| raw.downcase.to_sym }
51
51
  end
52
52
 
53
53
  # Returns whether this record is available.
@@ -64,26 +64,26 @@ module Whois
64
64
  # If available, returns a Time object representing the date
65
65
  # the record was created, according to the registry answer.
66
66
  property_supported :created_on do
67
- node("Created") { |raw| Time.parse(raw) }
67
+ @created_on ||= node("Created") { |raw| Time.parse(raw) }
68
68
  end
69
69
 
70
70
  # If available, returns a Time object representing the date
71
71
  # the record was last updated, according to the registry answer.
72
72
  property_supported :updated_on do
73
- node("Last Update") { |raw| Time.parse(raw) }
73
+ @updated_on ||= node("Last Update") { |raw| Time.parse(raw) }
74
74
  end
75
75
 
76
76
  # If available, returns a Time object representing the date
77
77
  # the record is set to expire, according to the registry answer.
78
78
  property_supported :expires_on do
79
- node("Expire Date") { |raw| Time.parse(raw) }
79
+ @expires_on ||= node("Expire Date") { |raw| Time.parse(raw) }
80
80
  end
81
81
 
82
82
 
83
83
  # If available, returns a <tt>Whois::Answer::Registrar</tt> record
84
84
  # containing the registrar details extracted from the registry answer.
85
85
  property_supported :registrar do
86
- node("Registrar") do |raw|
86
+ @registrar ||= node("Registrar") do |raw|
87
87
  Answer::Registrar.new(
88
88
  :id => raw["Name"],
89
89
  :name => raw["Name"],
@@ -95,19 +95,19 @@ module Whois
95
95
  # If available, returns a <tt>Whois::Answer::Contact</tt> record
96
96
  # containing the registrant details extracted from the registry answer.
97
97
  property_supported :registrant_contact do
98
- @registrant_contact ||= contact("Registrant")
98
+ @registrant_contact ||= contact("Registrant", Whois::Answer::Contact::TYPE_REGISTRANT)
99
99
  end
100
100
 
101
101
  # If available, returns a <tt>Whois::Answer::Contact</tt> record
102
102
  # containing the admin contact details extracted from the registry answer.
103
103
  property_supported :admin_contact do
104
- @admin_contact ||= contact("Admin Contact")
104
+ @admin_contact ||= contact("Admin Contact", Whois::Answer::Contact::TYPE_ADMIN)
105
105
  end
106
106
 
107
107
  # If available, returns a <tt>Whois::Answer::Contact</tt> record
108
108
  # containing the technical contact details extracted from the registry answer.
109
109
  property_supported :technical_contact do
110
- @technical_contact ||= contact("Technical Contacts")
110
+ @technical_contact ||= contact("Technical Contacts", Whois::Answer::Contact::TYPE_TECHNICAL)
111
111
  end
112
112
 
113
113
  # @deprecated
@@ -166,11 +166,12 @@ module Whois
166
166
  Scanner.new(content_for_scanner).parse
167
167
  end
168
168
 
169
- def contact(element)
169
+ def contact(element, type)
170
170
  node(element) do |raw|
171
171
  address = (raw["Address"] || "").split("\n")
172
172
  Answer::Contact.new(
173
173
  :id => raw["ContactID"],
174
+ :type => type,
174
175
  :name => raw["Name"],
175
176
  :organization => raw["Organization"],
176
177
  :address => address[0],
@@ -30,21 +30,21 @@ module Whois
30
30
  include Ast
31
31
 
32
32
  property_supported :disclaimer do
33
- node("Disclaimer")
33
+ @disclaimer ||= node("Disclaimer")
34
34
  end
35
35
 
36
36
 
37
37
  property_supported :domain do
38
- node("Domain Name") { |value| value.downcase }
38
+ @domain ||= node("Domain Name") { |value| value.downcase }
39
39
  end
40
40
 
41
41
  property_supported :domain_id do
42
- node("Domain ID")
42
+ @domain_id ||= node("Domain ID")
43
43
  end
44
44
 
45
45
 
46
46
  property_supported :status do
47
- node("Status")
47
+ @status ||= node("Status")
48
48
  end
49
49
 
50
50
  property_supported :available? do
@@ -57,26 +57,26 @@ module Whois
57
57
 
58
58
 
59
59
  property_supported :created_on do
60
- node("Created On") { |value| Time.parse(value) }
60
+ @created_on ||= node("Created On") { |value| Time.parse(value) }
61
61
  end
62
62
 
63
63
  property_supported :updated_on do
64
- node("Last Updated On") { |value| Time.parse(value) }
64
+ @updated_on ||= node("Last Updated On") { |value| Time.parse(value) }
65
65
  end
66
66
 
67
67
  property_supported :expires_on do
68
- node("Expiration Date") { |value| Time.parse(value) }
68
+ @expires_on ||= node("Expiration Date") { |value| Time.parse(value) }
69
69
  end
70
70
 
71
-
71
+
72
72
  property_supported :registrar do
73
- node("Sponsoring Registrar") do |registrar|
73
+ @registrar ||= node("Sponsoring Registrar") do |registrar|
74
74
  id, name = if registrar =~ /(.*?)\((.*?)\)/
75
75
  [$2.strip, $1.strip]
76
76
  else
77
77
  [nil, registrar]
78
78
  end
79
- Answer::Registrar.new(
79
+ Whois::Answer::Registrar.new(
80
80
  :id => id,
81
81
  :name => name
82
82
  )
@@ -84,15 +84,15 @@ module Whois
84
84
  end
85
85
 
86
86
  property_supported :registrant_contact do
87
- contact("Registrant")
87
+ @registrant_contact ||= contact("Registrant", Whois::Answer::Contact::TYPE_REGISTRANT)
88
88
  end
89
89
 
90
90
  property_supported :admin_contact do
91
- contact("Admin")
91
+ @admin_contact ||= contact("Admin", Whois::Answer::Contact::TYPE_ADMIN)
92
92
  end
93
93
 
94
94
  property_supported :technical_contact do
95
- contact("Tech")
95
+ @technical_contact ||= contact("Tech", Whois::Answer::Contact::TYPE_TECHNICAL)
96
96
  end
97
97
 
98
98
  # @deprecated
@@ -125,10 +125,11 @@ module Whois
125
125
  Scanner.new(content_for_scanner).parse
126
126
  end
127
127
 
128
- def contact(element)
128
+ def contact(element, type)
129
129
  node("#{element} ID") do |registrant_id|
130
- Answer::Contact.new(
130
+ Whois::Answer::Contact.new(
131
131
  :id => registrant_id,
132
+ :type => type,
132
133
  :name => node("#{element} Name"),
133
134
  :organization => node("#{element} Organization"),
134
135
  :address => [node("#{element} Street1"),
data/lib/whois/version.rb CHANGED
@@ -19,7 +19,7 @@ module Whois
19
19
  module Version
20
20
  MAJOR = 1
21
21
  MINOR = 1
22
- PATCH = 1
22
+ PATCH = 2
23
23
 
24
24
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
25
25
  end
@@ -51,15 +51,15 @@ class AnswerParserBaseTest < Test::Unit::TestCase
51
51
  end
52
52
 
53
53
  def test_contacts_should_return_all_supported_contacts
54
- c1 = "1st"
55
- c2 = "2nd"
56
- c3 = "3rd"
54
+ c1 = Whois::Answer::Contact.new(:id => "1st", :name => "foo")
55
+ c2 = Whois::Answer::Contact.new(:id => "2nd", :name => "foo")
56
+ c3 = Whois::Answer::Contact.new(:id => "3rd", :name => "foo")
57
57
  klass = Class.new(@klass) do
58
58
  register_property(:registrant_contact, :supported) { [c1, c2] }
59
59
  register_property(:admin_contact, :supported) { nil }
60
60
  register_property(:technical_contact, :supported) { c3 }
61
61
  end
62
- assert_equal [c1, c2, c3], klass.new(@part).contacts
62
+ assert_equal ["1st", "2nd", "3rd"], klass.new(@part).contacts.map(&:id)
63
63
  end
64
64
 
65
65
 
@@ -185,6 +185,7 @@ http://www.denic.de/en/background/whois-service/webwhois.html
185
185
 
186
186
  assert_instance_of Whois::Answer::Contact, result
187
187
  assert_equal nil, result.id
188
+ assert_equal Whois::Answer::Contact::TYPE_TECHNICAL, result.type
188
189
  assert_equal 'Google Inc.', result.name
189
190
  assert_equal nil, result.organization
190
191
  assert_equal ['Google Inc.', '1600 Amphitheatre Parkway'], result.address
@@ -138,6 +138,7 @@ EOS
138
138
  result = parser.registrant_contact
139
139
 
140
140
  assert_instance_of Whois::Answer::Contact, result
141
+ assert_equal Whois::Answer::Contact::TYPE_REGISTRANT, result.type
141
142
  assert_equal 'Google, Inc.', result.name
142
143
  assert_equal 'Google, Inc.', result.organization
143
144
  assert_equal 'Amphitheatre Pkwy 1600.', result.address
@@ -153,6 +154,7 @@ EOS
153
154
  result = parser.registrant_contact
154
155
 
155
156
  assert_instance_of Whois::Answer::Contact, result
157
+ assert_equal Whois::Answer::Contact::TYPE_REGISTRANT, result.type
156
158
  assert_match /Buruzs/, result.name # UTF-8 hack
157
159
  assert_equal nil, result.organization
158
160
  assert_equal nil, result.address
@@ -174,16 +176,17 @@ EOS
174
176
  end
175
177
 
176
178
  def test_admin_contact_with_registered
177
- admin = @klass.new(load_part('/registered.txt')).admin_contact
178
- assert_instance_of Whois::Answer::Contact, admin
179
- assert_equal '2000466366', admin.id
180
- assert_equal '3C Kft. (Registrar)', admin.name
181
- assert_equal 'Konkoly Thege út 29-33.', admin.address
182
- assert_equal 'H-1121', admin.zip
183
- assert_equal 'Budapest', admin.city
184
- assert_equal 'HU', admin.country_code
185
- assert_equal '+36 1 275 52 00', admin.phone
186
- assert_equal '+36 1 275 58 87', admin.fax
179
+ result = @klass.new(load_part('/registered.txt')).admin_contact
180
+ assert_instance_of Whois::Answer::Contact, result
181
+ assert_equal Whois::Answer::Contact::TYPE_ADMIN, result.type
182
+ assert_equal '2000466366', result.id
183
+ assert_equal '3C Kft. (Registrar)', result.name
184
+ assert_equal 'Konkoly Thege út 29-33.', result.address
185
+ assert_equal 'H-1121', result.zip
186
+ assert_equal 'Budapest', result.city
187
+ assert_equal 'HU', result.country_code
188
+ assert_equal '+36 1 275 52 00', result.phone
189
+ assert_equal '+36 1 275 58 87', result.fax
187
190
  end
188
191
 
189
192
  def test_admin_contact_with_unregistered
@@ -199,17 +202,18 @@ EOS
199
202
  end
200
203
 
201
204
  def test_technical_contact_with_registered
202
- technical = @klass.new(load_part('/registered.txt')).technical_contact
203
- assert_instance_of Whois::Answer::Contact, technical
204
- assert_equal '2000578125', technical.id
205
- assert_equal 'Markmonitor', technical.name
206
- assert_equal 'Overland Road 10400, PMB155', technical.address
207
- assert_equal 'ID-83709', technical.zip
208
- assert_equal 'Boise', technical.city
209
- assert_equal 'US', technical.country_code
210
- assert_equal '+ 1 208 389 5798', technical.phone
211
- assert_equal '+ 1 208 389 5771', technical.fax
212
- assert_equal 'ccops@markmonitor.com', technical.email
205
+ result = @klass.new(load_part('/registered.txt')).technical_contact
206
+ assert_instance_of Whois::Answer::Contact, result
207
+ assert_equal Whois::Answer::Contact::TYPE_TECHNICAL, result.type
208
+ assert_equal '2000578125', result.id
209
+ assert_equal 'Markmonitor', result.name
210
+ assert_equal 'Overland Road 10400, PMB155', result.address
211
+ assert_equal 'ID-83709', result.zip
212
+ assert_equal 'Boise', result.city
213
+ assert_equal 'US', result.country_code
214
+ assert_equal '+ 1 208 389 5798', result.phone
215
+ assert_equal '+ 1 208 389 5771', result.fax
216
+ assert_equal 'ccops@markmonitor.com', result.email
213
217
  end
214
218
 
215
219
  def test_technical_contact_with_unregistered