Skip to content

Commit

Permalink
add setup instructions for usage from an Elixir app
Browse files Browse the repository at this point in the history
  • Loading branch information
petrus-jvrensburg committed Jul 10, 2024
1 parent 6eb0dec commit 9e3097f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ Then clone the repository, run `make shell` and declare your key:
application:set_env(locus, license_key, "YOUR_LICENSE_KEY").
```

If you're using Elixir, add locus as a dependency to your mix project:

```elixir
defp deps do
[
...
{:locus, "~> 2.3"}
]
end
```

Then, configure your license key in `config.exs`:

```elixir
config :locus,
license_key: <MAXMIND_API_KEY>
```

#### 2\. Start the database loader

``` erlang
Expand All @@ -47,6 +65,17 @@ ok = locus:start_loader(country, {maxmind, "GeoLite2-Country"}).
% implementing the locus_custom_fetcher behaviour.
```

Or, in Elixir, start the database loaders that you'll be using in `application.ex`:

```elixir
def start(_type, _args) do
# :locus.start_loader(:asn, {:maxmind, "GeoLite2-ASN"})
# :locus.start_loader(:country, {:maxmind, "GeoLite2-Country"})
:locus.start_loader(:city, {:maxmind, "GeoLite2-City"})

...
```

#### 3\. Wait for the database to load (optional)

``` erlang
Expand Down Expand Up @@ -102,6 +131,17 @@ ok = locus:start_loader(country, {maxmind, "GeoLite2-Country"}).
<<"zh-CN">> => <<"美国"/utf8>>}}}}
```

Or, in Elixir, call the erlang library from your Elixir application:

```elixir
iex> :locus.lookup(:city, "93.184.216.34")
{:ok,
%{
"city" => %{"geoname_id" => 4945936, "names" => %{"en" => "Norwell"}},
...
}}
```

## Documentation

1. [Supported File Formats](#supported-file-formats)
Expand Down

0 comments on commit 9e3097f

Please sign in to comment.