whoisxmlapi 0.2.2 → 0.3.0

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: ee3ef0dacc5ba9fc76df7676ead15f629cb34785ca90db96f8ca89f7ff15c6f9
4
- data.tar.gz: 7f7b7e5c16db21d3c0c27b09fa0d14a2cdc21d5de5eb564a790948e36c3b5be9
3
+ metadata.gz: fe3b9a00715ebd01c80e1378d9f64c57051f4af98848fe8fba3b548dac9716c4
4
+ data.tar.gz: 4cbb2e345411dd433820b4ec4c465635e4cbb6c13ac4ae687175ada3d776c64d
5
5
  SHA512:
6
- metadata.gz: 00656d04d2cdd7fd68a8076e10671e176d4ba2f76f557cce1db16c9227073c335a452c649939fae5131c5e711dec59895c64f7867292f9009d10b28acd0d2e72
7
- data.tar.gz: 0c64f4c1c9b9d9a3dbdf4a3f2e3e540f91d2a75e87e6d64d8682b6238cc39452610f26a01dbc3119e964ebfa8018f2c078f20ef8d561471d699d7ef04f9fa91a
6
+ metadata.gz: c6be612f3c774ad9d4a0511c49bc3a78cf53b3cc592fcd47c02a7c94423be084d3ce54728f5b96b9a568194c76a4ed6d912a6ab101b9576cdef937cc45c73f22
7
+ data.tar.gz: ebe16297aa08021577cecca96c15be662cb0da4995940ccf9bcb7041ca2047854d720281434bdfd88b0c02af496e61c22ff7527d891419d02b6ea333e20c1d92
@@ -7,74 +7,126 @@ 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}."
44
+ WhoisXMLAPI.logger.debug "WhoisXMLAPI#whois - WARNING: passed back parsed_response as a String instead of a Hash for \'#{domain}\'."
51
45
  presponse = JSON.parse(r.parsed_response)
52
46
  else
53
47
  presponse = r.parsed_response
54
48
  end
55
49
  if presponse.key? 'ErrorMessage'
56
50
  WhoisXMLAPI.logger.info "WhoisXMLAPI#whois - Error getting Whois info: #{presponse['ErrorMessage']['msg']}"
57
- res = WhoisXMLAPI::Unavailable.new
58
- res.parse(domain)
51
+ res = WhoisXMLAPI::Unavailable.new(:whoisable => owner)
52
+ res.parse(domain) # parse will save document for Unavailable
59
53
  elsif (200..299).include? r.code.to_i
60
- res = WhoisXMLAPI::Good.new
61
- res.parse(presponse['WhoisRecord'])
54
+ res = WhoisXMLAPI::Good.new(:whoisable => owner)
55
+ res.parse(presponse['WhoisRecord']) # parse will NOT save document for Good or UnParsable
62
56
  res.save
63
57
  end
64
58
  end
59
+ end
65
60
 
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
-
61
+ unless res
62
+ WhoisXMLAPI.logger.info "WhoisXMLAPI#whois - Unable to get Whois info for domain: \'#{domain}\'"
63
+ res = WhoisXMLAPI::Unavailable.new(:whoisable => owner)
64
+ res.parse(domain) # parse will save document for Unavailable
72
65
  end
66
+
73
67
  return res
74
68
  end
75
69
 
76
70
 
