Class: Pandora::User

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/pandora/user.rb

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

Request::BASE_FEED

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Request

#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.strip
end

Instance Attribute Details

#userObject

Returns the value of attribute user.



12
13
14
# File 'lib/pandora/user.rb', line 12

def user
  @user
end

Instance Method Details

#bookmarked_artistsObject

== 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,
                 :link        => node.xpath('link').text,
                 :description => node.xpath('description').text,
                 :date        => node.xpath('pubDate').text,
                 :artist      => node.xpath('mm:Artist/dc:title').text,
                 :station     => node.xpath('pandora:stationLink').text }
  end
  artists
end

#bookmarked_songsObject

== 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,
               :link        => node.xpath('link').text,
               :description => node.xpath('description').text,
               :date        => node.xpath('pubDate').text,
               :track       => node.xpath('mm:Track/dc:title').text,
               :artist      => node.xpath('mm:Artist/dc:title').text,
               :album       => node.xpath('mm:Album/dc:title').text,
               :artwork     => node.xpath('pandora:albumArtUrl').text,
               :station     => node.xpath('pandora:stationLink').text }
  end
  songs
end

#now_playingObject

== Returns the Station Now Playing

now_playing = user.now_playing

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_song:: Name of song used to create station songSeed_artist:: Name of the artist for the song used to create the station composerSeed:: Name of the composer used to create the station artistSeed:: Name of the artist used to create the station



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/pandora/user.rb', line 127

def now_playing
  doc = request(@user, "nowplaying")
  station = []
  doc.xpath('//rss/channel/item').each do |node|
    station << { :title       => node.xpath('title').text,
                 :link        => node.xpath('link').text,
                 :description => node.xpath('description').text,
                 :date        => node.xpath('pubDate').text,
                 :artwork     => node.xpath('pandora:stationAlbumArtImageUrl').text,
                 :songSeed_song   => node.xpath('pandora:seeds/pandora:songSeed/pandora:song').text,
                 :songSeed_artist => node.xpath('pandora:seeds/pandora:songSeed/pandora:artist').text,
                 :composerSeed    => node.xpath('pandora:seeds/pandora:composerSeed/pandora:composer').text,
                 :artistSeed      => node.xpath('pandora:seeds/pandora:artistSeed/pandora:artist') }
  end
  station
end

#recent_activityObject

== 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,
               :link        => node.xpath('link').text,
               :description => node.xpath('description').text,
               :date        => node.xpath('pubDate').text,
               :track       => node.xpath('mm:Track/dc:title').text,
               :artist      => node.xpath('mm:Artist/dc:title').text,
               :album       => node.xpath('mm:Album/dc:title').text,
               :artwork     => node.xpath('pandora:albumArtUrl').text,
               :station     => node.xpath('pandora:stationLink').text }
  end
  items
end

#stationsObject

== 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_song:: Name of song used to create station songSeed_artist:: Name of the artist for the song used to create the station composerSeed:: Name of the composer used to create the station artistSeed:: Name of the artist used to create the station



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/pandora/user.rb', line 94

def stations
  doc = request(@user, "stations")
  stations = []
  doc.xpath('//rss/channel/item').each do |node|
    stations << { :title       => node.xpath('title').text,
                  :link        => node.xpath('link').text,
                  :description => node.xpath('description').text,
                  :date        => node.xpath('pubDate').text,
                  :artwork     => node.xpath('pandora:stationAlbumArtImageUrl').text,
                  :songSeed_song   => node.xpath('pandora:seeds/pandora:songSeed/pandora:song').text,
                  :songSeed_artist => node.xpath('pandora:seeds/pandora:songSeed/pandora:artist').text,
                  :composerSeed    => node.xpath('pandora:seeds/pandora:composerSeed/pandora:composer').text,
                  :artistSeed      => node.xpath('pandora:seeds/pandora:artistSeed/pandora:artist') }
  end
  stations
end