Skip to content

Commit

Permalink
Ruby sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
whoisxmlapi committed Jul 20, 2018
1 parent 3d5112f commit 78c0817
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions ruby/reverse_whois_api_v2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
require 'json'
require 'net/https'
require 'openssl'
require 'uri'
require 'yaml' # only needed to print the returned result in a very pretty way

url = 'https://reverse-whois-api.whoisxmlapi.com/api/v2'

########################
# Fill in your details #
########################
key = 'Your reverse whois api key'

params_advanced = {
advancedSearchTerms: [
{
field: 'RegistrantContact.Name',
term: 'Test'
}
],
mode: 'purchase',
apiKey: key,
sinceDate: '2018-07-15'
}

params_basic = {
basicSearchTerms: {
include: %w[
test
],
exclude: %w[
whois
api
]
},
mode: 'purchase',
apiKey: key,
sinceDate: '2018-07-15'
}

uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)

# Connect using ssl
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.request_uri)

# Set headers
request.add_field('Content-Type', 'application/json')
request.add_field('Accept', 'application/json')

# Basic search

request.body = params_basic.to_json
response = http.request(request)

# Print pretty parsed json
puts 'Basic:'
puts JSON.parse(response.body).to_yaml

# Advanced search

request.body = params_advanced.to_json
response = http.request(request)

puts "\nAdvanced:"
puts JSON.parse(response.body).to_yaml

0 comments on commit 78c0817

Please sign in to comment.