Sha256: d07802b8c3ea7a695a331ab1a230eebd2d4f9c0e191f5345a514772b698c4495

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

# Grooveshark module
module Grooveshark
  # Playlist class
  class Playlist
    attr_reader :id, :user_id
    attr_reader :name, :about, :picture, :username
    attr_reader :songs, :num_songs

    def initialize(client, data = nil, user_id = nil)
      @client = client
      @songs = []

      return if data.nil?
      @id        = data['playlist_id']
      @name      = data['name']
      @about     = data['about']
      @picture   = data['picture']
      @user_id   = data['user_id'] || user_id
      @username  = data['f_name']
      @num_songs = data['num_songs'].to_i
    end

    # Fetch playlist songs
    def load_songs
      @songs = []
      playlist = @client.request('getPlaylistByID', playlistID: @id)
      @songs = playlist['songs'].map! do |s|
        Song.new(s)
      end if playlist.key?('songs')
      @songs
    end

    # Rename playlist
    def rename(name, description)
      @client.request('renamePlaylist', playlistID: @id, playlistName: name)
      @client.request('setPlaylistAbout', playlistID: @id, about: description)
      @name = name
      @about = description
      true
    rescue
      false
    end

    # Delete existing playlist
    def delete
      @client.request('deletePlaylist', playlistID: @id, name: @name)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grooveshark-0.2.14 lib/grooveshark/playlist.rb
grooveshark-0.2.13 lib/grooveshark/playlist.rb