Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for IP2Location.io API #58

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading