whoisxmlapi 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/whoisxmlapi.rb +8 -0
- data/lib/whoisxmlapi/client.rb +95 -32
- data/lib/whoisxmlapi/version.rb +1 -1
- data/whoisxmlapi.gemspec +2 -2
- metadata +23 -18
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NmQxYWY5OTg0NzFjMDcwNmY2NGJhYWJlOWNhZDFiNzU2MTBlNzQ5Nw==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2ee7bacb19ead9fff1009409330c4b224e496f0c40311d2a00b4fed487b9fe51
|
4
|
+
data.tar.gz: 0b5df1d17fb4995116bd156fc6c06687515dc902034e8d41e002cdd6c66cd016
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NjJjNWEyM2JlZThiMjEyNTkxYzQyNzJlYzVkYmJjNmE2MTBlYzQxM2JlNGM0
|
11
|
-
Zjg5YWI3ZmY0M2U3NDY3NDAyYmYwOTVmZTIwOGVlZjAxOWRhYmI=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
OWJmN2FiYzVlNWM0ODI2ODlmMWYwNzJlMGM2NGJhZTNjZjQ0YTk1NTRiMzFk
|
14
|
-
NGM0ZDNiZjMyYTE2N2UwMzMxNTk0MDI0M2JjNGQ5ZDIxNzkyMzM4YmJjYjQx
|
15
|
-
MmEyNGJkMDMyNTU2NjhmMGRiNmMyZjNjMTE1MjEzNDA2ZTJhMmE=
|
6
|
+
metadata.gz: 7bf58edcfa9453db455c1ad5ff1a5a82efddf33bd195bbdd5421f65503944198222f6289590e655a17db98e0dbfabff72581738f7e65c51ec23d9238d2c7088f
|
7
|
+
data.tar.gz: fbcf7db8ecee37bce1f36a9f2ae0f4c1293f6bf5b97dd86cf0ecbf748f83f2aff9909bc15aef8f7f06df7fdf0d8368f73568e0b24d12f69b1299ab891fd049fb
|
data/lib/whoisxmlapi.rb
CHANGED
data/lib/whoisxmlapi/client.rb
CHANGED
@@ -4,7 +4,9 @@ require 'json'
|
|
4
4
|
require 'public_suffix'
|
5
5
|
|
6
6
|
module WhoisXMLAPI
|
7
|
+
|
7
8
|
class Client
|
9
|
+
|
8
10
|
def whois(domain)
|
9
11
|
unless PublicSuffix.valid?(domain)
|
10
12
|
res = WhoisXMLAPI::BadDomain.new
|
@@ -24,15 +26,15 @@ module WhoisXMLAPI
|
|
24
26
|
return res
|
25
27
|
else
|
26
28
|
xquery = {
|
29
|
+
:apiKey => WhoisXMLAPI.api_key,
|
27
30
|
:domainName => domain,
|
28
|
-
:outputFormat => '
|
29
|
-
:userName => WhoisXMLAPI.username,
|
30
|
-
:password => WhoisXMLAPI.password
|
31
|
+
:outputFormat => 'JSON'
|
31
32
|
}
|
33
|
+
|
32
34
|
begin
|
33
35
|
r = HTTParty.get("#{WhoisXMLAPI.domain}/whoisserver/WhoisService", :query => xquery, :timeout => 120)
|
34
36
|
rescue Exception => e
|
35
|
-
WhoisXMLAPI.logger.info("Error getting Whois info: #{e}")
|
37
|
+
WhoisXMLAPI.logger.info("Error getting Whois info for #{domain}: #{e}")
|
36
38
|
res = WhoisXMLAPI::Unavailable.new
|
37
39
|
res.parse(domain)
|
38
40
|
return res
|
@@ -46,8 +48,15 @@ module WhoisXMLAPI
|
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
49
|
-
#
|
50
|
-
|
51
|
+
# WhoisXML and HTTParty are sometimes returning a Hash and not a JSON string as requested,
|
52
|
+
# which is causing an error of "no implicit conversion of Hash into String" when we call JSON.parse.
|
53
|
+
# Logger message is to monitor whether WhoisXML and/or HTTParty will still return a string on occasion.
|
54
|
+
if r.parsed_response.is_a?(String)
|
55
|
+
WhoisXMLAPI.logger.debug "WhoisXML Whois method passed back parsed_response as a String instead of a Hash for #{domain}."
|
56
|
+
presponse = JSON.parse(r.parsed_response)
|
57
|
+
else
|
58
|
+
presponse = r.parsed_response
|
59
|
+
end
|
51
60
|
|
52
61
|
if (200..299).include? r.code.to_i and not presponse.key? 'ErrorMessage'
|
53
62
|
res.parse(presponse['WhoisRecord'])
|
@@ -62,7 +71,9 @@ module WhoisXMLAPI
|
|
62
71
|
end
|
63
72
|
end
|
64
73
|
|
74
|
+
|
65
75
|
def rwhois(entity_name)
|
76
|
+
# entity_name is really the domain being passed in for Rwhois not the actual entity name
|
66
77
|
return nil if entity_name.nil?
|
67
78
|
query = WhoisXMLAPI::RWhoisResult.where(:entity_name => entity_name)
|
68
79
|
if WhoisXMLAPI.cache
|
@@ -71,23 +82,28 @@ module WhoisXMLAPI
|
|
71
82
|
res = query.first
|
72
83
|
|
73
84
|
if res
|
74
|
-
|
85
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI rwhois - using cached rwhois data for #{entity_name}"
|
75
86
|
else
|
76
|
-
|
87
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI rwhois - no cached rwhois data for #{entity_name}"
|
77
88
|
res = WhoisXMLAPI::RWhoisResult.create(:entity_name => entity_name)
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
:
|
82
|
-
:
|
83
|
-
|
89
|
+
|
90
|
+
params_basic = {
|
91
|
+
basicSearchTerms: {
|
92
|
+
:include => [entity_name], # must be an array of strings!
|
93
|
+
:search_type => "current"
|
94
|
+
},
|
95
|
+
:mode => WhoisXMLAPI.rwhois_mode,
|
96
|
+
:apiKey => WhoisXMLAPI.api_key,
|
84
97
|
}
|
85
|
-
|
98
|
+
|
99
|
+
r = create_and_send_rwhois_request(params_basic)
|
100
|
+
|
86
101
|
if WhoisXMLAPI.callbacks[:rwhois]
|
87
102
|
WhoisXMLAPI.callbacks[:rwhois].each do |cb|
|
88
103
|
cb.call
|
89
104
|
end
|
90
105
|
end
|
106
|
+
|
91
107
|
if r && r.parsed_response && r.parsed_response['domains']
|
92
108
|
res.domains = r.parsed_response['domains']
|
93
109
|
res.save
|
@@ -96,19 +112,24 @@ module WhoisXMLAPI
|
|
96
112
|
domain_sld = domain.sld
|
97
113
|
Rails.logger.debug "WhoisXMLAPI rwhois - no domains found for domain #{entity_name}, trying #{domain_sld}"
|
98
114
|
res = WhoisXMLAPI::RWhoisResult.create(:entity_name => domain_sld)
|
99
|
-
|
100
|
-
|
101
|
-
|
115
|
+
|
116
|
+
params_basic = {
|
117
|
+
basicSearchTerms: {
|
118
|
+
:include => [domain_sld], #must be an array of strings!
|
119
|
+
:search_type => "current"
|
120
|
+
},
|
102
121
|
:mode => WhoisXMLAPI.rwhois_mode,
|
103
|
-
:
|
104
|
-
:password => WhoisXMLAPI.password
|
122
|
+
:apiKey => WhoisXMLAPI.api_key,
|
105
123
|
}
|
106
|
-
|
124
|
+
|
125
|
+
r = create_and_send_rwhois_request(params_basic)
|
126
|
+
|
107
127
|
if WhoisXMLAPI.callbacks[:rwhois]
|
108
128
|
WhoisXMLAPI.callbacks[:rwhois].each do |cb|
|
109
129
|
cb.call
|
110
130
|
end
|
111
131
|
end
|
132
|
+
|
112
133
|
if r && r.parsed_response && r.parsed_response['domains']
|
113
134
|
res.domains = r.parsed_response['domains']
|
114
135
|
res.save
|
@@ -117,37 +138,79 @@ module WhoisXMLAPI
|
|
117
138
|
res.save
|
118
139
|
end
|
119
140
|
else
|
120
|
-
|
141
|
+
WhoisXMLAPI.logger.debug "WhoisXMLAPI rwhois - no domains found for #{entity_name}!"
|
121
142
|
res.domains = []
|
122
143
|
res.save
|
123
144
|
end
|
124
145
|
end
|
125
146
|
res
|
126
147
|
end
|
127
|
-
|
148
|
+
|
149
|
+
|
128
150
|
def exists?(domain)
|
129
151
|
xquery = {
|
130
152
|
:cmd => 'GET_DN_AVAILABILITY',
|
131
153
|
:domainName => domain,
|
132
|
-
:outputFormat => '
|
133
|
-
:
|
134
|
-
:password => WhoisXMLAPI.password
|
154
|
+
:outputFormat => 'JSON',
|
155
|
+
:apiKey => WhoisXMLAPI.api_key
|
135
156
|
}
|
136
157
|
r = HTTParty.get("#{WhoisXMLAPI.domain}/whoisserver/WhoisService", :query => xquery, :timeout => 120)
|
137
158
|
|
138
|
-
|
159
|
+
# WhoisXML and HTTParty are sometimes returning a Hash and not a JSON string as requested,
|
160
|
+
# which is causing an error of "no implicit conversion of Hash into String" when we call JSON.parse.
|
161
|
+
# Logger message is to monitor whether WhoisXML and/or HTTParty will still return a string on occasion.
|
162
|
+
if r.parsed_response.is_a?(String)
|
163
|
+
Rails.logger.debug "WhoisXML passed back parsed_response as a String instead of a Hash for #{domain}. Exists? method"
|
164
|
+
resp = JSON.parse(r.parsed_response)
|
165
|
+
else
|
166
|
+
resp = r.parsed_response
|
167
|
+
end
|
168
|
+
|
139
169
|
resp["DomainInfo"]["domainAvailability"] == "UNAVAILABLE"
|
140
170
|
end
|
141
171
|
|
172
|
+
|
142
173
|
def account_balance
|
143
174
|
aquery = {
|
144
175
|
:servicetype => 'accountbalance',
|
145
176
|
:output_format => 'JSON',
|
146
|
-
:
|
147
|
-
:password => WhoisXMLAPI.password
|
177
|
+
:apiKey => WhoisXMLAPI.api_key
|
148
178
|
}
|
149
179
|
r = HTTParty.get("#{WhoisXMLAPI.domain}/accountServices.php", :query => aquery, :timeout => 120)
|
150
|
-
|
180
|
+
|
181
|
+
# WhoisXML and HTTParty are sometimes returning a Hash and not a JSON string as requested,
|
182
|
+
# which is causing an error of "no implicit conversion of Hash into String" when we call JSON.parse.
|
183
|
+
# Logger message is to monitor whether WhoisXML and/or HTTParty will still return a string on occasion.
|
184
|
+
if r.parsed_response.is_a?(String)
|
185
|
+
Rails.logger.debug "WhoisXML passed back parsed_response as a String instead of a Hash. Account_balance method"
|
186
|
+
JSON.parse(r.parsed_response)
|
187
|
+
else
|
188
|
+
r.parsed_response
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
####################################################################################################
|
195
|
+
private
|
196
|
+
####################################################################################################
|
197
|
+
|
198
|
+
|
199
|
+
def self.create_and_send_rwhois_request(params_basic)
|
200
|
+
uri = URI.parse('https://reverse-whois-api.whoisxmlapi.com/api/v2')
|
201
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
202
|
+
http.use_ssl = true
|
203
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
204
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
205
|
+
request.add_field('Content-Type', 'application/json')
|
206
|
+
request.add_field('Accept', 'application/json')
|
207
|
+
request.body = params_basic.to_json
|
208
|
+
r = http.request(request)
|
209
|
+
# used for debugging
|
210
|
+
# puts JSON.parse(r.body).to_yaml
|
211
|
+
return r
|
151
212
|
end
|
152
|
-
|
153
|
-
end
|
213
|
+
|
214
|
+
end # of class Client
|
215
|
+
|
216
|
+
end # of module WhoisXMLAPI
|
data/lib/whoisxmlapi/version.rb
CHANGED
data/whoisxmlapi.gemspec
CHANGED
@@ -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"]
|
10
|
-
spec.email = ["dhillard@brandle.net"]
|
9
|
+
spec.authors = ["Christopher Maujean", "David Hillard", "Matt Appel", "Chip Roberson"]
|
10
|
+
spec.email = ["cmaujean@brandle.net", "dhillard@brandle.net", "mappel@brandle.net", "chip@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,108 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whoisxmlapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Maujean
|
8
8
|
- David Hillard
|
9
|
+
- Matt Appel
|
10
|
+
- Chip Roberson
|
9
11
|
autorequire:
|
10
12
|
bindir: bin
|
11
13
|
cert_chain: []
|
12
|
-
date:
|
14
|
+
date: 2018-11-22 00:00:00.000000000 Z
|
13
15
|
dependencies:
|
14
16
|
- !ruby/object:Gem::Dependency
|
15
17
|
name: activesupport
|
16
18
|
requirement: !ruby/object:Gem::Requirement
|
17
19
|
requirements:
|
18
|
-
- - ~>
|
20
|
+
- - "~>"
|
19
21
|
- !ruby/object:Gem::Version
|
20
22
|
version: '3.2'
|
21
23
|
type: :runtime
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
24
26
|
requirements:
|
25
|
-
- - ~>
|
27
|
+
- - "~>"
|
26
28
|
- !ruby/object:Gem::Version
|
27
29
|
version: '3.2'
|
28
30
|
- !ruby/object:Gem::Dependency
|
29
31
|
name: mongoid
|
30
32
|
requirement: !ruby/object:Gem::Requirement
|
31
33
|
requirements:
|
32
|
-
- -
|
34
|
+
- - ">="
|
33
35
|
- !ruby/object:Gem::Version
|
34
36
|
version: '0'
|
35
37
|
type: :runtime
|
36
38
|
prerelease: false
|
37
39
|
version_requirements: !ruby/object:Gem::Requirement
|
38
40
|
requirements:
|
39
|
-
- -
|
41
|
+
- - ">="
|
40
42
|
- !ruby/object:Gem::Version
|
41
43
|
version: '0'
|
42
44
|
- !ruby/object:Gem::Dependency
|
43
45
|
name: httparty
|
44
46
|
requirement: !ruby/object:Gem::Requirement
|
45
47
|
requirements:
|
46
|
-
- -
|
48
|
+
- - ">="
|
47
49
|
- !ruby/object:Gem::Version
|
48
50
|
version: '0'
|
49
51
|
type: :runtime
|
50
52
|
prerelease: false
|
51
53
|
version_requirements: !ruby/object:Gem::Requirement
|
52
54
|
requirements:
|
53
|
-
- -
|
55
|
+
- - ">="
|
54
56
|
- !ruby/object:Gem::Version
|
55
57
|
version: '0'
|
56
58
|
- !ruby/object:Gem::Dependency
|
57
59
|
name: public_suffix
|
58
60
|
requirement: !ruby/object:Gem::Requirement
|
59
61
|
requirements:
|
60
|
-
- - ~>
|
62
|
+
- - "~>"
|
61
63
|
- !ruby/object:Gem::Version
|
62
64
|
version: 1.4.6
|
63
65
|
type: :runtime
|
64
66
|
prerelease: false
|
65
67
|
version_requirements: !ruby/object:Gem::Requirement
|
66
68
|
requirements:
|
67
|
-
- - ~>
|
69
|
+
- - "~>"
|
68
70
|
- !ruby/object:Gem::Version
|
69
71
|
version: 1.4.6
|
70
72
|
- !ruby/object:Gem::Dependency
|
71
73
|
name: bundler
|
72
74
|
requirement: !ruby/object:Gem::Requirement
|
73
75
|
requirements:
|
74
|
-
- - ~>
|
76
|
+
- - "~>"
|
75
77
|
- !ruby/object:Gem::Version
|
76
78
|
version: '1.3'
|
77
79
|
type: :development
|
78
80
|
prerelease: false
|
79
81
|
version_requirements: !ruby/object:Gem::Requirement
|
80
82
|
requirements:
|
81
|
-
- - ~>
|
83
|
+
- - "~>"
|
82
84
|
- !ruby/object:Gem::Version
|
83
85
|
version: '1.3'
|
84
86
|
- !ruby/object:Gem::Dependency
|
85
87
|
name: rake
|
86
88
|
requirement: !ruby/object:Gem::Requirement
|
87
89
|
requirements:
|
88
|
-
- -
|
90
|
+
- - ">="
|
89
91
|
- !ruby/object:Gem::Version
|
90
92
|
version: '0'
|
91
93
|
type: :development
|
92
94
|
prerelease: false
|
93
95
|
version_requirements: !ruby/object:Gem::Requirement
|
94
96
|
requirements:
|
95
|
-
- -
|
97
|
+
- - ">="
|
96
98
|
- !ruby/object:Gem::Version
|
97
99
|
version: '0'
|
98
100
|
description: Gem for accessing the Whois XML API via JSON, with caching
|
99
101
|
email:
|
102
|
+
- cmaujean@brandle.net
|
100
103
|
- dhillard@brandle.net
|
104
|
+
- mappel@brandle.net
|
105
|
+
- chip@brandle.net
|
101
106
|
executables: []
|
102
107
|
extensions: []
|
103
108
|
extra_rdoc_files: []
|
104
109
|
files:
|
105
|
-
- .gitignore
|
110
|
+
- ".gitignore"
|
106
111
|
- Gemfile
|
107
112
|
- Gemfile.lock
|
108
113
|
- LICENSE.txt
|
@@ -129,17 +134,17 @@ require_paths:
|
|
129
134
|
- lib
|
130
135
|
required_ruby_version: !ruby/object:Gem::Requirement
|
131
136
|
requirements:
|
132
|
-
- -
|
137
|
+
- - ">="
|
133
138
|
- !ruby/object:Gem::Version
|
134
139
|
version: '0'
|
135
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
141
|
requirements:
|
137
|
-
- -
|
142
|
+
- - ">="
|
138
143
|
- !ruby/object:Gem::Version
|
139
144
|
version: '0'
|
140
145
|
requirements: []
|
141
146
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
147
|
+
rubygems_version: 2.7.7
|
143
148
|
signing_key:
|
144
149
|
specification_version: 4
|
145
150
|
summary: whoisxmlapi.com access
|