Refactor last_fm configuration
Move all configuration outside of the LastFm module, so that it's not polluted with references to the parent music_library application.
This commit is contained in:
@@ -1,28 +1,19 @@
|
||||
defmodule LastFm.Supervisor do
|
||||
use Supervisor
|
||||
|
||||
def start_link(init_arg) do
|
||||
Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
|
||||
def start_link(config) do
|
||||
Supervisor.start_link(__MODULE__, config, name: __MODULE__)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def init(_opts) do
|
||||
def init(config) do
|
||||
:ok = LastFm.Feed.create_table!()
|
||||
|
||||
children = [
|
||||
{Phoenix.PubSub, name: LastFm.PubSub},
|
||||
{LastFm.Refresh, %{api: api(), user: "cloud8421", api_key: api_key()}}
|
||||
{LastFm.Refresh, config}
|
||||
]
|
||||
|
||||
Supervisor.init(children, strategy: :one_for_one)
|
||||
end
|
||||
|
||||
defp api_key do
|
||||
Application.get_env(:music_library, LastFm, [])
|
||||
|> Keyword.get(:api_key)
|
||||
end
|
||||
|
||||
defp api do
|
||||
Application.get_env(:music_library, :last_fm, LastFm.APIImpl)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user