Class: Rockstar::Scrobble
- Inherits:
-
Object
- Object
- Rockstar::Scrobble
- Defined in:
- lib/rockstar/scrobble.rb
Instance Attribute Summary collapse
-
#album ⇒ Object
you need to read last.fm/api/submissions#subs first!.
-
#artist ⇒ Object
you need to read last.fm/api/submissions#subs first!.
-
#length ⇒ Object
you need to read last.fm/api/submissions#subs first!.
-
#mb_track_id ⇒ Object
you need to read last.fm/api/submissions#subs first!.
-
#rating ⇒ Object
you need to read last.fm/api/submissions#subs first!.
-
#session_id ⇒ Object
you need to read last.fm/api/submissions#subs first!.
-
#source ⇒ Object
you need to read last.fm/api/submissions#subs first!.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#submission_url ⇒ Object
you need to read last.fm/api/submissions#subs first!.
-
#time ⇒ Object
you need to read last.fm/api/submissions#subs first!.
-
#track ⇒ Object
you need to read last.fm/api/submissions#subs first!.
-
#track_number ⇒ Object
you need to read last.fm/api/submissions#subs first!.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Scrobble
constructor
A new instance of Scrobble.
- #submit! ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Scrobble
Returns a new instance of Scrobble.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rockstar/scrobble.rb', line 13 def initialize(args = {}) @session_id = args[:session_id] # from Rockstar::TokenAuth @submission_url = args[:submission_url] # from Rockstar::TokenAuth (can change) @artist = args[:artist] # track artist @track = args[:track] # track name @time = args[:time] # a Time object set to the time the track started playing @source = args[:source] || 'P' # track source, see last.fm/api/submissions#subs @length = args[:length].to_s || '' # track length in seconds @album = args[:album] || '' # track album name (optional) @track_number = args[:track_number] || '' # track number (optional) @mb_track_id = args[:mb_track_id] || '' # MusicBrainz track ID (optional) @rating = args[:rating] || '' # Rating for clip (optional L=Love, B=Ban (if source=L), S=Skip (if source=L)) if [@session_id, @submission_url, @artist, @track].any?(&:blank?) raise ArgumentError, 'Missing required argument' elsif @time.class.to_s != 'Time' raise ArgumentError, ":time must be a Time object" elsif !['P','R','E','U'].include?(@source) # see last.fm/api/submissions#subs raise ArgumentError, "Invalid source" elsif @source == 'P' && @length.blank? # length is not optional if source is P raise ArgumentError, 'Length must be set' elsif !@length.blank? && @length.to_i <= 30 # see last.fm/api/submissions#subs raise ArgumentError, 'Length must be greater than 30 seconds' end @connection = REST::Connection.new(@submission_url) end |
Instance Attribute Details
#album ⇒ Object
you need to read last.fm/api/submissions#subs first!
9 10 11 |
# File 'lib/rockstar/scrobble.rb', line 9 def album @album end |
#artist ⇒ Object
you need to read last.fm/api/submissions#subs first!
9 10 11 |
# File 'lib/rockstar/scrobble.rb', line 9 def artist @artist end |
#length ⇒ Object
you need to read last.fm/api/submissions#subs first!
9 10 11 |
# File 'lib/rockstar/scrobble.rb', line 9 def length @length end |
#mb_track_id ⇒ Object
you need to read last.fm/api/submissions#subs first!
9 10 11 |
# File 'lib/rockstar/scrobble.rb', line 9 def mb_track_id @mb_track_id end |
#rating ⇒ Object
you need to read last.fm/api/submissions#subs first!
9 10 11 |
# File 'lib/rockstar/scrobble.rb', line 9 def @rating end |
#session_id ⇒ Object
you need to read last.fm/api/submissions#subs first!
9 10 11 |
# File 'lib/rockstar/scrobble.rb', line 9 def session_id @session_id end |
#source ⇒ Object
you need to read last.fm/api/submissions#subs first!
9 10 11 |
# File 'lib/rockstar/scrobble.rb', line 9 def source @source end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
11 12 13 |
# File 'lib/rockstar/scrobble.rb', line 11 def status @status end |
#submission_url ⇒ Object
you need to read last.fm/api/submissions#subs first!
9 10 11 |
# File 'lib/rockstar/scrobble.rb', line 9 def submission_url @submission_url end |
#time ⇒ Object
you need to read last.fm/api/submissions#subs first!
9 10 11 |
# File 'lib/rockstar/scrobble.rb', line 9 def time @time end |
#track ⇒ Object
you need to read last.fm/api/submissions#subs first!
9 10 11 |
# File 'lib/rockstar/scrobble.rb', line 9 def track @track end |
#track_number ⇒ Object
you need to read last.fm/api/submissions#subs first!
9 10 11 |
# File 'lib/rockstar/scrobble.rb', line 9 def track_number @track_number end |
Instance Method Details
#submit! ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rockstar/scrobble.rb', line 41 def submit! warn "[DEPRECATION] the `scrobble` class is deprecated. Please use track.scrobble" query = { :s => @session_id, 'a[0]' => @artist, 't[0]' => @track, 'i[0]' => @time.utc.to_i, 'o[0]' => @source, 'r[0]' => @rating, 'l[0]' => @length, 'b[0]' => @album, 'n[0]' => @track_number, 'm[0]' => @mb_track_id } @status = @connection.post('', false, query) case @status when /OK/ when /BADSESSION/ raise BadSessionError # rerun Rockstar::SimpleAuth#handshake! when /FAILED/ raise RequestFailedError, @status else raise RequestFailedError end end |