Class: Scrobbler::Authentication
- Inherits:
-
Base
- Object
- Base
- Scrobbler::Authentication
show all
- Defined in:
- lib/scrobbler/authentication.rb
Instance Method Summary
(collapse)
Methods inherited from Base
add_cache, api_key=, #call, #call_pageable, fetch_http, get, load_from_cache, #populate_data, post_request, #request, request, sanitize, save_to_cache, secret=, validate_response_document
Constructor Details
A new instance of Authentication
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/scrobbler/authentication.rb', line 7
def initialize(data = {})
populate_data(data)
super()
@digest = Digest::MD5.new
if @username.nil? || @username.empty?
raise ArgumentError, 'Username is required'
end
end
|
Instance Method Details
- (Object) auth_token(password)
19
20
21
|
# File 'lib/scrobbler/authentication.rb', line 19
def auth_token(password)
@digest.hexdigest(@username + @digest.hexdigest(password))
end
|
- (Object) desktop_session_url(tokenStr)
59
60
61
|
# File 'lib/scrobbler/authentication.rb', line 59
def desktop_session_url(tokenStr)
webservice_session_url + '&token=' + tokenStr
end
|
- (Object) load_session_out_of_session_request(xml)
33
34
35
36
37
38
39
|
# File 'lib/scrobbler/authentication.rb', line 33
def load_session_out_of_session_request(xml)
xml.root.children.each do |child|
next unless child.name == 'session'
return Session.new(:xml => child)
end
end
|
- (Object) mobile_session(password)
23
24
25
26
|
# File 'lib/scrobbler/authentication.rb', line 23
def mobile_session(password)
xml = Base.request('auth.getMobileSession', {:username => @username, :signed => true, :authToken => auth_token(password)})
load_session_out_of_session_request(xml)
end
|
- (Object) session(tokenStr)
28
29
30
31
|
# File 'lib/scrobbler/authentication.rb', line 28
def session(tokenStr)
xml = Base.request('auth.getSession', {:signed => true, :token => tokenStr})
load_session_out_of_session_request(xml)
end
|
- (Object) token
41
42
43
44
45
46
47
48
|
# File 'lib/scrobbler/authentication.rb', line 41
def token
xml = Base.request('auth.getToken', {:signed => true})
xml.root.children.each do |child|
next unless child.name == 'token'
return child.content
end
end
|
- (Object) webservice_session_url(callback = nil)
50
51
52
53
54
55
56
57
|
# File 'lib/scrobbler/authentication.rb', line 50
def webservice_session_url(callback=nil)
if not callback.nil? then
cb = "&cb=" + CGI::escape(callback)
else
cb = ''
end
'http://www.last.fm/api/auth/?api_key=' + @@api_key + cb
end
|