77
- def self.send_rwhois_request(entity_name)
71
+ # https://whoisapi.whoisxmlapi.com/docs
72
+ # GET https://www.whoisxmlapi.com/whoisserver/WhoisService?apiKey=YOUR_API_KEY&domainName=google.com
73
+ def whois(domain, owner=nil)
74
+ unless PublicSuffix.valid?(domain)
75
+ res = WhoisXMLAPI::BadDomain.new
76
+ res.parse(domain)
77
+ return res
78
+ end
79
+
80
+ query = WhoisXMLAPI::Result.where(:domain => domain)
81
+ query = query.where(:created_at.gte => (Time.now - WhoisXMLAPI.cache_length)) if WhoisXMLAPI.cache
82
+ res = query.first
83
+
84
+ if res.nil? || res._type == "WhoisXMLAPI::Unavailable"
85
+ WhoisXMLAPI.logger.debug "WhoisXMLAPI#whois - no cached Whois data for \'#{domain}\': initiating API access."
86
+ res = whois_cacheless(domain, owner)
87
+ else
88
+ WhoisXMLAPI.logger.debug "WhoisXMLAPI#whois - using cached Whois data for \'#{domain}\'"
89
+ end
90
+ res
91
+ end
92
+
93
+
94
+ def exists?(domain)
95
+ params = {
96
+ :cmd => 'GET_DN_AVAILABILITY',
97
+ :domainName => domain,
98
+ :outputFormat => 'JSON',
99
+ :apiKey => WhoisXMLAPI.api_key
100
+ }
101
+ begin
102
+ r = HTTParty.get(WhoisXMLAPI.whois_path, :query => params, :timeout => 120)
103
+ rescue StandardError => e
104
+ WhoisXMLAPI.logger.info "WhoisXMLAPI#whois - Error getting Whois info for \'#{domain}\': #{e}"
105
+ res = WhoisXMLAPI::Unavailable.new
106
+ res.parse(domain)
107
+ return res
108
+ end
109
+
110
+ # WhoisXML and HTTParty are sometimes returning a Hash and not a JSON string as requested,
111
+ # which is causing an error of "no implicit conversion of Hash into String" when we call JSON.parse.
112
+ # Logger message is to monitor whether WhoisXML and/or HTTParty will still return a string on occasion.
113
+ if r.parsed_response.is_a?(String)
114
+ WhoisXMLAPI.logger.debug "WhoisXMLAPI#exists? - passed back parsed_response as a String instead of a Hash for \'#{domain}\'."
115
+ resp = JSON.parse(r.parsed_response)
116
+ else
117
+ resp = r.parsed_response
118
+ end
119
+
120
+ resp["DomainInfo"]["domainAvailability"] == "UNAVAILABLE"
121
+ end
122
+
123
+
124
+ ####################################################################################################
125
+ # Reverse Whois
126
+ ####################################################################################################
127
+
128
+
129
+ def self.send_rwhois_request(entity_name, since_dt=nil)
78
130
  params = {
79
131
  :apiKey => WhoisXMLAPI.api_key,
80
132
  :searchType => "current",
@@ -82,13 +134,15 @@ module WhoisXMLAPI
82
134
  :responseFormat => 'json',
83
135
  :basicSearchTerms => {
84
136
  :include => [entity_name] # must be an array of strings!
85
- },
137
+ }
86
138
  }
139
+ params[:createdDateFrom] = since_dt.strftime("%F") if since_dt
140
+
87
141
  begin
88
142
  # To DEBUG add ":debug_output => $stdout"
89
143
  r = HTTParty.post(WhoisXMLAPI.rwhois_path, :body => params.to_json, :timeout => 120, :headers => {'Content-Type' => 'application/json'})
90
144
  rescue StandardError => e
91
- WhoisXMLAPI.logger.info "WhoisXMLAPI#rwhois - Error getting RWhois info for #{entity_name}: #{e}"
145
+ WhoisXMLAPI.logger.info "WhoisXMLAPI#rwhois - Error getting RWhois info for \'#{entity_name}\': #{e}"
92
146
  r = nil
93
147
  end
94
148
 
@@ -104,81 +158,76 @@ module WhoisXMLAPI
104
158
 
105
159
  # https://reverse-whois-api.whoisxmlapi.com/docs
106
160
  # POST https://reverse-whois-api.whoisxmlapi.com/api/v2
107
- def rwhois(entity_name)
161
+ def rwhois_cacheless(entity_name, since_dt=nil, owner=nil)
108
162
  # 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)
