whoisxmlapi 0.2.3 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/whoisxmlapi/client.rb +177 -106
- data/lib/whoisxmlapi/contact.rb +19 -0
- data/lib/whoisxmlapi/result.rb +37 -8
- data/lib/whoisxmlapi/rwhois_result.rb +5 -9
- data/lib/whoisxmlapi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2442b889d8fed140f51f7d83bf621f30403d81bace0d7fa3f16db5fba1c61ba5
|
4
|
+
data.tar.gz: 248927a9e820129a2cb6bfe0ba3656de0e361d9624ca375f0896fd55f1a774f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba31775e1e05d8b9c482ab67b52858d401defa81b746a8e5a7913a6da3536f38c2786337c9d0c47cb402779d90408445cf98ac3ebc2b9fd526dacea03efad509
|
7
|
+
data.tar.gz: 1e9d36cf33a50560a604ffdf5085228dbb7ff51f53b4721568a5da72095b1f507e05e97de5babd48149795bdfab5b6baedae7f822c5c0afc703711106612bcc2
|
data/lib/whoisxmlapi/client.rb
CHANGED
@@ -7,74 +7,129 @@ module WhoisXMLAPI
|
|
7
7
|
|
8
8
|
class Client
|
9
9
|
|
10
|
+
####################################################################################################
|
11
|
+
# Whois
|
12
|
+
####################################################################################################
|
13
|
+
|
10
14
|
# https://whoisapi.whoisxmlapi.com/docs
|
11
15
|
# GET https://www.whoisxmlapi.com/whoisserver/WhoisService?apiKey=YOUR_API_KEY&domainName=google.com
|
12
|
-
def
|
16
|
+
def whois_cacheless(domain, owner=nil)
|
13
17
|
unless PublicSuffix.valid?(domain)
|
14
|
-
res = WhoisXMLAPI::BadDomain.new
|
18
|
+
res = WhoisXMLAPI::BadDomain.new(:whoisable => owner)
|
15
19
|
res.parse(domain)
|
16
20
|
return res
|
17
21
|
end
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
params = {
|
25
|
-
:apiKey => WhoisXMLAPI.api_key,
|
26
|
-
:domainName => domain,
|
27
|
-
:outputFormat => 'JSON'
|
28
|
-
}
|
29
|
-
|
30
|
-
begin
|
31
|
-
r = HTTParty.get(WhoisXMLAPI.whois_path, :query => params, :timeout => 120)
|
32
|
-
rescue StandardError => e
|
33
|
-
WhoisXMLAPI.logger.info "WhoisXMLAPI#whois - Error getting Whois info for #{domain}: #{e}"
|
34
|
-
res = WhoisXMLAPI::Unavailable.new
|
35
|
-
res.parse(domain)
|
36
|
-
return res
|
37
|
-
end
|
23
|
+
params = {
|
24
|
+
:apiKey => WhoisXMLAPI.api_key,
|
25
|
+
:domainName => domain,
|
26
|
+
:outputFormat => 'JSON'
|
27
|
+
}
|
38
28
|
|
29
|
+
begin
|
30
|
+
r = HTTParty.get(WhoisXMLAPI.whois_path, :query => params, :timeout => 120)
|
31
|
+
rescue StandardError => e
|
32
|
+
WhoisXMLAPI.logger.info "WhoisXMLAPI#whois - Error getting Whois info for \'#{domain}\': #{e}"
|
33
|
+
res = WhoisXMLAPI::Unavailable.new(:whoisable => owner)
|
34
|
+
res.parse(domain) # parse will save document for Unavailable
|
35
|
+
else
|
39
36
|
if WhoisXMLAPI.callbacks[:whois]
|
40
|
-
WhoisXMLAPI.callbacks[:whois].each
|
41
|
-
cb.call
|
42
|
-
end
|
37
|
+
WhoisXMLAPI.callbacks[:whois].each{ |cb| cb.call }
|
43
38
|
end
|
44
|
-
|
45
39
|
# WhoisXML and HTTParty are sometimes returning a Hash and not a JSON string as requested,
|
46
40
|
# which is causing an error of "no implicit conversion of Hash into String" when we call JSON.parse.
|
47
41
|
# Logger message is to monitor whether WhoisXML and/or HTTParty will still return a string on occasion.
|
48
42
|
if r
|
49
43
|
if r.parsed_response.is_a?(String)
|
50
|
-
WhoisXMLAPI.logger.debug "WhoisXMLAPI#whois - WARNING: passed back parsed_response as a String instead of a Hash for #{domain}."
|
51
|
-
presponse = JSON.parse(r.parsed_response)
|
44
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#whois - WARNING: passed back parsed_response as a String instead of a Hash for \'#{domain}\'."
|
45
|
+
presponse = JSON.parse(r.parsed_response) rescue nil
|
52
46
|
else
|
53
47
|
presponse = r.parsed_response
|
54
48
|
end
|
55
|
-
|
49
|
+
|
50
|
+
if presponse.nil?
|
51
|
+
res = {:error => {message: 'Failed to parse response from API.'}}
|
52
|
+
elsif presponse.key? 'ErrorMessage'
|
56
53
|
WhoisXMLAPI.logger.info "WhoisXMLAPI#whois - Error getting Whois info: #{presponse['ErrorMessage']['msg']}"
|
57
|
-
res = WhoisXMLAPI::Unavailable.new
|
58
|
-
res.parse(domain)
|
54
|
+
res = WhoisXMLAPI::Unavailable.new(:whoisable => owner)
|
55
|
+
res.parse(domain) # parse will save document for Unavailable
|
59
56
|
elsif (200..299).include? r.code.to_i
|
60
|
-
res = WhoisXMLAPI::Good.new
|
61
|
-
res.parse(presponse['WhoisRecord'])
|
57
|
+
res = WhoisXMLAPI::Good.new(:whoisable => owner)
|
58
|
+
res.parse(presponse['WhoisRecord']) # parse will NOT save document for Good or UnParsable
|
62
59
|
res.save
|
63
60
|
end
|
64
61
|
end
|
62
|
+
end
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
|
64
|
+
unless res
|
65
|
+
WhoisXMLAPI.logger.info "WhoisXMLAPI#whois - Unable to get Whois info for domain: \'#{domain}\'"
|
66
|
+
res = WhoisXMLAPI::Unavailable.new(:whoisable => owner)
|
67
|
+
res.parse(domain) # parse will save document for Unavailable
|
72
68
|
end
|
69
|
+
|
73
70
|
return res
|
74
71
|
end
|
75
72
|
|
76
73
|
|
77
|
-
|
74
|
+
# https://whoisapi.whoisxmlapi.com/docs
|
75
|
+
# GET https://www.whoisxmlapi.com/whoisserver/WhoisService?apiKey=YOUR_API_KEY&domainName=google.com
|
76
|
+
def whois(domain, owner=nil)
|
77
|
+
unless PublicSuffix.valid?(domain)
|
78
|
+
res = WhoisXMLAPI::BadDomain.new
|
79
|
+
res.parse(domain)
|
80
|
+
return res
|
81
|
+
end
|
82
|
+
|
83
|
+
query = WhoisXMLAPI::Result.where(:domain => domain)
|
84
|
+
query = query.where(:created_at.gte => (Time.now - WhoisXMLAPI.cache_length)) if WhoisXMLAPI.cache
|
85
|
+
res = query.first
|
86
|
+
|
87
|
+
if res.nil? || res._type == "WhoisXMLAPI::Unavailable"
|
88
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#whois - no cached Whois data for \'#{domain}\': initiating API access."
|
89
|
+
res = whois_cacheless(domain, owner)
|
90
|
+
else
|
91
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#whois - using cached Whois data for \'#{domain}\'"
|
92
|
+
end
|
93
|
+
res
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
def exists?(domain)
|
98
|
+
params = {
|
99
|
+
:cmd => 'GET_DN_AVAILABILITY',
|
100
|
+
:domainName => domain,
|
101
|
+
:outputFormat => 'JSON',
|
102
|
+
:apiKey => WhoisXMLAPI.api_key
|
103
|
+
}
|
104
|
+
begin
|
105
|
+
r = HTTParty.get(WhoisXMLAPI.whois_path, :query => params, :timeout => 120)
|
106
|
+
rescue StandardError => e
|
107
|
+
WhoisXMLAPI.logger.info "WhoisXMLAPI#whois - Error getting Whois info for \'#{domain}\': #{e}"
|
108
|
+
res = WhoisXMLAPI::Unavailable.new
|
109
|
+
res.parse(domain)
|
110
|
+
return res
|
111
|
+
end
|
112
|
+
|
113
|
+
# WhoisXML and HTTParty are sometimes returning a Hash and not a JSON string as requested,
|
114
|
+
# which is causing an error of "no implicit conversion of Hash into String" when we call JSON.parse.
|
115
|
+
# Logger message is to monitor whether WhoisXML and/or HTTParty will still return a string on occasion.
|
116
|
+
if r.parsed_response.is_a?(String)
|
117
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#exists? - passed back parsed_response as a String instead of a Hash for \'#{domain}\'."
|
118
|
+
presponse = JSON.parse(r.parsed_response) rescue nil
|
119
|
+
else
|
120
|
+
presponse = r.parsed_response
|
121
|
+
end
|
122
|
+
|
123
|
+
presponse && presponse["DomainInfo"]["domainAvailability"] == "UNAVAILABLE"
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
####################################################################################################
|
128
|
+
# Reverse Whois
|
129
|
+
####################################################################################################
|
130
|
+
|
131
|
+
|
132
|
+
def self.send_rwhois_request(entity_name, since_dt=nil)
|
78
133
|
params = {
|
79
134
|
:apiKey => WhoisXMLAPI.api_key,
|
80
135
|
:searchType => "current",
|
@@ -82,13 +137,15 @@ module WhoisXMLAPI
|
|
82
137
|
:responseFormat => 'json',
|
83
138
|
:basicSearchTerms => {
|
84
139
|
:include => [entity_name] # must be an array of strings!
|
85
|
-
}
|
140
|
+
}
|
86
141
|
}
|
142
|
+
params[:createdDateFrom] = since_dt.strftime("%F") if since_dt
|
143
|
+
|
87
144
|
begin
|
88
145
|
# To DEBUG add ":debug_output => $stdout"
|
89
146
|
r = HTTParty.post(WhoisXMLAPI.rwhois_path, :body => params.to_json, :timeout => 120, :headers => {'Content-Type' => 'application/json'})
|
90
147
|
rescue StandardError => e
|
91
|
-
WhoisXMLAPI.logger.info "WhoisXMLAPI#rwhois - Error getting RWhois info for #{entity_name}: #{e}"
|
148
|
+
WhoisXMLAPI.logger.info "WhoisXMLAPI#rwhois - Error getting RWhois info for \'#{entity_name}\': #{e}"
|
92
149
|
r = nil
|
93
150
|
end
|
94
151
|
|
@@ -104,81 +161,76 @@ module WhoisXMLAPI
|
|
104
161
|
|
105
162
|
# https://reverse-whois-api.whoisxmlapi.com/docs
|
106
163
|
# POST https://reverse-whois-api.whoisxmlapi.com/api/v2
|
107
|
-
def
|
164
|
+
def rwhois_cacheless(entity_name, since_dt=nil, owner=nil)
|
108
165
|
# entity_name is really the domain being passed in for Rwhois not the actual entity name
|
109
|
-
return nil
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
WhoisXMLAPI.logger.debug "WhoisXMLAPI#
|
118
|
-
res
|
119
|
-
|
120
|
-
r = WhoisXMLAPI::Client.send_rwhois_request(entity_name)
|
166
|
+
return nil unless entity_name.present?
|
167
|
+
res = WhoisXMLAPI::RWhoisResult.new(:entity_name => entity_name, :rwhoisable => owner, :domains => [])
|
168
|
+
r = WhoisXMLAPI::Client.send_rwhois_request(entity_name, since_dt)
|
169
|
+
if r && r.parsed_response && r.parsed_response['domainsList']
|
170
|
+
res.domains = r.parsed_response['domainsList']
|
171
|
+
elsif PublicSuffix.valid?(entity_name)
|
172
|
+
# if no luck with what was passed in and we have a valid domain with TLD, try just the second-level domain.
|
173
|
+
domain_sld = PublicSuffix.parse(entity_name).sld
|
174
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois_cacheless - no domains found for domain \'#{entity_name}\', trying #{domain_sld}"
|
175
|
+
res.entity_name = domain_sld
|
176
|
+
r = WhoisXMLAPI::Client.send_rwhois_request(domain_sld)
|
121
177
|
if r && r.parsed_response && r.parsed_response['domainsList']
|
122
178
|
res.domains = r.parsed_response['domainsList']
|
123
|
-
res.save
|
124
|
-
elsif PublicSuffix.valid?(entity_name)
|
125
|
-
# if no luck with what was passed in and we have a valid domain with TLD, try just the second-level domain.
|
126
|
-
domain = PublicSuffix.parse(entity_name)
|
127
|
-
domain_sld = domain.sld
|
128
|
-
WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois - no domains found for domain #{entity_name}, trying #{domain_sld}"
|
129
|
-
res = WhoisXMLAPI::RWhoisResult.create(:entity_name => domain_sld)
|
130
|
-
|
131
|
-
r = WhoisXMLAPI::Client.send_rwhois_request(domain_sld)
|
132
|
-
if r && r.parsed_response && r.parsed_response['domainsList']
|
133
|
-
res.domains = r.parsed_response['domainsList']
|
134
|
-
res.save
|
135
|
-
else
|
136
|
-
res.domains = []
|
137
|
-
res.save
|
138
|
-
end
|
139
|
-
else
|
140
|
-
WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois - no domains found for #{entity_name}!"
|
141
|
-
res.domains = []
|
142
|
-
res.save
|
143
179
|
end
|
180
|
+
else
|
181
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois_cacheless - no domains found for \'#{entity_name}\'!"
|
182
|
+
end
|
183
|
+
unless res.save
|
184
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois_cacheless - ERROR saving RWhoisResult: #{res.errors.full_messages.join('; ')} - #{res}!"
|
144
185
|
end
|
145
186
|
res
|
146
187
|
end
|
147
188
|
|
148
189
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
r = HTTParty.get(WhoisXMLAPI.whois_path, :query => params, :timeout => 120)
|
158
|
-
rescue StandardError => e
|
159
|
-
WhoisXMLAPI.logger.info "WhoisXMLAPI#whois - Error getting Whois info for #{domain}: #{e}"
|
160
|
-
res = WhoisXMLAPI::Unavailable.new
|
161
|
-
res.parse(domain)
|
162
|
-
return res
|
163
|
-
end
|
190
|
+
# https://reverse-whois-api.whoisxmlapi.com/docs
|
191
|
+
# POST https://reverse-whois-api.whoisxmlapi.com/api/v2
|
192
|
+
def rwhois(entity_name, since_dt=nil, owner=nil)
|
193
|
+
# entity_name is really the domain being passed in for Rwhois not the actual entity name
|
194
|
+
return nil if entity_name.nil?
|
195
|
+
query = WhoisXMLAPI::RWhoisResult.where(:entity_name => entity_name, :rwhoisable => owner)
|
196
|
+
query = query.where(:created_at.gte => (Time.now - WhoisXMLAPI.cache_length)) if WhoisXMLAPI.cache
|
197
|
+
res = query.first
|
164
198
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
if r.parsed_response.is_a?(String)
|
169
|
-
WhoisXMLAPI.logger.debug "WhoisXMLAPI#exists? - passed back parsed_response as a String instead of a Hash for #{domain}."
|
170
|
-
resp = JSON.parse(r.parsed_response)
|
199
|
+
if res.nil?
|
200
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois - no cached RWhois data for \'#{entity_name}\': initiating API access."
|
201
|
+
res = rwhois_cacheless(entity_name, since_dt, owner)
|
171
202
|
else
|
172
|
-
|
203
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois - using cached RWhois data for \'#{entity_name}\'"
|
173
204
|
end
|
174
|
-
|
175
|
-
resp["DomainInfo"]["domainAvailability"] == "UNAVAILABLE"
|
205
|
+
res
|
176
206
|
end
|
177
207
|
|
178
208
|
|
209
|
+
####################################################################################################
|
210
|
+
# Account Balance
|
211
|
+
####################################################################################################
|
212
|
+
|
213
|
+
|
179
214
|
#
|
180
215
|
# GET https://user.whoisxmlapi.com/service/account-balance?apiKey=YOUR_API_KEY
|
216
|
+
# wc.account_balance
|
217
|
+
# =>
|
218
|
+
# {
|
219
|
+
# "Email Verification API" => {:product_id => 7, :credits => 1000},
|
220
|
+
# "IP Geolocation API" => {:product_id => 8, :credits => 1000},
|
221
|
+
# "Domain Research Suite" => {:product_id => 14, :credits => 100},
|
222
|
+
# "WHOIS API" => {:product_id => 1, :credits => 1000},
|
223
|
+
# "Domain Reputation API" => {:product_id => 20, :credits => 100},
|
224
|
+
# "IP Netblocks API" => {:product_id => 23, :credits => 1000},
|
225
|
+
# "Domain Availability API" => {:product_id => 25, :credits => 100},
|
226
|
+
# "Screenshot API" => {:product_id => 27, :credits => 500},
|
227
|
+
# "Website Categorization API" => {:product_id => 21, :credits => 100},
|
228
|
+
# "Website Contacts API" => {:product_id => 29, :credits => 100},
|
229
|
+
# "DNS Lookup API" => {:product_id => 26, :credits => 500}
|
230
|
+
# }
|
231
|
+
|
181
232
|
def account_balance
|
233
|
+
result = nil
|
182
234
|
params = {
|
183
235
|
:apiKey => WhoisXMLAPI.api_key
|
184
236
|
}
|
@@ -190,15 +242,34 @@ module WhoisXMLAPI
|
|
190
242
|
r = nil
|
191
243
|
end
|
192
244
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
245
|
+
if r && r.response.is_a?(Net::HTTPOK)
|
246
|
+
if r.parsed_response
|
247
|
+
# WhoisXML and HTTParty are sometimes returning a Hash and not a JSON string as requested,
|
248
|
+
# which is causing an error of "no implicit conversion of Hash into String" when we call JSON.parse.
|
249
|
+
# Logger message is to monitor whether WhoisXML and/or HTTParty will still return a string on occasion.
|
250
|
+
if r.parsed_response.is_a?(String)
|
251
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#account_balance - passed back parsed_response as a String instead of a Hash."
|
252
|
+
presponse = JSON.parse(r.parsed_response) rescue nil
|
253
|
+
else
|
254
|
+
presponse = r.parsed_response
|
255
|
+
end
|
200
256
|
|
201
|
-
|
257
|
+
if presponse.nil?
|
258
|
+
result = {:error => {message: 'Failed to parse response from API.'}}
|
259
|
+
elsif presponse["error"]
|
260
|
+
result = {:error => {message: presponse["error"]}}
|
261
|
+
elsif presponse["data"]
|
262
|
+
result = {}
|
263
|
+
presponse["data"].each do |datum|
|
264
|
+
key = datum["product"]["name"]
|
265
|
+
result[key] = {product_id: datum["product_id"], credits: datum["credits"]}
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
else
|
270
|
+
result = {:error =>{code: r.response.code, message: r.response.message}}
|
271
|
+
end
|
272
|
+
result
|
202
273
|
end
|
203
274
|
|
204
275
|
|
data/lib/whoisxmlapi/contact.rb
CHANGED
@@ -23,5 +23,24 @@ module WhoisXMLAPI
|
|
23
23
|
field :email
|
24
24
|
field :telephone
|
25
25
|
field :fax
|
26
|
+
|
27
|
+
def self.selectively_create_from_hash(h)
|
28
|
+
attr = {
|
29
|
+
:name => h['name'],
|
30
|
+
:organization => h['organization'],
|
31
|
+
:street1 => h['street1'],
|
32
|
+
:street2 => h['street2'],
|
33
|
+
:city => h['city'],
|
34
|
+
:state => h['state'],
|
35
|
+
:postalCode => h['postalCode'],
|
36
|
+
:country => h['country'],
|
37
|
+
:countryCode => h['countryCode'],
|
38
|
+
:email => h['email'],
|
39
|
+
:telephone => h['telephone'],
|
40
|
+
:fax => h['fax'],
|
41
|
+
}
|
42
|
+
Contact.create(attr)
|
43
|
+
end
|
44
|
+
|
26
45
|
end
|
27
46
|
end
|
data/lib/whoisxmlapi/result.rb
CHANGED
@@ -5,6 +5,9 @@ module WhoisXMLAPI
|
|
5
5
|
include Mongoid::Document
|
6
6
|
include Mongoid::Timestamps
|
7
7
|
|
8
|
+
# https://blog.bigbinary.com/2016/02/15/rails-5-makes-belong-to-association-required-by-default.html
|
9
|
+
belongs_to :whoisable, :polymorphic => true, optional: true
|
10
|
+
|
8
11
|
field :domain
|
9
12
|
field :record_created
|
10
13
|
field :record_updated
|
@@ -15,11 +18,10 @@ module WhoisXMLAPI
|
|
15
18
|
field :status
|
16
19
|
|
17
20
|
has_one :registrant, :as => :contactable, :class_name => "WhoisXMLAPI::Contact", :autosave => true
|
18
|
-
has_one :admin,
|
19
|
-
has_one :tech,
|
20
|
-
has_one :billing,
|
21
|
+
has_one :admin, :as => :contactable, :class_name => "WhoisXMLAPI::Contact", :autosave => true
|
22
|
+
has_one :tech, :as => :contactable, :class_name => "WhoisXMLAPI::Contact", :autosave => true
|
23
|
+
has_one :billing, :as => :contactable, :class_name => "WhoisXMLAPI::Contact", :autosave => true
|
21
24
|
|
22
|
-
belongs_to :whoisable, :polymorphic => true
|
23
25
|
# Actual indexing is performed in db_mongoid_extend.rake
|
24
26
|
# index([
|
25
27
|
# [ :whoisable_id, Mongo::ASCENDING ],
|
@@ -27,6 +29,7 @@ module WhoisXMLAPI
|
|
27
29
|
# ])
|
28
30
|
index({whoisable_id: 1, whoisable_type: 1})
|
29
31
|
|
32
|
+
|
30
33
|
def parse(record)
|
31
34
|
self.domain = record['domainName']
|
32
35
|
self.data_error = record['dataError'] ? record['dataError'] : nil
|
@@ -57,21 +60,47 @@ module WhoisXMLAPI
|
|
57
60
|
technical_data = record['technicalContact'] || (record['registryData'] ? record['registryData']['technicalContact'] : nil)
|
58
61
|
billing_data = record['billingContact'] || (record['registryData'] ? record['registryData']['billingContact'] : nil)
|
59
62
|
|
60
|
-
self.registrant = WhoisXMLAPI::Contact.
|
61
|
-
self.admin = WhoisXMLAPI::Contact.
|
62
|
-
self.tech = WhoisXMLAPI::Contact.
|
63
|
-
self.billing = WhoisXMLAPI::Contact.
|
63
|
+
self.registrant = WhoisXMLAPI::Contact.selectively_create_from_hash(registrant_data.merge({'email' => record['contactEmail']})) if registrant_data
|
64
|
+
self.admin = WhoisXMLAPI::Contact.selectively_create_from_hash(administrative_data) if administrative_data
|
65
|
+
self.tech = WhoisXMLAPI::Contact.selectively_create_from_hash(technical_data) if technical_data
|
66
|
+
self.billing = WhoisXMLAPI::Contact.selectively_create_from_hash(billing_data) if billing_data
|
64
67
|
end
|
65
68
|
|
69
|
+
|
66
70
|
def complete?
|
67
71
|
( self.domain and self.registrar and ( self.registrant or self.admin or self.tech) )
|
68
72
|
end
|
69
73
|
|
74
|
+
|
70
75
|
def private?
|
71
76
|
%w/networksolutionsprivateregistration.com domainprivacygroup.com/.each do |priv|
|
72
77
|
return true if self.registrant.email =~ /#{priv}/
|
73
78
|
end
|
74
79
|
false
|
75
80
|
end
|
81
|
+
|
82
|
+
|
83
|
+
def contact_email(contact)
|
84
|
+
case contact
|
85
|
+
when :registrant
|
86
|
+
registrant ? registrant.email : nil
|
87
|
+
when :admin
|
88
|
+
admin ? admin.email : nil
|
89
|
+
when :tech
|
90
|
+
tech ? tech.email : nil
|
91
|
+
when :billing
|
92
|
+
billing ? billing.email : nil
|
93
|
+
else
|
94
|
+
nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
def contact_email_host(contact)
|
100
|
+
email = contact_email(contact)
|
101
|
+
host = email.squish.split("@").last.downcase if email.present? && email.include?("@")
|
102
|
+
PublicSuffix.valid?(host) ? host : nil
|
103
|
+
end
|
104
|
+
|
76
105
|
end
|
77
106
|
end
|
@@ -3,16 +3,12 @@ module WhoisXMLAPI
|
|
3
3
|
include Mongoid::Document
|
4
4
|
include Mongoid::Timestamps
|
5
5
|
|
6
|
-
|
6
|
+
# https://blog.bigbinary.com/2016/02/15/rails-5-makes-belong-to-association-required-by-default.html
|
7
|
+
belongs_to :rwhoisable, :polymorphic => true, optional: true
|
8
|
+
|
7
9
|
# Actual indexing is performed in db_mongoid_extend.rake
|
8
|
-
# index([
|
9
|
-
# [ :rwhoisable_id, Mongo::ASCENDING ],
|
10
|
-
# [ :rwhoisable_type, Mongo::ASCENDING ]
|
11
|
-
# ])
|
12
|
-
index({rwhoisable_id: 1, rwhoisable_type: 1})
|
13
|
-
|
14
|
-
field :entity_name, :type => String
|
15
|
-
field :domains, :type => Array
|
16
10
|
|
11
|
+
field :entity_name, :type => String # , index: true
|
12
|
+
field :domains, :type => Array
|
17
13
|
end
|
18
14
|
end
|
data/lib/whoisxmlapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whoisxmlapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Hillard
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2020-09-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|