Remove LastFm.APIBehaviour

This commit is contained in:
Claudio Ortolina
2025-02-27 13:43:24 +00:00
parent 3d11cd585d
commit 7ac2f7a815
7 changed files with 12 additions and 35 deletions
@@ -1,6 +1,4 @@
defmodule LastFm.APIImpl do
@behaviour LastFm.APIBehaviour
defmodule LastFm.API do
require Logger
alias LastFm.{Artist, Track}
@@ -28,7 +26,6 @@ defmodule LastFm.APIImpl do
defp map_error(29), do: :rate_limit_exceeded
end
@impl true
def get_recent_tracks(config) do
params =
config
@@ -42,7 +39,6 @@ defmodule LastFm.APIImpl do
|> get_request()
end
@impl true
def get_artist_info(id_or_name_option, config) do
params =
config
@@ -57,7 +53,6 @@ defmodule LastFm.APIImpl do
|> get_request()
end
@impl true
def get_similar_artists(id_or_name_option, config) do
params =
config
-12
View File
@@ -1,12 +0,0 @@
defmodule LastFm.APIBehaviour do
alias LastFm.{Artist, Config, Track}
@type musicbrainz_id :: String.t()
@type name :: String.t()
@type config :: Config.t()
@callback get_recent_tracks(config) :: {:ok, [Track.t()]} | {:error, String.t()}
@callback get_artist_info({:musicbrainz_id, musicbrainz_id} | {:name, name}, config) ::
{:ok, Artist.t()} | {:error, String.t()}
@callback get_similar_artists({:musicbrainz_id, musicbrainz_id} | {:name, name}, config) ::
{:ok, [Artist.t()]} | {:error, String.t()}
end
+2 -8
View File
@@ -1,6 +1,5 @@
defmodule LastFm.Config do
@type t :: %__MODULE__{
api: module(),
api_key: String.t(),
user: String.t(),
auto_refresh: boolean(),
@@ -9,9 +8,8 @@ defmodule LastFm.Config do
req_options: Keyword.t()
}
@enforce_keys [:api, :api_key, :user]
defstruct api: LastFm.Api,
api_key: "",
@enforce_keys [:api_key, :user]
defstruct api_key: "",
user: "",
auto_refresh: true,
refresh_interval: 60_000,
@@ -19,10 +17,6 @@ defmodule LastFm.Config do
req_options: []
@schema NimbleOptions.new!(
api: [
type: :atom,
required: true
],
api_key: [
type: :string,
required: true
+3 -3
View File
@@ -3,7 +3,7 @@ defmodule LastFm.Refresh do
require Logger
alias LastFm.{Config, Feed}
alias LastFm.{API, Config, Feed}
@type config :: Config.t()
@@ -31,7 +31,7 @@ defmodule LastFm.Refresh do
@spec handle_call(:refresh, GenServer.from(), config) ::
{:reply, :ok | {:error, term()}, config, pos_integer()}
def handle_call(:refresh, _from, config) do
case config.api.get_recent_tracks(config) do
case API.get_recent_tracks(config) do
{:ok, tracks} ->
Feed.update(tracks)
{:reply, :ok, config, config.refresh_interval}
@@ -53,7 +53,7 @@ defmodule LastFm.Refresh do
def handle_info(:timeout, config), do: refresh(config)
defp refresh(config) do
case config.api.get_recent_tracks(config) do
case API.get_recent_tracks(config) do
{:ok, tracks} ->
Feed.update(tracks)
{:noreply, config, config.refresh_interval}