Class: StreamGrabber::LastFm
- Inherits:
-
Object
- Object
- StreamGrabber::LastFm
- Defined in:
- lib/stream_grabber/last_fm.rb
Instance Method Summary collapse
-
#initialize(user_name, api_key) ⇒ LastFm
constructor
A new instance of LastFm.
- #last_five ⇒ Object
- #message_for(artist, title, url) ⇒ Object
Constructor Details
#initialize(user_name, api_key) ⇒ LastFm
Returns a new instance of LastFm.
6 7 8 9 |
# File 'lib/stream_grabber/last_fm.rb', line 6 def initialize(user_name, api_key) @user_name = user_name @doc ||= Nokogiri::XML(open("http://ws.audioscrobbler.com/2.0/?method=user.getlovedtracks&user=#{user_name}&api_key=#{api_key}")) end |
Instance Method Details
#last_five ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/stream_grabber/last_fm.rb', line 11 def last_five tracks = {} ff = @doc.xpath("//track").first(5) ff.each do |elem| date_loved = elem.>('date').first['uts'].to_i artist_name = elem.css('artist > name').text track_name = elem.>('name').text url = elem.>('url').text tracks[date_loved] = [:lastfm, (artist_name,track_name, url)] end tracks end |
#message_for(artist, title, url) ⇒ Object
24 25 26 |
# File 'lib/stream_grabber/last_fm.rb', line 24 def (artist, title, url) %Q{ <a href="#{url}">#{@user_name} loved the track #{title} by #{artist} on Last.fm</a> } end |