Extract LastFm.Config module
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
defmodule LastFm.Config do
|
||||||
|
@type t :: %{
|
||||||
|
api: module(),
|
||||||
|
api_key: String.t(),
|
||||||
|
user: String.t(),
|
||||||
|
refresh_interval: pos_integer()
|
||||||
|
}
|
||||||
|
|
||||||
|
defstruct api: LastFm.Api,
|
||||||
|
api_key: "",
|
||||||
|
user: "",
|
||||||
|
refresh_interval: 60_000
|
||||||
|
|
||||||
|
@spec new(Enumerable.t()) :: t()
|
||||||
|
def new(opts) do
|
||||||
|
struct(__MODULE__, opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -5,12 +5,7 @@ defmodule LastFm.Refresh do
|
|||||||
|
|
||||||
alias LastFm.Feed
|
alias LastFm.Feed
|
||||||
|
|
||||||
@type config :: %{
|
@type config :: LastFm.Config.t()
|
||||||
api: module(),
|
|
||||||
api_key: String.t(),
|
|
||||||
user: String.t(),
|
|
||||||
refresh_interval: pos_integer()
|
|
||||||
}
|
|
||||||
|
|
||||||
@spec start_link(config) :: GenServer.on_start()
|
@spec start_link(config) :: GenServer.on_start()
|
||||||
def start_link(config) do
|
def start_link(config) do
|
||||||
@@ -25,8 +20,6 @@ defmodule LastFm.Refresh do
|
|||||||
@impl true
|
@impl true
|
||||||
@spec init(config) :: {:ok, config, {:continue, :refresh}} | :ignore
|
@spec init(config) :: {:ok, config, {:continue, :refresh}} | :ignore
|
||||||
def init(config) do
|
def init(config) do
|
||||||
config = Map.new(config)
|
|
||||||
|
|
||||||
if enabled?(config) do
|
if enabled?(config) do
|
||||||
{:ok, config, {:continue, :refresh}}
|
{:ok, config, {:continue, :refresh}}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -43,5 +43,6 @@ defmodule MusicLibrary.Application do
|
|||||||
|
|
||||||
defp last_fm_config do
|
defp last_fm_config do
|
||||||
Application.get_env(:music_library, LastFm)
|
Application.get_env(:music_library, LastFm)
|
||||||
|
|> LastFm.Config.new()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user