diff --git a/lib/last_fm/config.ex b/lib/last_fm/config.ex index 83325a2f..8bb7fe9f 100644 --- a/lib/last_fm/config.ex +++ b/lib/last_fm/config.ex @@ -15,9 +15,42 @@ defmodule LastFm.Config do refresh_interval: 60_000, user_agent: "change me" + @schema NimbleOptions.new!( + api: [ + type: :atom, + required: true + ], + api_key: [ + type: :string, + required: true + ], + user: [ + type: :string, + required: true + ], + auto_refresh: [ + type: :boolean, + required: false, + default: true + ], + refresh_interval: [ + type: :pos_integer, + required: false, + default: 60_000 + ], + user_agent: [ + type: :string, + required: false, + default: "change me" + ] + ) + + @doc NimbleOptions.docs(@schema) @spec resolve(atom) :: t def resolve(otp_app) do - app_config = Application.get_env(otp_app, LastFm) + app_config = + Application.get_env(otp_app, LastFm) + |> NimbleOptions.validate!(@schema) struct(__MODULE__, app_config) end