whoisxmlapi 0.3.0 → 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: fe3b9a00715ebd01c80e1378d9f64c57051f4af98848fe8fba3b548dac9716c4
4
- data.tar.gz: 4cbb2e345411dd433820b4ec4c465635e4cbb6c13ac4ae687175ada3d776c64d
3
+ metadata.gz: 2442b889d8fed140f51f7d83bf621f30403d81bace0d7fa3f16db5fba1c61ba5
4
+ data.tar.gz: 248927a9e820129a2cb6bfe0ba3656de0e361d9624ca375f0896fd55f1a774f4
5
5
  SHA512:
6
- metadata.gz: c6be612f3c774ad9d4a0511c49bc3a78cf53b3cc592fcd47c02a7c94423be084d3ce54728f5b96b9a568194c76a4ed6d912a6ab101b9576cdef937cc45c73f22
7
- data.tar.gz: ebe16297aa08021577cecca96c15be662cb0da4995940ccf9bcb7041ca2047854d720281434bdfd88b0c02af496e61c22ff7527d891419d02b6ea333e20c1d92
6
+ metadata.gz: ba31775e1e05d8b9c482ab67b52858d401defa81b746a8e5a7913a6da3536f38c2786337c9d0c47cb402779d90408445cf98ac3ebc2b9fd526dacea03efad509
7
+ data.tar.gz: 1e9d36cf33a50560a604ffdf5085228dbb7ff51f53b4721568a5da72095b1f507e05e97de5babd48149795bdfab5b6baedae7f822c5c0afc703711106612bcc2
@@ -42,11 +42,14 @@ module WhoisXMLAPI
42
42
  if r
43
43
  if r.parsed_response.is_a?(String)
44
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)
45
+ presponse = JSON.parse(r.parsed_response) rescue nil
46
46
  else
47
47
  presponse = r.parsed_response
48
48
  end
49
- if presponse.key? 'ErrorMessage'
49
+
50
+ if presponse.nil?
51
+ res = {:error => {message: 'Failed to parse response from API.'}}
52
+ elsif presponse.key? 'ErrorMessage'
50
53
  WhoisXMLAPI.logger.info "WhoisXMLAPI#whois - Error getting Whois info: #{presponse['ErrorMessage']['msg']}"
51
54
  res = WhoisXMLAPI::Unavailable.new(:whoisable => owner)
52
55
  res.parse(domain) # parse will save document for Unavailable
@@ -112,12 +115,12 @@ module WhoisXMLAPI
112
115
  # Logger message is to monitor whether WhoisXML and/or HTTParty will still return a string on occasion.
113
116
  if r.parsed_response.is_a?(String)
114
117
  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)
118
+ presponse = JSON.parse(r.parsed_response) rescue nil
116
119
  else
117
- resp = r.parsed_response
120
+ presponse = r.parsed_response
118
121
  end
119
122
 
120
- resp["DomainInfo"]["domainAvailability"] == "UNAVAILABLE"
123
+ presponse && presponse["DomainInfo"]["domainAvailability"] == "UNAVAILABLE"
121
124
  end
122
125
 
123
126
 
@@ -239,21 +242,25 @@ module WhoisXMLAPI
239
242
  r = nil
240
243
  end
241
244
 
242
- if r.response.is_a? Net::HTTPOK
243
- if r && r.parsed_response
245
+ if r && r.response.is_a?(Net::HTTPOK)
246
+ if r.parsed_response
244
247
  # WhoisXML and HTTParty are sometimes returning a Hash and not a JSON string as requested,
245
248
  # which is causing an error of "no implicit conversion of Hash into String" when we call JSON.parse.
246
249
  # Logger message is to monitor whether WhoisXML and/or HTTParty will still return a string on occasion.
247
250
  if r.parsed_response.is_a?(String)
248
251
  WhoisXMLAPI.logger.debug "WhoisXMLAPI#account_balance - passed back parsed_response as a String instead of a Hash."
249
- JSON.parse(r.parsed_response)
252
+ presponse = JSON.parse(r.parsed_response) rescue nil
253
+ else
254
+ presponse = r.parsed_response
250
255
  end
251
256
 
252
- if r.parsed_response["error"]
253
- result = {:error => {message: r.parsed_response["error"]}}
254
- elsif r.parsed_response["data"]
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"]
255
262
  result = {}
256
- r.parsed_response["data"].each do |datum|
263
+ presponse["data"].each do |datum|
257
264
  key = datum["product"]["name"]
258
265
  result[key] = {product_id: datum["product_id"], credits: datum["credits"]}
259
266
  end
@@ -1,3 +1,3 @@
1
1
  module WhoisXMLAPI
2
- VERSION = "0.3.0"
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.3.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: 2020-08-19 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