Skip to content

Add ip2geo IP geolocation lookup#1707

Open
bfzli wants to merge 1 commit intoalexreisner:masterfrom
bfzli:add-ip2geo-provider
Open

Add ip2geo IP geolocation lookup#1707
bfzli wants to merge 1 commit intoalexreisner:masterfrom
bfzli:add-ip2geo-provider

Conversation

@bfzli
Copy link
Copy Markdown

@bfzli bfzli commented Apr 20, 2026

Summary

  • Adds a new IP address lookup for the ip2geo API
  • Supports IPv4 and IPv6 geocoding
  • Returns 30+ fields: city, country, continent, ASN, currency, flag, timezone, registered country, etc.
  • Authentication via X-Api-Key header (auto-injected from api_key config)
  • HTTPS only

Configuration

Geocoder.configure(
  ip_lookup: :ip2geo,
  api_key: "your-api-key"
)

result = Geocoder.search("134.201.250.155").first
result.city          # => "Los Angeles"
result.country       # => "United States"
result.coordinates   # => [34.0544, -118.244]
result.asn_number    # => 25876
result.currency_code # => "USD"

Files changed

  • New: lib/geocoder/lookups/ip2geo.rb — lookup class
  • New: lib/geocoder/results/ip2geo.rb — result class with 30+ accessors
  • New: test/unit/lookups/ip2geo_test.rb — unit tests
  • New: test/fixtures/ip2geo_8_8_8_8, test/fixtures/ip2geo_no_results — test fixtures
  • Modified: lib/geocoder/lookup.rb — add :ip2geo to ip_services
  • Modified: test/test_helper.rb — add lookup stub
  • Modified: README_API_GUIDE.md — add documentation entry

Test plan

  • Lookup loads and registers in ip_services
  • Result class maps all fields correctly from API response
  • Loopback/private IP handling works
  • Live API test with real key returns correct data
  • No new dependencies added

Add support for the ip2geo.dev IP geolocation API as a new IP address
lookup service. Supports IPv4 and IPv6 with city, country, continent,
ASN, currency, flag, and timezone data.

Configuration:
    Geocoder.configure(ip_lookup: :ip2geo, api_key: 'your-key')

API docs: https://ip2geo.dev/docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant