Whoisxmlapi
Gem for accessing whoisxmlapi.com based on httparty and mongoid
Installation
Add this line to your application's Gemfile:
gem 'whoisxmlapi'
And then execute:
$ bundle
Or install it yourself as:
$ gem install whoisxmlapi
Usage
Whois
# config/initializers/whoisxmlapi.rb
WhoisXMLAPI.configure do |config|
config.username = ENV['WHOISXMLAPI_USERNAME']
config.password = ENV['WHOISXMLAPI_PASSWORD']
config.cache = true
config.cache_length = 1.minute
end
# elsewhere
wc = WhoisXMLAPI::Client.new
y = wc.whois("google.com")
# y should now be a WhoisXMLAPI::Result (or an exeption was thrown)
y.registrant.email
Associate your model with a whois record:
has_one :whois, as: :whoisable, autosave: true, class_name: "WhoisXMLAPI::Result"
Now we can get at the data:
myinstance.whois.registrant.email
RWhois
z = wc.rwhois(cmaujean@brandle.net)
z.domains
Associate your model with a rwhois record:
has_one :rwhois, as: :rwhoisable, autosave: true, class_name: "WhoisXMLAPI::RWhoisResult"
Account Balance
Check your whoisxmlapi credits:
balance = wc.account_balance
# {
# "balance"=>"464",
# "reserve"=>"500",
# "monthly_balance"=>"0",
# "monthly_reserve"=>"0",
# "reverse_whois_balance"=>"0",
# "reverse_whois_reserve"=>"0",
# "reverse_whois_monthly_balance"=>"0",
# "reverse_whois_monthly_reserve"=>"0",
# "ba_query_balance"=>nil,
# "ba_query_reserve"=>nil,
# "ra_query_balance"=>nil,
# "ra_query_reserve"=>nil,
# "ds_query_balance"=>nil,
# "ds_query_reserve"=>nil
# }
Callbacks
You can add callbacks to your whois and rwhois calls via the initializer:
config.callbacks[:whois] << Proc.new { SystemCumulativeStats.increment_whoisxmlapi_requests }
config.callbacks[:rwhois] << Proc.new { SystemCumulativeStats.increment_rwhoisxmlapi_requests }
The callbacks will be called after the request to whoisxmlapi.com has been made. NOTE: Callback arguments are not currently supported.
Exists
Boolean check to see if a domain is registered.
wc.exists("foo.com")
#=> true
wc.exists("sdflsdfhwetewrw.com")
#=> false
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request