163
+ return nil unless entity_name.present?
164
+ res = WhoisXMLAPI::RWhoisResult.new(:entity_name => entity_name, :rwhoisable => owner, :domains => [])
165
+ r = WhoisXMLAPI::Client.send_rwhois_request(entity_name, since_dt)
166
+ if r && r.parsed_response && r.parsed_response['domainsList']
167
+ res.domains = r.parsed_response['domainsList']
168
+ elsif PublicSuffix.valid?(entity_name)
169
+ # if no luck with what was passed in and we have a valid domain with TLD, try just the second-level domain.
170
+ domain_sld = PublicSuffix.parse(entity_name).sld
171
+ WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois_cacheless - no domains found for domain \'#{entity_name}\', trying #{domain_sld}"
172
+ res.entity_name = domain_sld
173
+ r = WhoisXMLAPI::Client.send_rwhois_request(domain_sld)
121
174
  if r && r.parsed_response && r.parsed_response['domainsList']
122
175
  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
176
  end
177
+ else
178
+ WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois_cacheless - no domains found for \'#{entity_name}\'!"
179
+ end
180
+ unless res.save
181
+ WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois_cacheless - ERROR saving RWhoisResult: #{res.errors.full_messages.join('; ')} - #{res}!"
144
182
  end
145
183
  res
146
184
  end
147
185
 
148
186
 
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
187
+ # https://reverse-whois-api.whoisxmlapi.com/docs
188
+ # POST https://reverse-whois-api.whoisxmlapi.com/api/v2
189
+ def rwhois(entity_name, since_dt=nil, owner=nil)
190
+ # entity_name is really the domain being passed in for Rwhois not the actual entity name
191
+ return nil if entity_name.nil?
192
+ query = WhoisXMLAPI::RWhoisResult.where(:entity_name => entity_name, :rwhoisable => owner)
193
+ query = query.where(:created_at.gte => (Time.now - WhoisXMLAPI.cache_length)) if WhoisXMLAPI.cache
194
+ res = query.first
164
195
 
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)
196
+ if res.nil?
197
+ WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois - no cached RWhois data for \'#{entity_name}\': initiating API access."
198
+ res = rwhois_cacheless(entity_name, since_dt, owner)
171
199
  else
172
- resp = r.parsed_response
200
+ WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois - using cached RWhois data for \'#{entity_name}\'"
173
201
  end
174
-
175
- resp["DomainInfo"]["domainAvailability"] == "UNAVAILABLE"
202
+ res
176
203
  end
177
204
 
178
205
 
206
+ ####################################################################################################
207
+ # Account Balance
208
+ ####################################################################################################
209
+
210
+
179
211
  #
180
212
  # GET https://user.whoisxmlapi.com/service/account-balance?apiKey=YOUR_API_KEY
213
+ # wc.account_balance
214
+ # =>
215
+ # {
216
+ # "Email Verification API" => {:product_id => 7, :credits => 1000},
217
+ # "IP Geolocation API" => {:product_id => 8, :credits => 1000},
218
+ # "Domain Research Suite" => {:product_id => 14, :credits => 100},
219
+ # "WHOIS API" => {:product_id => 1, :credits => 1000},
220
+ # "Domain Reputation API" => {:product_id => 20, :credits => 100},
221
+ # "IP Netblocks API" => {:product_id => 23, :credits => 1000},
222
+ # "Domain Availability API" => {:product_id => 25, :credits => 100},
223
+ # "Screenshot API" => {:product_id => 27, :credits => 500},
224
+ # "Website Categorization API" => {:product_id => 21, :credits => 100},
225
+ # "Website Contacts API" => {:product_id => 29, :credits => 100},
226
+ # "DNS Lookup API" => {:product_id => 26, :credits => 500}
227
+ # }
228
+
181
229
  def account_balance
