Tune.Spotify.Session behaviour (tune v0.1.0)

Defines a behaviour that can be used to model an active user session against the Spotify API.

Implementations should be stateful: given an initial session id and authentication credentials, the implementation should perform authentication in setup/2. If successful, a session should be opened and used for any other function keyed by the same session id.

Most of the behaviour functions cover the Spotify HTTP Api and return structs defined under Tune.Spotify.Schema.

Two extra functions, subscribe/1 and broadcast/2, are used to define the mechanism used to notify other processes of changes in the session state.

For a working implementation, see Tune.Spotify.Session.HTTP.

Link to this section Summary

Link to this section Types

Link to this type

context_uri()

Specs

context_uri() :: String.t()
Link to this type

credentials()

Specs

credentials() :: Ueberauth.Auth.Credentials.t()

Specs

id() :: String.t()

Specs

item_id() :: String.t()

Specs

message() ::
  {:now_playing, Tune.Spotify.Schema.Player.t()}
  | {:player_token, player_token()}
  | {:devices, [Tune.Spotify.Schema.Device.t()]}
Link to this type

player_token()

Specs

player_token() :: binary() | nil

Specs

uri() :: String.t()

Link to this section Callbacks

Link to this callback

broadcast(id, message)

Specs

broadcast(id(), message()) :: :ok | {:error, term()}
Link to this callback

get_album(id, album_id)

Specs

get_album(id(), album_id :: Tune.Spotify.Schema.Album.id()) ::
  {:ok, Tune.Spotify.Schema.Album.t()} | {:error, term()}
Link to this callback

get_artist(id, artist_id)

Specs

get_artist(id(), artist_id :: Tune.Spotify.Schema.Artist.id()) ::
  {:ok, Tune.Spotify.Schema.Artist.t()} | {:error, term()}
Link to this callback

get_artist_albums(id, artist_id, pagination_options)

Specs

get_artist_albums(
  id(),
  artist_id :: Tune.Spotify.Schema.Artist.id(),
  pagination_options :: Tune.Spotify.Client.pagination_options()
) ::
  {:ok, %{albums: [Tune.Spotify.Schema.Album.t()], total: pos_integer()}}
  | {:error, term()}
Link to this callback

get_devices(id)

Specs

get_devices(id()) :: {:ok, [Tune.Spotify.Schema.Device.t()]} | {:error, term()}
Link to this callback

get_episodes(id, show_id)

Specs

get_episodes(id(), show_id :: Tune.Spotify.Schema.Show.id()) ::
  {:ok, [Tune.Spotify.Schema.Episode.t()]} | {:error, term()}
Link to this callback

get_player_token(id)

Specs

get_player_token(id()) :: {:ok, player_token()} | {:error, term()}
Link to this callback

get_playlist(id, playlist_id)

Specs

get_playlist(id(), playlist_id :: Tune.Spotify.Schema.Playlist.id()) ::
  {:ok, map()} | {:error, term()}
Link to this callback

get_profile(id)

Specs

get_profile(id()) :: {:ok, Tune.Spotify.Schema.User.t()} | {:error, term()}
Link to this callback

get_recommendations_from_artists(id, artist_ids)

Specs

get_recommendations_from_artists(
  id(),
  artist_ids :: [Tune.Spotify.Schema.Artist.id()]
) :: {:ok, [Tune.Spotify.Schema.Track.t()]} | {:error, term()}
Link to this callback

get_show(id, show_id)

Specs

get_show(id(), show_id :: Tune.Spotify.Schema.Show.id()) ::
  {:ok, Tune.Spotify.Schema.Show.t()} | {:error, term()}

Specs

next(id()) :: :ok | {:error, term()}
Link to this callback

now_playing(id)

Specs

now_playing(id()) :: Tune.Spotify.Schema.Player.t() | {:error, term()}

Specs

play(id(), uri()) :: :ok | {:error, term()}
Link to this callback

play(id, uri, context_uri)

Specs

play(id(), uri(), context_uri()) :: :ok | {:error, term()}

Specs

prev(id()) :: :ok | {:error, term()}
Link to this callback

recently_played_tracks(id, recently_played_tracks_options)

Specs

recently_played_tracks(
  id(),
  recently_played_tracks_options ::
    Tune.Spotify.Client.recently_played_tracks_options()
) :: {:ok, [Tune.Spotify.Schema.Track.t()]} | {:error, term()}
Link to this callback

refresh_devices(id)

Specs

refresh_devices(id()) :: :ok | {:error, term()}
Link to this callback

search(id, query, search_options)

Specs

search(
  id(),
  query :: Tune.Spotify.Client.q(),
  search_options :: Tune.Spotify.Client.search_options()
) :: {:ok, Tune.Spotify.Client.search_results()} | {:error, term()}
Link to this callback

seek(id, position_ms)

Specs

seek(id(), position_ms :: Tune.Duration.milliseconds()) ::
  :ok | {:error, term()}
Link to this callback

set_volume(id, volume_percent)

Specs

set_volume(id(), volume_percent :: Tune.Spotify.Schema.Device.volume_percent()) ::
  :ok | {:error, term()}
Link to this callback

setup(id, credentials)

Specs

setup(id(), credentials()) :: :ok | {:error, term()}

Specs

subscribe(id()) :: :ok | {:error, term()}
Link to this callback

subscribers_count(id)

Specs

subscribers_count(id()) :: pos_integer()
Link to this callback

toggle_play(id)

Specs

toggle_play(id()) :: :ok | {:error, term()}
Link to this callback

top_tracks(id, top_tracks_options)

Specs

top_tracks(id(), top_tracks_options :: Tune.Spotify.Client.top_tracks_options()) ::
  {:ok, [Tune.Spotify.Schema.Track.t()]} | {:error, term()}
Link to this callback

transfer_playback(id, device_id)

Specs

transfer_playback(id(), device_id :: Tune.Spotify.Schema.Device.id()) ::
  :ok | {:error, term()}