Class: Hearken::SimpleScrobbler

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Debug

#debug, #pause

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_keyObject (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

#secretObject (readonly)

Returns the value of attribute secret.



25
26
27
# File 'lib/hearken/simple_scrobbler.rb', line 25

def secret
  @secret
end

#session_keyObject (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

#userObject (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

Yields:

  • ("http://www.last.fm/api/auth/?api_key=#{api_key}&token=#{request_token}")


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 now_playing 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

Yields:



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