Class: Turntabler::PlaylistDirectory
- Inherits:
-
Object
- Object
- Turntabler::PlaylistDirectory
- Includes:
- Assertions
- Defined in:
- lib/turntabler/playlist_directory.rb
Overview
Provides a set of helper methods for interacting with a user’s playlists.
Instance Method Summary collapse
-
#all ⇒ Array<Turntabler::Playlist>
Gets the list of playlists created.
-
#build(attrs) ⇒ Turntabler::Playlist
private
Gets the playlist represented by the given attributes.
-
#create(id) ⇒ Turntabler::Playlist
Creates a new playlist with the given id.
-
#initialize(client) ⇒ PlaylistDirectory
constructor
private
A new instance of PlaylistDirectory.
Methods included from Assertions
#assert_valid_keys, #assert_valid_values
Constructor Details
#initialize(client) ⇒ PlaylistDirectory
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of PlaylistDirectory.
9 10 11 12 |
# File 'lib/turntabler/playlist_directory.rb', line 9 def initialize(client) @client = client @playlists = {} end |
Instance Method Details
#all ⇒ Array<Turntabler::Playlist>
Gets the list of playlists created.
34 35 36 37 |
# File 'lib/turntabler/playlist_directory.rb', line 34 def all data = api('playlist.list_all') data['list'].map {|attrs| build(attrs)} end |
#build(attrs) ⇒ Turntabler::Playlist
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Gets the playlist represented by the given attributes.
If the playlist hasn’t been previously accessed, then a new Playlist instance will get created.
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/turntabler/playlist_directory.rb', line 47 def build(attrs) playlist = Playlist.new(client, attrs) # Update existing in cache or cache a new playlist if existing = @playlists[playlist.id] playlist = existing playlist.attributes = attrs else @playlists[playlist.id] = playlist end playlist end |
#create(id) ⇒ Turntabler::Playlist
This will automatically enter the playlist when it is created
Creates a new playlist with the given id. This should only be used if the playlist doesn’t already exist.
23 24 25 26 |
# File 'lib/turntabler/playlist_directory.rb', line 23 def create(id) api('playlist.create', :playlist_name => id) build(:_id => id) end |