whoisxmlapi 0.0.21 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/whoisxmlapi.rb +26 -15
- data/lib/whoisxmlapi/client.rb +101 -105
- data/lib/whoisxmlapi/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 19ef89481b853c23afd17b496d79abf4075a6ff4757ceafb33b67ee902b1ea6a
|
4
|
+
data.tar.gz: 35c3eeb9ac3ae90c776135f863a96812b2ec8ff65a0bff66b331a1bb1c5bf324
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6be70457f7c5291f1b23cbaf2210fd559df5bbdf7a1616ed9e92655859d11fb1ad20e2914c9efdd5c908769a9175fcb71244e4357ac772b543d3ec6a491bb0b
|
7
|
+
data.tar.gz: 79c9a1d03097cd8cb69ecf29714e189053a36420ae2177f3578d057eaab8407b4dddb20d23a3c2994b55c1d75537e4fd6c96ec088a4a5087c7079a0d121754b7
|
data/lib/whoisxmlapi.rb
CHANGED
@@ -9,38 +9,43 @@ require_relative "./whoisxmlapi/client"
|
|
9
9
|
require_relative "./whoisxmlapi/rwhois_result"
|
10
10
|
|
11
11
|
module WhoisXMLAPI
|
12
|
-
|
13
|
-
|
12
|
+
|
13
|
+
def self.whois_path=(path)
|
14
|
+
@whois_path = path
|
14
15
|
end
|
15
16
|
|
16
|
-
def self.
|
17
|
-
@
|
17
|
+
def self.whois_path
|
18
|
+
@whois_path ? @whois_path : "https://www.whoisxmlapi.com/whoisserver/WhoisService"
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
|
22
|
+
def self.rwhois_path=(path)
|
23
|
+
@rwhois_path = path
|
22
24
|
end
|
23
25
|
|
24
|
-
def self.
|
25
|
-
@
|
26
|
+
def self.rwhois_path
|
27
|
+
@rwhois_path ? @rwhois_path : "https://reverse-whois-api.whoisxmlapi.com/api/v2"
|
26
28
|
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
+
|
31
|
+
def self.account_path=(path)
|
32
|
+
@account_path = path
|
30
33
|
end
|
31
34
|
|
32
|
-
def self.
|
33
|
-
@
|
35
|
+
def self.account_path
|
36
|
+
@account_path ? @account_path : "https://user.whoisxmlapi.com/service/account-balance"
|
34
37
|
end
|
35
|
-
|
38
|
+
|
39
|
+
|
36
40
|
def self.api_key
|
37
41
|
@api_key
|
38
42
|
end
|
39
|
-
|
43
|
+
|
40
44
|
def self.api_key=(key)
|
41
45
|
@api_key = key
|
42
46
|
end
|
43
47
|
|
48
|
+
|
44
49
|
def self.cache_length=(leng)
|
45
50
|
@cache_length = leng
|
46
51
|
end
|
@@ -49,6 +54,7 @@ module WhoisXMLAPI
|
|
49
54
|
@cache_length
|
50
55
|
end
|
51
56
|
|
57
|
+
|
52
58
|
def self.cache=(bool)
|
53
59
|
@cache = bool
|
54
60
|
end
|
@@ -57,6 +63,7 @@ module WhoisXMLAPI
|
|
57
63
|
@cache.nil? or @cache.blank? ? true : @cache
|
58
64
|
end
|
59
65
|
|
66
|
+
|
60
67
|
def self.rwhois_mode=(mode)
|
61
68
|
@rwhois_mode = mode
|
62
69
|
end
|
@@ -65,6 +72,7 @@ module WhoisXMLAPI
|
|
65
72
|
@rwhois_mode ? @rwhois_mode : 'sample_purchase'
|
66
73
|
end
|
67
74
|
|
75
|
+
|
68
76
|
def self.callbacks
|
69
77
|
@callbacks ||= {}
|
70
78
|
@callbacks[:whois] ||= []
|
@@ -72,6 +80,7 @@ module WhoisXMLAPI
|
|
72
80
|
@callbacks
|
73
81
|
end
|
74
82
|
|
83
|
+
|
75
84
|
def self.logger
|
76
85
|
@logger ||= Logger.new(STDOUT)
|
77
86
|
@logger
|
@@ -81,7 +90,9 @@ module WhoisXMLAPI
|
|
81
90
|
@logger = log
|
82
91
|
end
|
83
92
|
|
93
|
+
|
84
94
|
def self.configure
|
85
|
-
|
95
|
+
yield self
|
86
96
|
end
|
97
|
+
|
87
98
|
end
|
data/lib/whoisxmlapi/client.rb
CHANGED
@@ -7,6 +7,8 @@ module WhoisXMLAPI
|
|
7
7
|
|
8
8
|
class Client
|
9
9
|
|
10
|
+
# https://whoisapi.whoisxmlapi.com/docs
|
11
|
+
# GET https://www.whoisxmlapi.com/whoisserver/WhoisService?apiKey=YOUR_API_KEY&domainName=google.com
|
10
12
|
def whois(domain)
|
11
13
|
unless PublicSuffix.valid?(domain)
|
12
14
|
res = WhoisXMLAPI::BadDomain.new
|
@@ -15,33 +17,25 @@ module WhoisXMLAPI
|
|
15
17
|
end
|
16
18
|
|
17
19
|
query = WhoisXMLAPI::Result.where(:domain => domain)
|
18
|
-
|
19
|
-
if WhoisXMLAPI.cache
|
20
|
-
query = query.where(:created_at.gte => (Time.now - WhoisXMLAPI.cache_length))
|
21
|
-
end
|
22
|
-
|
20
|
+
query = query.where(:created_at.gte => (Time.now - WhoisXMLAPI.cache_length)) if WhoisXMLAPI.cache
|
23
21
|
res = query.first
|
24
22
|
|
25
|
-
if res
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
:domainName => domain,
|
31
|
-
:outputFormat => 'JSON'
|
23
|
+
if res.nil? || res._type == "WhoisXMLAPI::Unavailable"
|
24
|
+
params = {
|
25
|
+
:apiKey => WhoisXMLAPI.api_key,
|
26
|
+
:domainName => domain,
|
27
|
+
:outputFormat => 'JSON'
|
32
28
|
}
|
33
29
|
|
34
30
|
begin
|
35
|
-
r = HTTParty.get(
|
36
|
-
rescue
|
37
|
-
WhoisXMLAPI.logger.info
|
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}"
|
38
34
|
res = WhoisXMLAPI::Unavailable.new
|
39
35
|
res.parse(domain)
|
40
36
|
return res
|
41
37
|
end
|
42
38
|
|
43
|
-
res = WhoisXMLAPI::Good.new
|
44
|
-
|
45
39
|
if WhoisXMLAPI.callbacks[:whois]
|
46
40
|
WhoisXMLAPI.callbacks[:whois].each do |cb|
|
47
41
|
cb.call
|
@@ -51,94 +45,99 @@ module WhoisXMLAPI
|
|
51
45
|
# WhoisXML and HTTParty are sometimes returning a Hash and not a JSON string as requested,
|
52
46
|
# which is causing an error of "no implicit conversion of Hash into String" when we call JSON.parse.
|
53
47
|
# Logger message is to monitor whether WhoisXML and/or HTTParty will still return a string on occasion.
|
54
|
-
if r
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
48
|
+
if r
|
49
|
+
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)
|
52
|
+
else
|
53
|
+
presponse = r.parsed_response
|
54
|
+
end
|
55
|
+
if presponse.key? 'ErrorMessage'
|
56
|
+
WhoisXMLAPI.logger.info "WhoisXMLAPI#whois - Error getting Whois info: #{presponse['ErrorMessage']['msg']}"
|
57
|
+
res = WhoisXMLAPI::Unavailable.new
|
58
|
+
res.parse(domain)
|
59
|
+
elsif (200..299).include? r.code.to_i
|
60
|
+
res = WhoisXMLAPI::Good.new
|
61
|
+
res.parse(presponse['WhoisRecord'])
|
62
|
+
res.save
|
63
|
+
end
|
59
64
|
end
|
60
65
|
|
61
|
-
|
62
|
-
|
63
|
-
res.save
|
64
|
-
return res
|
65
|
-
else
|
66
|
-
WhoisXMLAPI.logger.info("Error getting Whois info: #{e}")
|
66
|
+
unless res
|
67
|
+
WhoisXMLAPI.logger.info "WhoisXMLAPI#whois - Unable to get Whois info for : #{domain}"
|
67
68
|
res = WhoisXMLAPI::Unavailable.new
|
68
69
|
res.parse(domain)
|
69
|
-
return res
|
70
70
|
end
|
71
|
+
|
71
72
|
end
|
73
|
+
return res
|
72
74
|
end
|
73
75
|
|
74
76
|
|
77
|
+
def self.send_rwhois_request(entity_name)
|
78
|
+
params = {
|
79
|
+
:apiKey => WhoisXMLAPI.api_key,
|
80
|
+
:searchType => "current",
|
81
|
+
:mode => WhoisXMLAPI.rwhois_mode,
|
82
|
+
:responseFormat => 'json',
|
83
|
+
:basicSearchTerms => {
|
84
|
+
:include => [entity_name] # must be an array of strings!
|
85
|
+
},
|
86
|
+
}
|
87
|
+
begin
|
88
|
+
# To DEBUG add ":debug_output => $stdout"
|
89
|
+
r = HTTParty.post(WhoisXMLAPI.rwhois_path, :body => params.to_json, :timeout => 120, :headers => {'Content-Type' => 'application/json'})
|
90
|
+
rescue StandardError => e
|
91
|
+
WhoisXMLAPI.logger.info "WhoisXMLAPI#rwhois - Error getting RWhois info for #{entity_name}: #{e}"
|
92
|
+
r = nil
|
93
|
+
end
|
94
|
+
|
95
|
+
if WhoisXMLAPI.callbacks[:rwhois]
|
96
|
+
WhoisXMLAPI.callbacks[:rwhois].each do |cb|
|
97
|
+
cb.call
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
return r
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
# https://reverse-whois-api.whoisxmlapi.com/docs
|
106
|
+
# POST https://reverse-whois-api.whoisxmlapi.com/api/v2
|
75
107
|
def rwhois(entity_name)
|
76
108
|
# entity_name is really the domain being passed in for Rwhois not the actual entity name
|
77
109
|
return nil if entity_name.nil?
|
78
110
|
query = WhoisXMLAPI::RWhoisResult.where(:entity_name => entity_name)
|
79
|
-
if WhoisXMLAPI.cache
|
80
|
-
query = query.where(:created_at.gte => (Time.now - WhoisXMLAPI.cache_length))
|
81
|
-
end
|
111
|
+
query = query.where(:created_at.gte => (Time.now - WhoisXMLAPI.cache_length)) if WhoisXMLAPI.cache
|
82
112
|
res = query.first
|
83
113
|
|
84
114
|
if res
|
85
|
-
WhoisXMLAPI.logger.debug "WhoisXMLAPI
|
115
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois - using cached rwhois data for #{entity_name}"
|
86
116
|
else
|
87
|
-
WhoisXMLAPI.logger.debug "WhoisXMLAPI
|
117
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois - no cached rwhois data for #{entity_name}"
|
88
118
|
res = WhoisXMLAPI::RWhoisResult.create(:entity_name => entity_name)
|
89
119
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
:search_type => "current"
|
94
|
-
},
|
95
|
-
:mode => WhoisXMLAPI.rwhois_mode,
|
96
|
-
:apiKey => WhoisXMLAPI.api_key,
|
97
|
-
}
|
98
|
-
|
99
|
-
r = WhoisXMLAPI::Client.create_and_send_rwhois_request(params_basic)
|
100
|
-
|
101
|
-
if WhoisXMLAPI.callbacks[:rwhois]
|
102
|
-
WhoisXMLAPI.callbacks[:rwhois].each do |cb|
|
103
|
-
cb.call
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
if r && r.parsed_response && r.parsed_response['domains']
|
108
|
-
res.domains = r.parsed_response['domains']
|
120
|
+
r = WhoisXMLAPI::Client.send_rwhois_request(entity_name)
|
121
|
+
if r && r.parsed_response && r.parsed_response['domainsList']
|
122
|
+
res.domains = r.parsed_response['domainsList']
|
109
123
|
res.save
|
110
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.
|
111
126
|
domain = PublicSuffix.parse(entity_name)
|
112
127
|
domain_sld = domain.sld
|
113
|
-
|
128
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois - no domains found for domain #{entity_name}, trying #{domain_sld}"
|
114
129
|
res = WhoisXMLAPI::RWhoisResult.create(:entity_name => domain_sld)
|
115
130
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
:search_type => "current"
|
120
|
-
},
|
121
|
-
:mode => WhoisXMLAPI.rwhois_mode,
|
122
|
-
:apiKey => WhoisXMLAPI.api_key,
|
123
|
-
}
|
124
|
-
|
125
|
-
r = WhoisXMLAPI::Client.create_and_send_rwhois_request(params_basic)
|
126
|
-
|
127
|
-
if WhoisXMLAPI.callbacks[:rwhois]
|
128
|
-
WhoisXMLAPI.callbacks[:rwhois].each do |cb|
|
129
|
-
cb.call
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
if r && r.parsed_response && r.parsed_response['domains']
|
134
|
-
res.domains = r.parsed_response['domains']
|
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']
|
135
134
|
res.save
|
136
135
|
else
|
137
136
|
res.domains = []
|
138
137
|
res.save
|
139
138
|
end
|
140
139
|
else
|
141
|
-
WhoisXMLAPI.logger.debug "WhoisXMLAPI
|
140
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#rwhois - no domains found for #{entity_name}!"
|
142
141
|
res.domains = []
|
143
142
|
res.save
|
144
143
|
end
|
@@ -148,19 +147,26 @@ module WhoisXMLAPI
|
|
148
147
|
|
149
148
|
|
150
149
|
def exists?(domain)
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
150
|
+
params = {
|
151
|
+
:cmd => 'GET_DN_AVAILABILITY',
|
152
|
+
:domainName => domain,
|
153
|
+
:outputFormat => 'JSON',
|
154
|
+
:apiKey => WhoisXMLAPI.api_key
|
156
155
|
}
|
157
|
-
|
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
|
158
164
|
|
159
165
|
# WhoisXML and HTTParty are sometimes returning a Hash and not a JSON string as requested,
|
160
166
|
# which is causing an error of "no implicit conversion of Hash into String" when we call JSON.parse.
|
161
167
|
# Logger message is to monitor whether WhoisXML and/or HTTParty will still return a string on occasion.
|
162
168
|
if r.parsed_response.is_a?(String)
|
163
|
-
|
169
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#exists? - passed back parsed_response as a String instead of a Hash for #{domain}."
|
164
170
|
resp = JSON.parse(r.parsed_response)
|
165
171
|
else
|
166
172
|
resp = r.parsed_response
|
@@ -170,39 +176,29 @@ module WhoisXMLAPI
|
|
170
176
|
end
|
171
177
|
|
172
178
|
|
179
|
+
#
|
180
|
+
# GET https://user.whoisxmlapi.com/service/account-balance?apiKey=YOUR_API_KEY
|
173
181
|
def account_balance
|
174
|
-
|
175
|
-
|
176
|
-
:output_format => 'JSON',
|
177
|
-
:apiKey => WhoisXMLAPI.api_key
|
182
|
+
params = {
|
183
|
+
:apiKey => WhoisXMLAPI.api_key
|
178
184
|
}
|
179
|
-
|
185
|
+
|
186
|
+
begin
|
187
|
+
r = HTTParty.get(WhoisXMLAPI.account_path, :query => params, :timeout => 120)
|
188
|
+
rescue StandardError => e
|
189
|
+
WhoisXMLAPI.logger.info "WhoisXMLAPI#account_balance - Error getting account_balance: #{e}"
|
190
|
+
r = nil
|
191
|
+
end
|
180
192
|
|
181
193
|
# WhoisXML and HTTParty are sometimes returning a Hash and not a JSON string as requested,
|
182
194
|
# which is causing an error of "no implicit conversion of Hash into String" when we call JSON.parse.
|
183
195
|
# Logger message is to monitor whether WhoisXML and/or HTTParty will still return a string on occasion.
|
184
196
|
if r.parsed_response.is_a?(String)
|
185
|
-
|
197
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI#account_balance - passed back parsed_response as a String instead of a Hash."
|
186
198
|
JSON.parse(r.parsed_response)
|
187
|
-
else
|
188
|
-
r.parsed_response
|
189
199
|
end
|
190
200
|
|
191
|
-
|
192
|
-
|
193
|
-
def self.create_and_send_rwhois_request(params_basic)
|
194
|
-
uri = URI.parse('https://reverse-whois-api.whoisxmlapi.com/api/v2')
|
195
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
196
|
-
http.use_ssl = true
|
197
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
198
|
-
request = Net::HTTP::Post.new(uri.request_uri)
|
199
|
-
request.add_field('Content-Type', 'application/json')
|
200
|
-
request.add_field('Accept', 'application/json')
|
201
|
-
request.body = params_basic.to_json
|
202
|
-
r = http.request(request)
|
203
|
-
# used for debugging
|
204
|
-
# puts JSON.parse(r.body).to_yaml
|
205
|
-
return r
|
201
|
+
r ? r.parsed_response : nil
|
206
202
|
end
|
207
203
|
|
208
204
|
|
@@ -212,5 +208,5 @@ module WhoisXMLAPI
|
|
212
208
|
|
213
209
|
|
214
210
|
end # of class Client
|
215
|
-
|
211
|
+
|
216
212
|
end # of module WhoisXMLAPI
|
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Maujean
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2019-03-
|
14
|
+
date: 2019-03-17 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
146
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.
|
147
|
+
rubygems_version: 2.7.7
|
148
148
|
signing_key:
|
149
149
|
specification_version: 4
|
150
150
|
summary: whoisxmlapi.com access
|