First pass at uniformed types, specs and docs

- spec public functions (skipping controllers, views, live views and
components)
- use types instead of explanations in docs
- remove redundant docs
- fix typos
This commit is contained in:
Claudio Ortolina
2026-03-06 08:33:11 +00:00
parent 99e30d5fdf
commit 7cf9b4e7f8
81 changed files with 652 additions and 300 deletions
+13
View File
@@ -2,19 +2,24 @@ defmodule LastFm do
alias LastFm.{API, Feed, Refresh, Scrobble, Track, Worker}
alias MusicLibrary.{BackgroundRepo, Repo}
@spec subscribe_to_feed() :: :ok
def subscribe_to_feed, do: Feed.subscribe()
@spec refresh_scrobbled_tracks() :: :ok | {:error, term()}
def refresh_scrobbled_tracks, do: Refresh.refresh()
@spec get_tracks(keyword()) :: {:ok, [Track.t()]} | {:error, term()}
def get_tracks(opts) do
last_fm_config = last_fm_config()
API.get_recent_tracks(opts, last_fm_config)
end
@spec lowest_scrobbled_at_uts() :: integer() | nil
def lowest_scrobbled_at_uts do
Repo.aggregate(Track, :min, :scrobbled_at_uts)
end
@spec backfill_scrobbled_tracks() :: {:ok, Oban.Job.t()} | {:error, Ecto.Changeset.t()}
def backfill_scrobbled_tracks do
to_uts = lowest_scrobbled_at_uts()
@@ -23,6 +28,7 @@ defmodule LastFm do
|> BackgroundRepo.insert()
end
@spec get_artist_info(String.t(), String.t()) :: {:ok, LastFm.Artist.t()} | {:error, term()}
def get_artist_info(musicbrainz_id, name) do
last_fm_config = last_fm_config()
@@ -40,6 +46,8 @@ defmodule LastFm do
end
end
@spec get_similar_artists(String.t(), String.t()) ::
{:ok, [LastFm.Artist.t()]} | {:error, term()}
def get_similar_artists(musicbrainz_id, name) do
last_fm_config = last_fm_config()
@@ -57,6 +65,8 @@ defmodule LastFm do
end
end
@spec get_artist_tags(String.t(), String.t()) ::
{:ok, [{String.t(), integer()}]} | {:error, term()}
def get_artist_tags(musicbrainz_id, name) do
last_fm_config = last_fm_config()
@@ -74,12 +84,14 @@ defmodule LastFm do
end
end
@spec get_session(String.t()) :: {:ok, LastFm.Session.t()} | {:error, term()}
def get_session(token) do
last_fm_config = last_fm_config()
API.get_session(token, last_fm_config)
end
@spec scrobble([Scrobble.t()], String.t()) :: {:ok, map()} | {:error, term()}
def scrobble(scrobbles, session_key) do
last_fm_config = last_fm_config()
@@ -88,6 +100,7 @@ defmodule LastFm do
|> API.scrobble(session_key, last_fm_config)
end
@spec auth_url() :: String.t()
def auth_url do
last_fm_config = last_fm_config()
"https://www.last.fm/api/auth/?api_key=" <> last_fm_config.api_key