Class: Pandora::User
Overview
User class to get data for a particular user.
Initiating User
user = Pandora::User.new("username") this 'user' defined will be used in examples to invoke methods below. After the methods are invoked the results can be iterated over for each song, artist, staiton, item.
Constant Summary
Constants included from Request
Instance Attribute Summary collapse
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#bookmarked_artists ⇒ Object
Returns the Bookmarked Artists.
-
#bookmarked_songs ⇒ Object
Returns the Bookmarked Songs.
-
#initialize(user) ⇒ User
constructor
Create a new user and make sure no whitespace, since it will be parsed as url in the request.
-
#now_playing ⇒ Object
Returns the Station Now Playing.
-
#recent_activity ⇒ Object
Returns the Recent Activity.
-
#stations ⇒ Object
Returns the Stations created.
Methods included from Request
Constructor Details
#initialize(user) ⇒ User
Create a new user and make sure no whitespace, since it will be parsed as url in the request.
15 16 17 |
# File 'lib/pandora/user.rb', line 15 def initialize(user) @user = user.downcase.strip end |
Instance Attribute Details
#user ⇒ Object
Returns the value of attribute user.
12 13 14 |
# File 'lib/pandora/user.rb', line 12 def user @user end |
Instance Method Details
#bookmarked_artists ⇒ Object
Returns the Bookmarked Artists
bookmarked_artists = user.bookmarked_artists
will return the parameters below:
Parameters:
- title
Name of the artist
- link
Link to the artist
- description
Description of the artist
- date
Date the artist was bookmarked
- station
Station link to the station
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pandora/user.rb', line 64 def bookmarked_artists doc = request(@user, "favoriteartists") artists = [] doc.xpath('//rss/channel/item').each do |node| artists << { :title => node.xpath('title').text.strip, :link => node.xpath('link').text.strip, :description => node.xpath('description').text.strip, :date => node.xpath('pubDate').text.strip, :artist => node.xpath('mm:Artist/dc:title').text.strip, :station => node.xpath('pandora:stationLink').text.strip } end artists end |
#bookmarked_songs ⇒ Object
Returns the Bookmarked Songs
bookmarked_songs = user.bookmarked_songs
will return the parameters below:
Parameters:
- title
Name of the song
- link
Link to the song
- description
Description of the song and the artist
- date
Date the song was bookmarked
- track
Song name
- artist
Artist name
- album
Album name
- artwork
Artwork of the album
- station
Station link to the song
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pandora/user.rb', line 35 def bookmarked_songs doc = request(@user, "favorites") songs = [] doc.xpath('//rss/channel/item').each do |node| songs << { :title => node.xpath('title').text.strip, :link => node.xpath('link').text.strip, :description => node.xpath('description').text.strip, :date => node.xpath('pubDate').text.strip, :track => node.xpath('mm:Track/dc:title').text.strip, :artist => node.xpath('mm:Artist/dc:title').text.strip, :album => node.xpath('mm:Album/dc:title').text.strip, :artwork => node.xpath('pandora:albumArtUrl').text.strip, :station => node.xpath('pandora:stationLink').text.strip } end songs end |
#now_playing ⇒ Object
Returns the Station Now Playing
= user.
will return the parameters below:
Parameters:
- title
Title of the station
- link
Link to the station
- description
Description of the station
- date
Date the station was last played
- artwork
Artwork of the station
- songSeed
Array of hashes => "..", :artist => ".." representing songs used to create the station
- composerSeed
Array of names of the composers used to create the station
- artistSeed
Array of names of the artists used to create the station
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/pandora/user.rb', line 126 def doc = request(@user, "nowplaying") station = [] doc.xpath('//rss/channel/item').each do |node| seeds = parse_seeds(node) station << { :title => node.xpath('title').text.strip, :link => node.xpath('link').text.strip, :description => node.xpath('description').text.strip, :date => node.xpath('pubDate').text.strip, :artwork => node.xpath('pandora:stationAlbumArtImageUrl').text.strip, :songSeed => seeds[:song], :composerSeed => seeds[:composer], :artistSeed => seeds[:artist]} end station end |
#recent_activity ⇒ Object
Returns the Recent Activity
recent_activity = user.recent_activity
will return the parameters below:
Parameters:
- title
Title of the item(song or artist)
- link
Link to the item(song or artist)
- description
Description of the song and the artist
- date
Date the song was modified
- track
Song name
- artist
Artist name
- album
Album name
- artwork
Artwork of the item
- station
Station link to the item
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/pandora/user.rb', line 160 def recent_activity doc = request(@user, "recentactivity") items = [] doc.xpath('//rss/channel/item').each do |node| items << { :title => node.xpath('title').text.strip, :link => node.xpath('link').text.strip, :description => node.xpath('description').text.strip, :date => node.xpath('pubDate').text.strip, :track => node.xpath('mm:Track/dc:title').text.strip, :artist => node.xpath('mm:Artist/dc:title').text.strip, :album => node.xpath('mm:Album/dc:title').text.strip, :artwork => node.xpath('pandora:albumArtUrl').text.strip, :station => node.xpath('pandora:stationLink').text.strip} end items end |
#stations ⇒ Object
Returns the Stations created
stations = user.stations
will return the parameters below:
Parameters:
- title
Title of the station
- link
Link to the station
- description
Description of the station
- date
Date the station was created
- artwork
Artwork of the station
- songSeed
Array of hashes => "..", :artist => ".." representing songs used to create the station
- composerSeed
Array of names of the composers used to create the station
- artistSeed
Array of names of the artists used to create the station
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/pandora/user.rb', line 93 def stations doc = request(@user, "stations") stations = [] doc.xpath('//rss/channel/item').each do |node| seeds = parse_seeds(node) stations << { :title => node.xpath('title').text.strip, :link => node.xpath('link').text.strip, :description => node.xpath('description').text.strip, :date => node.xpath('pubDate').text.strip, :artwork => node.xpath('pandora:stationAlbumArtImageUrl').text.strip, :songSeed => seeds[:song], :composerSeed => seeds[:composer], :artistSeed => seeds[:artist]} end stations end |