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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7217317d0caf1be648ce6b96cef1c0b3c977bb90c65fa5d1e69cb6b181b36967
4
- data.tar.gz: 8c77cd66f5a26dbf8e7e99b86e64a42c332fb234d69d2b35c89784e667930775
3
+ metadata.gz: 2442b889d8fed140f51f7d83bf621f30403d81bace0d7fa3f16db5fba1c61ba5
4
+ data.tar.gz: 248927a9e820129a2cb6bfe0ba3656de0e361d9624ca375f0896fd55f1a774f4
5
5
  SHA512:
6
- metadata.gz: dd9344a0e3a271d1641f9e91a12c5cbe3f04dc12a5acad25a6db009313932cafd9aaa8fe455702d666335452211dae33c4a8e38715a9dd8343ba47acfed3fefc
7
- data.tar.gz: 76e08efaf6aa25e334a9ee90dc20b10e3b500ab2ec571dc2a82aef2bcea2a36ae43d33ba2326e947ef6e16344db03e18b9ed1bca3d380cd9b3ee3ad91fd83208
6
+ metadata.gz: ba31775e1e05d8b9c482ab67b52858d401defa81b746a8e5a7913a6da3536f38c2786337c9d0c47cb402779d90408445cf98ac3ebc2b9fd526dacea03efad509
7
+ data.tar.gz: 1e9d36cf33a50560a604ffdf5085228dbb7ff51f53b4721568a5da72095b1f507e05e97de5babd48149795bdfab5b6baedae7f822c5c0afc703711106612bcc2
@@ -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 whois(domain)
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
- query = WhoisXMLAPI::Result.where(:domain => domain)
20
- query = query.where(:created_at.gte => (Time.now - WhoisXMLAPI.cache_length)) if WhoisXMLAPI.cache
21
- res = query.first
22
-
23
- if res.nil? || res._type == "WhoisXMLAPI::Unavailable"
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 do |cb|
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
- if presponse.key? 'ErrorMessage'
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
- unless res
67
- WhoisXMLAPI.logger.info "WhoisXMLAPI#whois - Unable to get Whois info for : #{domain}"
68
- res = WhoisXMLAPI::Unavailable.new
69
- res.parse(domain)
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
- def self.send_rwhois_request(entity_name)
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 rwhois(entity_name)
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 if entity_name.nil?
110
- query = WhoisXMLAPI::RWhoisResult.where(:entity_name => entity_name)
111
- query = query.where(:created_at.gte => (Time.now - WhoisXMLAPI.cache_length)) if WhoisXMLAPI.cache
112
- res = query.first
113
-
114
- if res
115
- WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois - using cached rwhois data for #{entity_name}"
116
- else
117
- WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois - no cached rwhois data for #{entity_name}"
118
- res = WhoisXMLAPI::RWhoisResult.create(:entity_name => entity_name)
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
- def exists?(domain)
150
- params = {
151
- :cmd => 'GET_DN_AVAILABILITY',
152
- :domainName => domain,
153
- :outputFormat => 'JSON',
154
- :apiKey => WhoisXMLAPI.api_key
155
- }
156
- begin
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
- # WhoisXML and HTTParty are sometimes returning a Hash and not a JSON string as requested,
166
- # which is causing an error of "no implicit conversion of Hash into String" when we call JSON.parse.
167
- # Logger message is to monitor whether WhoisXML and/or HTTParty will still return a string on occasion.
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
- resp = r.parsed_response
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
- # WhoisXML and HTTParty are sometimes returning a Hash and not a JSON string as requested,
194
- # which is causing an error of "no implicit conversion of Hash into String" when we call JSON.parse.
195
- # Logger message is to monitor whether WhoisXML and/or HTTParty will still return a string on occasion.
196
- if r.parsed_response.is_a?(String)
197
- WhoisXMLAPI.logger.debug "WhoisXMLAPI#account_balance - passed back parsed_response as a String instead of a Hash."
198
- JSON.parse(r.parsed_response)
199
- end
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
- r ? r.parsed_response : nil
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
 
@@ -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
@@ -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, :as => :contactable, :class_name => "WhoisXMLAPI::Contact", :autosave => true
19
- has_one :tech, :as => :contactable, :class_name => "WhoisXMLAPI::Contact", :autosave => true
20
- has_one :billing, :as => :contactable, :class_name => "WhoisXMLAPI::Contact", :autosave => true
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.create(registrant_data.merge({'email' => record['contactEmail']})) if registrant_data
61
- self.admin = WhoisXMLAPI::Contact.create(administrative_data) if administrative_data
62
- self.tech = WhoisXMLAPI::Contact.create(technical_data) if technical_data
63
- self.billing = WhoisXMLAPI::Contact.create(billing_data) if billing_data
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
- belongs_to :rwhoisable, :polymorphic => true
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
@@ -1,3 +1,3 @@
1
1
  module WhoisXMLAPI
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.1"
3
3
  end
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.2.3
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: 2019-10-28 00:00:00.000000000 Z
14
+ date: 2020-09-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport