From eb2169bcea64700e4e019855d4d288e198cb1085 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Fri, 16 Jan 2026 15:50:57 +0100 Subject: [PATCH 1/2] Add resproxy API support Add resproxy method to IPinfo for looking up residential proxy information for IP addresses. The resproxy API endpoint returns: - ip: The IP address - last_seen: Last recorded date when the proxy was active - percent_days_seen: Percentage of days active in the last 7-day period - service: Name of the residential proxy service --- lib/ipinfo.rb | 17 +++++++++++++++++ test/ipinfo_test.rb | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/lib/ipinfo.rb b/lib/ipinfo.rb index 2d46b1f..433e5c5 100644 --- a/lib/ipinfo.rb +++ b/lib/ipinfo.rb @@ -54,6 +54,23 @@ def details_v6(ip_address = nil) details_base(ip_address, :v6) end + def resproxy(ip_address) + cache_key_str = "resproxy:#{ip_address}" + res = @cache.get(cache_key(cache_key_str)) + return Response.new(res) unless res.nil? + + response = @httpc.get("/resproxy/#{CGI.escape(ip_address)}", :v4) + + if response.status.eql?(429) + raise RateLimitError, + RATE_LIMIT_MESSAGE + end + + details = JSON.parse(response.body, symbolize_names: true) + @cache.set(cache_key(cache_key_str), details) + Response.new(details) + end + def get_map_url(ips) if !ips.kind_of?(Array) return JSON.generate({:error => 'Invalid input. Array required!'}) diff --git a/test/ipinfo_test.rb b/test/ipinfo_test.rb index d5a69ba..fdf96e8 100644 --- a/test/ipinfo_test.rb +++ b/test/ipinfo_test.rb @@ -5,6 +5,7 @@ class IPinfoTest < Minitest::Test TEST_IPV4 = '8.8.8.8' TEST_IPV6 = '2001:240:2a54:3900::' + TEST_RESPROXY_IP = '175.107.211.204' def assert_ip6(resp) assert_equal(resp.ip, TEST_IPV6) @@ -181,6 +182,26 @@ def test_lookup_ip4 end end + def test_resproxy + ipinfo = IPinfo.create(ENV['IPINFO_TOKEN']) + + # multiple checks for cache + (0...5).each do |_| + resp = ipinfo.resproxy(TEST_RESPROXY_IP) + assert_equal(resp.ip, TEST_RESPROXY_IP) + refute_nil(resp.last_seen) + refute_nil(resp.percent_days_seen) + refute_nil(resp.service) + end + end + + def test_resproxy_empty + ipinfo = IPinfo.create(ENV['IPINFO_TOKEN']) + + resp = ipinfo.resproxy(TEST_IPV4) + assert_equal(resp.all, {}) + end + # # Requires IPv6 support # def test_lookup_ip4_on_host_v6 # ipinfo = IPinfo.create(ENV['IPINFO_TOKEN']) From 0bd8f833a2ba49ef6efe40bc5dc024634b595ada Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Wed, 21 Jan 2026 16:19:18 +0100 Subject: [PATCH 2/2] Fix unrelated tests failures --- test/ipinfo_test.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/test/ipinfo_test.rb b/test/ipinfo_test.rb index fdf96e8..5663d7c 100644 --- a/test/ipinfo_test.rb +++ b/test/ipinfo_test.rb @@ -53,14 +53,8 @@ def assert_ip6(resp) phone: '+000000000' } ) - assert_equal( - resp.domains, - { - page: 0, - total: 0, - domains: [] - } - ) + assert_equal(resp.domains[:total], 0) + assert_equal(resp.domains[:domains], []) end def assert_ip4(resp)