Class: Tinyscrobbler::Client
- Inherits:
-
Object
- Object
- Tinyscrobbler::Client
- Defined in:
- lib/tinyscrobbler.rb
Overview
This is the lastfm submission api client class. It contains necessary methods for full interaction with LastFM submissions API.
Constant Summary collapse
- CLIENT_ID =
'tny'
- CLIENT_VERSION =
'0.3.3'
- HANDSHAKE_BASE_URL =
"http://post.audioscrobbler.com/?hs=true&p=1.2.1&c=#{CLIENT_ID}&v=#{CLIENT_VERSION}"
Instance Method Summary collapse
-
#initialize(username, password) ⇒ Client
constructor
Starts handshake and initializes instance attributes.
-
#now_playing(track) ⇒ Object
Sends a now playing track.
-
#played(track) ⇒ Object
Adds a new track to the queue and submits the queue.
Constructor Details
#initialize(username, password) ⇒ Client
Starts handshake and initializes instance attributes
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tinyscrobbler.rb', line 37 def initialize(username, password) @username = username @password = password @queue = [] response = handshake() raise BadFormatedResponseError, 'Bad formated server response' if response.length != 4 @session_id = response[1] @now_playing_url = response[2] @submission_url = response[3] end |
Instance Method Details
#now_playing(track) ⇒ Object
Sends a now playing track. track is a hash containing the following keys => values:
-
artistname => the name of the artist
-
track => the title of the track (song)
-
album => the album name
-
secs => the length of the track (seconds)
-
tracknumber => the number of the track in album
-
mbtrackid => the track’s musicbrainz id
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/tinyscrobbler.rb', line 77 def (track) params = "s=#{@session_id}" params << "&a=#{URI.escape(track['artistname'].to_s)}" params << "&t=#{URI.escape(track['track'].to_s)}" params << "&b=#{URI.escape(track['album'].to_s)}" params << "&l=#{URI.escape(track['secs'].to_s)}" params << "&n=#{URI.escape(track['tracknumber'].to_s)}" params << "&m=#{URI.escape(track['mbtrackid'].to_s)}" send_submission(@now_playing_url, params) end |
#played(track) ⇒ Object
Adds a new track to the queue and submits the queue.
-
artistname => the name of the artist
-
track => the title of the track (song)
-
album => the album name
-
secs => the length of the track (seconds)
-
tracknumber => the number of the track in album
-
mbtrackid => the track’s musicbrainz id
-
time => the time the track started playing
-
source => always ‘P’
-
rating => the track rating: L, B or S (love, ban, skip)
63 64 65 66 |
# File 'lib/tinyscrobbler.rb', line 63 def played(track) @queue << track submit_queue end |