Class: Rockstar::Playing
- Inherits:
-
Object
- Object
- Rockstar::Playing
- Defined in:
- lib/rockstar/playing.rb
Instance Attribute Summary collapse
-
#album ⇒ Object
you should read last.fm/api/submissions#np first!.
-
#artist ⇒ Object
you should read last.fm/api/submissions#np first!.
-
#length ⇒ Object
you should read last.fm/api/submissions#np first!.
-
#mb_track_id ⇒ Object
you should read last.fm/api/submissions#np first!.
-
#now_playing_url ⇒ Object
you should read last.fm/api/submissions#np first!.
-
#session_id ⇒ Object
you should read last.fm/api/submissions#np first!.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#track ⇒ Object
you should read last.fm/api/submissions#np first!.
-
#track_number ⇒ Object
you should read last.fm/api/submissions#np first!.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Playing
constructor
A new instance of Playing.
- #submit! ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Playing
Returns a new instance of Playing.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rockstar/playing.rb', line 9 def initialize(args = {}) @session_id = args[:session_id] # from Rockstar::SimpleAuth @now_playing_url = args[:now_playing_url] # from Rockstar::SimpleAuth (can change) @artist = args[:artist] # track artist @track = args[:track] # track name @album = args[:album] || '' # track album (optional) @length = args[:length] || '' # track length in seconds (optional) @track_number = args[:track_number] || '' # track number (optional) @mb_track_id = args[:mb_track_id] || '' # MusicBrainz track ID (optional) if [@session_id, @now_playing_url, @artist, @track].any?(&:blank?) raise ArgumentError, 'Missing required argument' elsif !@length.to_s.empty? && @length.to_i <= 30 # see last.fm/api raise ArgumentError, 'Length must be greater than 30 seconds' end @connection = REST::Connection.new(@now_playing_url) end |
Instance Attribute Details
#album ⇒ Object
you should read last.fm/api/submissions#np first!
5 6 7 |
# File 'lib/rockstar/playing.rb', line 5 def album @album end |
#artist ⇒ Object
you should read last.fm/api/submissions#np first!
5 6 7 |
# File 'lib/rockstar/playing.rb', line 5 def artist @artist end |
#length ⇒ Object
you should read last.fm/api/submissions#np first!
5 6 7 |
# File 'lib/rockstar/playing.rb', line 5 def length @length end |
#mb_track_id ⇒ Object
you should read last.fm/api/submissions#np first!
5 6 7 |
# File 'lib/rockstar/playing.rb', line 5 def mb_track_id @mb_track_id end |
#now_playing_url ⇒ Object
you should read last.fm/api/submissions#np first!
5 6 7 |
# File 'lib/rockstar/playing.rb', line 5 def @now_playing_url end |
#session_id ⇒ Object
you should read last.fm/api/submissions#np first!
5 6 7 |
# File 'lib/rockstar/playing.rb', line 5 def session_id @session_id end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/rockstar/playing.rb', line 7 def status @status end |
#track ⇒ Object
you should read last.fm/api/submissions#np first!
5 6 7 |
# File 'lib/rockstar/playing.rb', line 5 def track @track end |
#track_number ⇒ Object
you should read last.fm/api/submissions#np first!
5 6 7 |
# File 'lib/rockstar/playing.rb', line 5 def track_number @track_number end |
Instance Method Details
#submit! ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rockstar/playing.rb', line 28 def submit! warn "[DEPRECATION] the `playing` class is deprecated. Please use track.updateNowPlaying" query = { :s => @session_id, :a => @artist, :t => @track, :b => @album, :l => @length, :n => @track_number, :m => @mb_track_id } @status = @connection.post('', false, query) case @status when /OK/ when /BADSESSION/ raise BadSessionError # rerun Rockstar::SimpleAuth#handshake! else raise RequestFailedError end end |