Fix geospatial runtime configuration

Geospatial configuration was only evaluated at compile-time, not at
runtime

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-03-16 15:33:44 +01:00
parent ad913eb131
commit 35e641bcff
8 changed files with 43 additions and 35 deletions

View File

@@ -17,8 +17,6 @@ defmodule Mobilizon.Service.Geospatial.MapQuest do
@behaviour Provider
@api_key Application.get_env(:mobilizon, __MODULE__) |> get_in([:api_key])
@api_key_missing_message "API Key required to use MapQuest"
@impl Provider
@@ -27,7 +25,7 @@ defmodule Mobilizon.Service.Geospatial.MapQuest do
"""
@spec geocode(String.t(), keyword()) :: list(Address.t())
def geocode(lon, lat, options \\ []) do
api_key = Keyword.get(options, :api_key, @api_key)
api_key = Keyword.get(options, :api_key, api_key())
limit = Keyword.get(options, :limit, 10)
open_data = Keyword.get(options, :open_data, true)
@@ -56,7 +54,7 @@ defmodule Mobilizon.Service.Geospatial.MapQuest do
@spec search(String.t(), keyword()) :: list(Address.t())
def search(q, options \\ []) do
limit = Keyword.get(options, :limit, 10)
api_key = Keyword.get(options, :api_key, @api_key)
api_key = Keyword.get(options, :api_key, api_key())
open_data = Keyword.get(options, :open_data, true)
@@ -114,4 +112,8 @@ defmodule Mobilizon.Service.Geospatial.MapQuest do
street: Map.get(address, "street")
}
end
defp api_key do
Application.get_env(:mobilizon, __MODULE__) |> get_in([:api_key])
end
end