From 774c8d6006fb78713ba5f5c28bebd51112055242 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Wed, 4 Dec 2024 14:58:05 +0000 Subject: [PATCH] Use NimbleOptions to validate LastFm.Config --- lib/last_fm/config.ex | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) 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