Class: Rockstar::SimpleAuth
- Inherits:
-
Object
- Object
- Rockstar::SimpleAuth
- Defined in:
- lib/rockstar/simpleauth.rb
Overview
This class is deprecated. Please use TokenAuth instead.
Instance Attribute Summary collapse
-
#client_id ⇒ Object
you should read last.fm/api/submissions#handshake.
-
#client_ver ⇒ Object
you should read last.fm/api/submissions#handshake.
-
#now_playing_url ⇒ Object
readonly
Returns the value of attribute now_playing_url.
-
#password ⇒ Object
you should read last.fm/api/submissions#handshake.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#submission_url ⇒ Object
readonly
Returns the value of attribute submission_url.
-
#user ⇒ Object
you should read last.fm/api/submissions#handshake.
Instance Method Summary collapse
- #handshake! ⇒ Object
-
#initialize(args = {}) ⇒ SimpleAuth
constructor
A new instance of SimpleAuth.
Constructor Details
#initialize(args = {}) ⇒ SimpleAuth
Returns a new instance of SimpleAuth.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rockstar/simpleauth.rb', line 18 def initialize(args = {}) warn "[DEPRECATION] This class is deprecated. Please use TokenAuth instead!" @user = args[:user] # last.fm username @password = args[:password] # last.fm password @client_id = 'rck' # Client ID assigned by last.fm; Don't change this! @client_ver = Rockstar::Version raise ArgumentError, 'Missing required argument' if @user.blank? || @password.blank? @connection = REST::Connection.new(AUTH_URL) end |
Instance Attribute Details
#client_id ⇒ Object
you should read last.fm/api/submissions#handshake
15 16 17 |
# File 'lib/rockstar/simpleauth.rb', line 15 def client_id @client_id end |
#client_ver ⇒ Object
you should read last.fm/api/submissions#handshake
15 16 17 |
# File 'lib/rockstar/simpleauth.rb', line 15 def client_ver @client_ver end |
#now_playing_url ⇒ Object (readonly)
Returns the value of attribute now_playing_url.
16 17 18 |
# File 'lib/rockstar/simpleauth.rb', line 16 def @now_playing_url end |
#password ⇒ Object
you should read last.fm/api/submissions#handshake
15 16 17 |
# File 'lib/rockstar/simpleauth.rb', line 15 def password @password end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
16 17 18 |
# File 'lib/rockstar/simpleauth.rb', line 16 def session_id @session_id end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
16 17 18 |
# File 'lib/rockstar/simpleauth.rb', line 16 def status @status end |
#submission_url ⇒ Object (readonly)
Returns the value of attribute submission_url.
16 17 18 |
# File 'lib/rockstar/simpleauth.rb', line 16 def submission_url @submission_url end |
#user ⇒ Object
you should read last.fm/api/submissions#handshake
15 16 17 |
# File 'lib/rockstar/simpleauth.rb', line 15 def user @user end |
Instance Method Details
#handshake! ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rockstar/simpleauth.rb', line 31 def handshake! password_hash = Digest::MD5.hexdigest(@password) = Time.now.to_i.to_s token = Digest::MD5.hexdigest(password_hash + ) query = { :hs => 'true', :p => AUTH_VER, :c => @client_id, :v => @client_ver, :u => @user, :t => , :a => token } result = @connection.get('/', false, query) @status = result.split(/\n/)[0] case @status when /OK/ @session_id, @now_playing_url, @submission_url = result.split(/\n/)[1,3] when /BANNED/ raise BannedError # something is wrong with the gem, check for an update when /BADAUTH/ raise BadAuthError # invalid user/password when /FAILED/ raise RequestFailedError, @status when /BADTIME/ raise BadTimeError # system time is way off else raise RequestFailedError end end |