Class Scrobbler::SimpleAuth
In: lib/scrobbler/simpleauth.rb
Parent: Object

Methods

handshake!   new  

Attributes

client_id  [RW]  you should read last.fm/api/submissions#handshake
client_ver  [RW]  you should read last.fm/api/submissions#handshake
now_playing_url  [R] 
password  [RW]  you should read last.fm/api/submissions#handshake
session_id  [R] 
status  [R] 
submission_url  [R] 
user  [RW]  you should read last.fm/api/submissions#handshake

Public Class methods

[Source]

    # File lib/scrobbler/simpleauth.rb, line 17
17:     def initialize(args = {})
18:       @user = args[:user] # last.fm username
19:       @password = args[:password] # last.fm password
20:       @client_id = 'rbs' # Client ID assigned by last.fm; Don't change this!
21:       @client_ver = Scrobbler::Version
22: 
23:       raise ArgumentError, 'Missing required argument' if @user.blank? || @password.blank?
24: 
25:       @connection = REST::Connection.new(AUTH_URL)
26:     end

Public Instance methods

[Source]

    # File lib/scrobbler/simpleauth.rb, line 28
28:     def handshake!
29:       password_hash = Digest::MD5.hexdigest(@password)
30:       timestamp = Time.now.to_i.to_s
31:       token = Digest::MD5.hexdigest(password_hash + timestamp)
32: 
33:       query = { :hs => 'true',
34:                 :p => AUTH_VER,
35:                 :c => @client_id,
36:                 :v => @client_ver,
37:                 :u => @user,
38:                 :t => timestamp,
39:                 :a => token }
40:       result = @connection.get('/', query)
41: 
42:       @status = result.split(/\n/)[0]
43:       case @status 
44:       when /OK/
45:         @session_id, @now_playing_url, @submission_url = result.split(/\n/)[1,3]
46:       when /BANNED/
47:         raise BannedError # something is wrong with the gem, check for an update
48:       when /BADAUTH/
49:         raise BadAuthError # invalid user/password
50:       when /FAILED/
51:         raise RequestFailedError, @status
52:       when /BADTIME/
53:         raise BadTimeError # system time is way off
54:       else
55:         raise RequestFailedError
56:       end  
57:     end

[Validate]