Use NimbleOptions to validate LastFm.Config

This commit is contained in:
Claudio Ortolina
2024-12-04 14:58:05 +00:00
parent 24319b1bff
commit 774c8d6006
+34 -1
View File
@@ -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