Skip to content

Commit

Permalink
Merge pull request #9 from platogo/feature/fix-database-config
Browse files Browse the repository at this point in the history
Fix: Database config for downloading geolix data
  • Loading branch information
abangratz authored Sep 28, 2022
2 parents d0fbe3c + 3d1d069 commit a839198
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Wrapper around Geolix that supports periodic refresh of the GeoIP database.

```elixir
def deps do
[{:geo, git: "[email protected]:platogo/geoip-elixir.git"}, tag: "1.4.7"]
[{:geo, git: "[email protected]:platogo/geoip-elixir.git"}, tag: "1.4.8"]
end
```

Expand All @@ -32,3 +32,43 @@ You can manually disable database refresh completely (useful for tests which don
```elixir
config :geo, :disable_refresh, true
```

In order to use a fake database, add something similar to the following configuration to your configuration:

```elixir
config :geolix,
databases: [
%{
id: :city,
adapter: Geolix.Adapter.Fake,
data: %{
{1, 1, 1, 1} => %{country: %{iso_code: "AT"}, location: %{time_zone: "Europe/Vienna"}},
{2, 2, 2, 2} => %{country: %{iso_code: "HU"}, location: %{time_zone: "Europe/Budapest"}},
}
}
]
```

In order to use a downloaded database, use the following:

```elixir
geolix_database_path = "/absolute/path/to/ip_database.tar.gz"

config :geo,
disable_refresh: false,
database_path: geolix_database_path

config :geolix,
databases: [
%{
id: :city,
adapter: Geolix.Adapter.MMDB2,
source: geolix_database_path
}
]
```

## TODO

This should be changed so we no longer use `Application.get_env/2` for configuration, supervision is handled in the including
application, and `Task` is preferred over `GenServer`.
2 changes: 1 addition & 1 deletion lib/geo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule GEO do
# Refresh database file during compilation
{:ok, _started} = Application.ensure_all_started(:httpoison)

case GEO.Database.Refresh.refresh(false) do
case GEO.Database.Refresh.refresh() do
:ok -> :ok
:error -> raise "Could not refresh IP database"
end
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule GEO.Mixfile do
def project do
[
app: :geo,
version: "1.4.7",
version: "1.4.8",
elixir: "~> 1.13",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
Expand Down

0 comments on commit a839198

Please sign in to comment.