Class: IpApiIo::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ipapi_io/client.rb

Overview

Client for the ip-api.io IP intelligence and email validation API.

client = IpApiIo::Client.new(api_key: "YOUR_API_KEY")
client.lookup("8.8.8.8") #=> { "ip" => "8.8.8.8", "location" => {...}, ... }

An API key is required by the live API — get a free key at ip-api.io.

Constant Summary collapse

BASE_URL =
"https://ip-api.io".freeze
MAX_BATCH_SIZE =
100

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, base_url: BASE_URL, timeout: 10) ⇒ Client

Returns a new instance of Client.



19
20
21
22
23
# File 'lib/ipapi_io/client.rb', line 19

def initialize(api_key: nil, base_url: BASE_URL, timeout: 10)
  @api_key = api_key
  @base_url = base_url.sub(%r{/+\z}, "")
  @timeout = timeout
end

Instance Method Details

#asn(ip) ⇒ Object



46
47
48
# File 'lib/ipapi_io/client.rb', line 46

def asn(ip)
  request(:get, "/api/v1/asn/#{encode(ip)}")
end

#domain_age(domain) ⇒ Object



97
98
99
# File 'lib/ipapi_io/client.rb', line 97

def domain_age(domain)
  request(:get, "/api/v1/domain/age/#{encode(domain)}")
end

#domain_age_batch(domains) ⇒ Object

Raises:

  • (ArgumentError)


101
102
103
104
105
# File 'lib/ipapi_io/client.rb', line 101

def domain_age_batch(domains)
  raise ArgumentError, "domains must not be empty" if domains.empty?

  request(:post, "/api/v1/domain/age/batch", body: { domains: domains })
end

#email_info(email) ⇒ Object

Syntax, disposability and MX analysis of an email address.



53
54
55
# File 'lib/ipapi_io/client.rb', line 53

def email_info(email)
  request(:get, "/api/v1/email/#{encode(email)}")
end

#email_risk_score(email) ⇒ Object



75
76
77
# File 'lib/ipapi_io/client.rb', line 75

def email_risk_score(email)
  request(:get, "/api/v1/risk-score/email/#{encode(email)}")
end

#forward_dns(hostname) ⇒ Object



89
90
91
# File 'lib/ipapi_io/client.rb', line 89

def forward_dns(hostname)
  request(:get, "/api/v1/dns/forward/#{encode(hostname)}")
end

#ip_reputation(ip) ⇒ Object



38
39
40
# File 'lib/ipapi_io/client.rb', line 38

def ip_reputation(ip)
  request(:get, "/api/v1/ip-reputation/#{encode(ip)}")
end

#lookup(ip = nil) ⇒ Object

Geolocation + threat intelligence for an IP (or the caller’s IP when nil).



28
29
30
# File 'lib/ipapi_io/client.rb', line 28

def lookup(ip = nil)
  request(:get, ip ? "/api/v1/ip/#{encode(ip)}" : "/api/v1/ip")
end

#lookup_batch(ips) ⇒ Object

Look up to 100 IP addresses in a single request.



33
34
35
36
# File 'lib/ipapi_io/client.rb', line 33

def lookup_batch(ips)
  check_batch!(ips, "ips")
  request(:post, "/api/v1/ip/batch", body: { ips: ips })
end

#mx_records(domain) ⇒ Object



93
94
95
# File 'lib/ipapi_io/client.rb', line 93

def mx_records(domain)
  request(:get, "/api/v1/dns/mx/#{encode(domain)}")
end

#rate_limitObject

– Account —————————————————————-



109
110
111
# File 'lib/ipapi_io/client.rb', line 109

def rate_limit
  request(:get, "/api/v1/ratelimit")
end

#reverse_dns(ip) ⇒ Object



85
86
87
# File 'lib/ipapi_io/client.rb', line 85

def reverse_dns(ip)
  request(:get, "/api/v1/dns/reverse/#{encode(ip)}")
end

#risk_score(ip = nil) ⇒ Object

Fraud risk score for an IP (or the caller’s IP when nil).



71
72
73
# File 'lib/ipapi_io/client.rb', line 71

def risk_score(ip = nil)
  request(:get, ip ? "/api/v1/risk-score/#{encode(ip)}" : "/api/v1/risk-score")
end

#tor_check(ip) ⇒ Object



42
43
44
# File 'lib/ipapi_io/client.rb', line 42

def tor_check(ip)
  request(:get, "/api/v1/tor/#{encode(ip)}")
end

#usage_summaryObject



113
114
115
# File 'lib/ipapi_io/client.rb', line 113

def usage_summary
  request(:get, "/api/v1/usage/summary")
end

#validate_email(email) ⇒ Object

Advanced validation including SMTP deliverability checks.



58
59
60
# File 'lib/ipapi_io/client.rb', line 58

def validate_email(email)
  request(:get, "/api/v1/email/advanced/#{encode(email)}")
end

#validate_email_batch(emails) ⇒ Object

Advanced-validate up to 100 email addresses in a single request.



63
64
65
66
# File 'lib/ipapi_io/client.rb', line 63

def validate_email_batch(emails)
  check_batch!(emails, "emails")
  request(:post, "/api/v1/email/advanced/batch", body: { emails: emails })
end

#whois(domain) ⇒ Object

– DNS & domains ———————————————————-



81
82
83
# File 'lib/ipapi_io/client.rb', line 81

def whois(domain)
  request(:get, "/api/v1/dns/whois/#{encode(domain)}")
end