From 8374733be41f82d51590bd6bc9fab895fae540d7 Mon Sep 17 00:00:00 2001 From: whoisxmlapi Date: Thu, 19 Jul 2018 21:34:20 +0300 Subject: [PATCH] Ruby sample. --- ruby/registrant_alert_api_v2.rb | 68 +++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 ruby/registrant_alert_api_v2.rb diff --git a/ruby/registrant_alert_api_v2.rb b/ruby/registrant_alert_api_v2.rb new file mode 100644 index 0000000..02313a5 --- /dev/null +++ b/ruby/registrant_alert_api_v2.rb @@ -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://registrant-alert-api.whoisxmlapi.com/api/v2' + +######################## +# Fill in your details # +######################## +key = 'Your registrant alert api key' + +params_advanced = { + advancedSearchTerms: [ + { + field: 'RegistrantContact.Name', + term: 'Test' + } + ], + mode: 'purchase', + apiKey: key, + sinceDate: '2018-07-10' +} + +params_basic = { + basicSearchTerms: { + include: %w[ + whois + api + ], + exclude: %w[ + online + ] + }, + mode: 'purchase', + apiKey: key, + sinceDate: '2018-07-10' +} + +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 \ No newline at end of file