Skip to content

Ruby SDK

RubyGems GitHub

The IPWho Ruby SDK wraps the IP geolocation API in idiomatic Ruby — typed response objects, built-in error classes, and a single gem install. One call returns the full payload: geolocation, timezone, currency, connection (ASN/ISP), security flags, and more.

Terminal window
gem install ipwho
gem "ipwho"

Ruby >= 2.5, Faraday. Client: IpwhoApi::Client.

require "ipwho"
client = IpwhoApi::Client.new(ENV.fetch("IPWHO_API_KEY"))
res = client.lookup("8.8.8.8") # GET /ip/{ip}
me = client.me # GET /me
bulk = client.bulk(["8.8.8.8", "1.1.1.1"]) # GET /bulk/{a,b,c}
puts res.data.geoLocation.country # United States
begin
res = client.lookup("8.8.8.8")
rescue IpwhoApi::Errors::InvalidIPError
# malformed IP address (404)
rescue IpwhoApi::Errors::RateLimitError
# plan limit reached (429)
rescue IpwhoApi::Errors::APIResponseError
# unexpected response
end
  • lookup(ip) — GET /ip/{ip}
  • me — GET /me
  • bulk(ips) — GET /bulk/{a,b,c}; rows on data.responseArray