From c398e813cf54734a1d97d85db4b53da7f4ba4be8 Mon Sep 17 00:00:00 2001 From: ip2location Date: Fri, 25 Aug 2023 14:48:24 +0800 Subject: [PATCH 1/2] Added support for IP2Location.io API --- README.md | 10 ++++++++++ lib/geoip/lookup.ex | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 6ba6992..084f85d 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,16 @@ config :geoip, provider: :ipstack, api_key: "your-api-key" config :geoip, provider: :ipinfo, api_key: "your-api-key" ``` +#### IP2Location.io + +[IP2Location.io](https://ip2location.io) does not support lookup by hostname (only ip address), therefore the above examples where a hostname is used will return an error. + +NOTE: Translation for certain columns is available for Plus and Security plan. You can visit the Parameters section in [https://www.ip2location.io/ip2location-documentation](https://www.ip2location.io/ip2location-documentation) for more information + +```elixir +config :geoip, provider: :ip2locationio, api_key: "your-api-key" +``` + #### test Provides an easy way to provide mock lookup data in test environments. diff --git a/lib/geoip/lookup.ex b/lib/geoip/lookup.ex index 39e1f60..5459c98 100644 --- a/lib/geoip/lookup.ex +++ b/lib/geoip/lookup.ex @@ -81,6 +81,11 @@ defmodule GeoIP.Lookup do do: "#{http_protocol()}://ipinfo.io/#{host}/json?token=#{Config.api_key()}#{Config.extra_params()}" + + defp lookup_url(host, :ip2locationio), + do: + "#{http_protocol()}://api.ip2location.io/?key=#{Config.api_key()}&ip=#{host}#{Config.extra_params()}" + defp lookup_url(_host, provider) do raise ArgumentError, "Unknown provider: '#{inspect(provider)}'. Please check your geoip configuration." From 88988a5f6939e393dc8d7661a8b842c32f47b8d1 Mon Sep 17 00:00:00 2001 From: ip2location Date: Mon, 28 Aug 2023 08:45:46 +0800 Subject: [PATCH 2/2] Update lookup.ex --- lib/geoip/lookup.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/geoip/lookup.ex b/lib/geoip/lookup.ex index 5459c98..d628a03 100644 --- a/lib/geoip/lookup.ex +++ b/lib/geoip/lookup.ex @@ -81,7 +81,6 @@ defmodule GeoIP.Lookup do do: "#{http_protocol()}://ipinfo.io/#{host}/json?token=#{Config.api_key()}#{Config.extra_params()}" - defp lookup_url(host, :ip2locationio), do: "#{http_protocol()}://api.ip2location.io/?key=#{Config.api_key()}&ip=#{host}#{Config.extra_params()}"