Class: WiMP::Playlist

Inherits:
Base
  • Object
show all
Defined in:
lib/wimp/playlist.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

execute, #execute, session, #session

Constructor Details

#initialize(oplaylist) ⇒ Playlist

Returns a new instance of Playlist.



3
4
5
6
# File 'lib/wimp/playlist.rb', line 3

def initialize(oplaylist)
  @o = oplaylist
  @tracks = (@o.tracks || []).map{|track| Track.new(track)}
end

Class Method Details

.create(title) ⇒ Object

Returns Playlist.

Returns:

  • Playlist



12
13
14
15
16
# File 'lib/wimp/playlist.rb', line 12

def self.create(title)
  execute do |client|
    new(client.addUserPlaylist(title, session))
  end
end

.find(uuid) ⇒ Object

Returns Playlist.

Returns:

  • Playlist



22
23
24
25
26
# File 'lib/wimp/playlist.rb', line 22

def self.find(uuid)
  execute do |client|
    new(client.getUserPlaylistByUuid(uuid, session))
  end
end

Instance Method Details

#add_tracks(tracks, options = {}) ⇒ Object

@options Integer Where

should the new tracks be added?

Returns:

  • Boolean Were the request sucessful?



34
35
36
# File 'lib/wimp/playlist.rb', line 34

def add_tracks(tracks, options = {})
  add_tracks_by_id(tracks.map(&:id), options)
end

#add_tracks_by_id(track_ids, options = {}) ⇒ Object

@options Integer Where

should the new tracks be added?

Returns:

  • Boolean Were the request sucessful?



44
45
46
47
48
49
50
51
52
53
# File 'lib/wimp/playlist.rb', line 44

def add_tracks_by_id(track_ids, options = {})
  execute do |client|
    client.addTracksToUserPlaylist(
      uuid,
      track_ids,
      options.fetch(:start_position, 0),
      session
    )
  end
end

#countObject

Returns Integer.

Returns:

  • Integer



89
90
91
# File 'lib/wimp/playlist.rb', line 89

def count
  @o.count
end

#remove_tracks_by_indices(indices) ⇒ Object

Returns Boolean Were the request successfull?.

Returns:

  • Boolean Were the request successfull?



59
60
61
62
63
# File 'lib/wimp/playlist.rb', line 59

def remove_tracks_by_indices(indices)
  execute do |client|
    client.removeUserPlaylistTracks(uuid, indices, session)
  end
end

#tracksObject



82
83
84
# File 'lib/wimp/playlist.rb', line 82

def tracks
  @tracks
end

#urlObject

Returns String.

Returns:

  • String



68
69
70
# File 'lib/wimp/playlist.rb', line 68

def url
  "http://wimpmusic.se/playlist/#{uuid}"
end

#uuidObject

Returns String.

Returns:

  • String



75
76
77
# File 'lib/wimp/playlist.rb', line 75

def uuid
  @o.uuid
end