Class Scrobbler::Playing
In: lib/scrobbler/playing.rb
Parent: Object

Methods

new   submit!  

Attributes

album  [RW]  you should read last.fm/api/submissions#np first!
artist  [RW]  you should read last.fm/api/submissions#np first!
length  [RW]  you should read last.fm/api/submissions#np first!
mb_track_id  [RW]  you should read last.fm/api/submissions#np first!
now_playing_url  [RW]  you should read last.fm/api/submissions#np first!
session_id  [RW]  you should read last.fm/api/submissions#np first!
status  [R] 
track  [RW]  you should read last.fm/api/submissions#np first!
track_number  [RW]  you should read last.fm/api/submissions#np first!

Public Class methods

[Source]

    # File lib/scrobbler/playing.rb, line 9
 9:     def initialize(args = {})
10:       @session_id = args[:session_id] # from Scrobbler::SimpleAuth
11:       @now_playing_url = args[:now_playing_url] # from Scrobbler::SimpleAuth (can change)
12:       @artist = args[:artist] # track artist
13:       @track = args[:track] # track name
14:       @album = args[:album] || '' # track album (optional)
15:       @length = args[:length] || '' # track length in seconds (optional)
16:       @track_number = args[:track_number] || '' # track number (optional)
17:       @mb_track_id = args[:mb_track_id] || '' # MusicBrainz track ID (optional)
18: 
19:       if [@session_id, @now_playing_url, @artist, @track].any?(&:empty?)
20:         raise ArgumentError, 'Missing required argument'
21:       elsif !@length.to_s.empty? && @length.to_i <= 30 # see last.fm/api
22:         raise ArgumentError, 'Length must be greater than 30 seconds'
23:       end 
24: 
25:       @connection = REST::Connection.new(@now_playing_url)
26:     end

Public Instance methods

[Source]

    # File lib/scrobbler/playing.rb, line 28
28:     def submit!
29:       query = { :s => @session_id,
30:                 :a => @artist,
31:                 :t => @track,
32:                 :b => @album,
33:                 :l => @length,
34:                 :n => @track_number,
35:                 :m => @mb_track_id }
36: 
37:       @status = @connection.post('', query)
38: 
39:       case @status
40:       when /OK/
41: 
42:       when /BADSESSION/
43:         raise BadSessionError # rerun Scrobbler::SimpleAuth#handshake!
44:       else
45:         raise RequestFailedError
46:       end
47:     end

[Validate]