Sha256: 32f231c9913233439800566e560f28040c38d34e21d51d01fef1daef92ce777e

Contents?: true

Size: 1.15 KB

Versions: 10

Compression:

Stored size: 1.15 KB

Contents

module Grooveshark
  class Playlist
    attr_reader :id, :user_id
    attr_reader :name, :about, :picture, :username
    attr_reader :songs
    
    def initialize(client, data=nil, user_id=nil)
      @client = client
      @songs = []
    
      if data
        @id       = data['playlist_id']
        @name     = data['name']
        @about    = data['about']
        @picture  = data['picture']
        @user_id  = data['user_id'] || user_id
        @username = data['user_name']
      end
    end

    # Fetch playlist songs
    def load_songs
      @songs = @client.request('playlistGetSongs', :playlistID => @id)['songs']
      @songs.map! { |s| Song.new(s) }
    end
    
    # Rename playlist
    def rename(name, description)
      begin
        @client.request('renamePlaylist', :playlistID => @id, :playlistName => name)
        @client.request('setPlaylistAbout', :playlistID => @id, :about => description)
        @name = name ; @about = description
        return true
      rescue
        return false
      end
    end
    
    # Delete existing playlist
    def delete
      @client.request('deletePlaylist', {:playlistID => @id, :name => @name})
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
grooveshark-0.2.8.1 lib/grooveshark/playlist.rb
grooveshark-0.2.8 lib/grooveshark/playlist.rb
grooveshark-0.2.7 lib/grooveshark/playlist.rb
grooveshark-0.2.6 lib/grooveshark/playlist.rb
grooveshark-0.2.5 lib/grooveshark/playlist.rb
grooveshark-0.2.4 lib/grooveshark/playlist.rb
grooveshark-0.2.3 lib/grooveshark/playlist.rb
grooveshark-0.2.2 lib/grooveshark/playlist.rb
grooveshark-0.2.1 lib/grooveshark/playlist.rb
grooveshark-0.2.0 lib/grooveshark/playlist.rb