Prerequisites
- Ruby 3.0+ with
ip-api-ioinstalled - A free ip-api.io API key
Score an IP with risk_score_ip
Returns a score (0–100) and a human risk_level, plus the
factors that drove it. Use risk_score for the caller's IP.
client = Ipapi::Client.new(api_key: ENV.fetch("IP_API_IO_KEY"))
risk = client.risk_score_ip("185.220.101.1")
puts risk.score # 88
puts risk.risk_level # "high"
if risk.factors.ip
puts "#{risk.factors.ip.tor_node?} #{risk.factors.ip.datacenter?}"
end
if risk.score >= 75
# block, or send to manual review / step-up auth
end Score an email with email_risk_score
Same 0–100 scale, driven by email signals (disposable provider, invalid syntax). Use it to grade leads or gate sign-ups by address quality.
risk = client.email_risk_score("user@mailinator.com")
puts "#{risk.score} #{risk.risk_level}" # 90 high
puts risk.factors.email.disposable? if risk.factors.email # true Raw signals with ip_reputation
Returns the underlying reputation data for an IP as a hash — use it when you want the source signals rather than a computed score.
reputation = client.ip_reputation("185.220.101.1")
puts reputation