Skip to content

Commit

Permalink
Added support for IP2Location.io API (#58)
Browse files Browse the repository at this point in the history
* Added support for IP2Location.io API

* Update lookup.ex
  • Loading branch information
ip2location authored Aug 29, 2023
1 parent 096a917 commit 444b82a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions lib/geoip/lookup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ 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."
Expand Down

0 comments on commit 444b82a

Please sign in to comment.