230
+ result = nil
182
231
  params = {
183
232
  :apiKey => WhoisXMLAPI.api_key
184
233
  }
@@ -190,15 +239,30 @@ module WhoisXMLAPI
190
239
  r = nil
191
240
  end
192
241
 
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
242
+ if r.response.is_a? Net::HTTPOK
243
+ if r && r.parsed_response
244
+ # WhoisXML and HTTParty are sometimes returning a Hash and not a JSON string as requested,
245
+ # which is causing an error of "no implicit conversion of Hash into String" when we call JSON.parse.
246
+ # Logger message is to monitor whether WhoisXML and/or HTTParty will still return a string on occasion.
247
+ if r.parsed_response.is_a?(String)
248
+ WhoisXMLAPI.logger.debug "WhoisXMLAPI#account_balance - passed back parsed_response as a String instead of a Hash."
249
+ JSON.parse(r.parsed_response)
250
+ end
200
251
 
201
- r ? r.parsed_response : nil
252
+ if r.parsed_response["error"]
253
+ result = {:error => {message: r.parsed_response["error"]}}
254
+ elsif r.parsed_response["data"]
255
+ result = {}
256
+ r.parsed_response["data"].each do |datum|
257
+ key = datum["product"]["name"]
258
+ result[key] = {product_id: datum["product_id"], credits: datum["credits"]}
259
+ end
260
+ end
261
+ end
262
+ else
263
+ result = {:error =>{code: r.response.code, message: r.response.message}}
264
+ end
265
+ result
202
266
  end
203
267
 
204
268
 
@@ -19,8 +19,28 @@ module WhoisXMLAPI
19
19
  field :state
20
20
  field :postalCode
21
21
  field :country
22
+ field :countryCode
22
23
  field :email
23
24
  field :telephone
24
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
+
25
45
  end
26
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.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -6,8 +6,8 @@ require 'whoisxmlapi/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "whoisxmlapi"
8
8
  spec.version = WhoisXMLAPI::VERSION
9
- spec.authors = ["Christopher Maujean", "David Hillard", "Matt Appel", "Chip Roberson", "Edgar Abadines"]
10
- spec.email = ["cmaujean@brandle.net", "dhillard@brandle.net", "mappel@brandle.net", "chip@brandle.net", "ed@brandle.net"]
9
+ spec.authors = ["David Hillard", "Matt Appel", "Chip Roberson", "Edgar Abadines"]
10
+ spec.email = ["dhillard@brandle.net", "mappel@brandle.net", "chip@brandle.net", "ed@brandle.net"]
11
11
  spec.description = %q{Gem for accessing the Whois XML API via JSON, with caching}
12
12
  spec.summary = %q{whoisxmlapi.com access}
13
13
  spec.homepage = "http://brandle.net/"
metadata CHANGED
@@ -1,10 +1,9 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whoisxmlapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Christopher Maujean
8
7
  - David Hillard
9
8
  - Matt Appel
10
9
  - Chip Roberson
@@ -12,7 +11,7 @@ authors:
12
11
  autorequire:
13
12
  bindir: bin
14
13
  cert_chain: []
15
- date: 2019-07-03 00:00:00.000000000 Z
14
+ date: 2020-08-19 00:00:00.000000000 Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: activesupport
@@ -100,7 +99,6 @@ dependencies:
100
99
  version: '0'
101
100
  description: Gem for accessing the Whois XML API via JSON, with caching
102
101
  email:
103
- - cmaujean@brandle.net
104
102
  - dhillard@brandle.net
105
103
  - mappel@brandle.net
106
104
  - chip@brandle.net
@@ -145,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
143
  - !ruby/object:Gem::Version
146
144
  version: '0'
147
145
  requirements: []
148
- rubygems_version: 3.0.4
146
+ rubygems_version: 3.0.6
149
147
  signing_key:
150
148
  specification_version: 4
151
149
  summary: whoisxmlapi.com access