Class: Hearken::SimpleScrobbler
- Inherits:
-
Object
- Object
- Hearken::SimpleScrobbler
- Includes:
- Debug
- Defined in:
- lib/hearken/simple_scrobbler.rb
Constant Summary collapse
- SCROBBLER_URL =
'http://ws.audioscrobbler.com/2.0/'
- SubmissionError =
Class.new(RuntimeError)
- SessionError =
Class.new(RuntimeError)
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#session_key ⇒ Object
readonly
Returns the value of attribute session_key.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #fetch_session_key {|"http://www.last.fm/api/auth/?api_key=#{api_key}&token=#{request_token}"| ... } ⇒ Object
-
#initialize(api_key, secret, user, session_key = nil) ⇒ SimpleScrobbler
constructor
A new instance of SimpleScrobbler.
- #love(artist, title, params = {}) ⇒ Object
-
#now_playing(artist, title, params = {}) ⇒ Object
See www.last.fm/api/show?service=454 for more details.
- #scrobble(artist, title, params = {}) ⇒ Object
- #with_profile_url {|"http://www.last.fm/user/#{user}"| ... } ⇒ Object
Methods included from Debug
Constructor Details
#initialize(api_key, secret, user, session_key = nil) ⇒ SimpleScrobbler
Returns a new instance of SimpleScrobbler.
18 19 20 21 22 23 |
# File 'lib/hearken/simple_scrobbler.rb', line 18 def initialize api_key, secret, user, session_key=nil @api_key = api_key @secret = secret @user = user @session_key = session_key end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
25 26 27 |
# File 'lib/hearken/simple_scrobbler.rb', line 25 def api_key @api_key end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
25 26 27 |
# File 'lib/hearken/simple_scrobbler.rb', line 25 def secret @secret end |
#session_key ⇒ Object (readonly)
Returns the value of attribute session_key.
25 26 27 |
# File 'lib/hearken/simple_scrobbler.rb', line 25 def session_key @session_key end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
25 26 27 |
# File 'lib/hearken/simple_scrobbler.rb', line 25 def user @user end |
Instance Method Details
#fetch_session_key {|"http://www.last.fm/api/auth/?api_key=#{api_key}&token=#{request_token}"| ... } ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/hearken/simple_scrobbler.rb', line 31 def fetch_session_key doc = lfm :get, 'auth.gettoken' request_token = doc.at('token').inner_text yield "http://www.last.fm/api/auth/?api_key=#{api_key}&token=#{request_token}" doc = lfm :get, 'auth.getsession', :token => request_token @session_key = doc.at('key').inner_text @user = doc.at('name').inner_text @session_key end |
#love(artist, title, params = {}) ⇒ Object
56 57 58 |
# File 'lib/hearken/simple_scrobbler.rb', line 56 def love artist, title, params={} lfm_track 'track.love', artist, title, params end |
#now_playing(artist, title, params = {}) ⇒ Object
See www.last.fm/api/show?service=454 for more details
51 52 53 |
# File 'lib/hearken/simple_scrobbler.rb', line 51 def artist, title, params={} lfm_track 'track.updateNowPlaying', artist, title, params end |
#scrobble(artist, title, params = {}) ⇒ Object
46 47 48 |
# File 'lib/hearken/simple_scrobbler.rb', line 46 def scrobble artist, title, params={} lfm_track 'track.scrobble', artist, title, params end |
#with_profile_url {|"http://www.last.fm/user/#{user}"| ... } ⇒ Object
41 42 43 |
# File 'lib/hearken/simple_scrobbler.rb', line 41 def with_profile_url yield "http://www.last.fm/user/#{user}" if user end |