# geolite2data


Downloads and updates the [GeoLite2 databases from MaxMind]( for Erlang and Elixir.

Designed to be used alongside other applications like [geolix](

## Installation

Add `geolite2data` to your project's dependencies in `mix.exs`

defp deps do
    {:geolite2data, "~> 1.0.0"}

Add `geolite2data` to your project's dependencies in your `Makefile` for [``]( or the following to your `rebar.config`

{deps, [
  {geolite2data, ".*", {git, "git://", {branch, "master"}}}

## Configuration

When using `mix` along with [geolix](, the following configuration may be used:

config :geolite2data,
  geolix_updater: true

This will automatically check for updates once a day and load any changes into geolix.

The defaults for all configuration options are:

config :geolite2data,
  autoupdate: 86400, # 24 hours
  databases: [
    {:city, "", ""},
    {:country, "", ""}
  geolix_updater: false,
  keep_releases: 2,
  logger: false

For Erlang applications, there is an event handler that can be used to watch for any changes to database files:



%% gen_server callbacks

-record(state, {}).

start_link() ->
    gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

init([]) ->
    ok = geolite2data_event:add_handler(geolite2data_event_handler, self()),
    {ok, #state{}}.

handle_call(_Request, _From, State) ->
    {reply, ignored, State}.

handle_cast(_Request, State) ->
    {noreply, State}.

handle_info({'$geolite2data-event', {database, announce, Key, Filename}}, State) ->
    %% Handle changes to the database identified by 'Key' and stored at 'Filename'
    {noreply, State};
handle_info(_Info, State) ->
    {noreply, State}.

terminate(_Reason, _State) ->

code_change(_OldVsn, State, _Extra) ->
    {ok, State}.

See `geolite2data_geolix_updater` and `geolite2data_logger` for more examples.

## Usage

The current filename for a database can be fetched with `geolite2data:get_database/1`:

% {ok, ".../priv/releases/country/20160513224618GeoLite2-Country.mmdb.gz"}

## License