Class: Scrobbler::Auth

Inherits:
Base
  • Object
show all
Defined in:
lib/scrobbler/auth.rb

Overview

TODO:

everything

Instance Method Summary collapse

Methods inherited from Base

api_key=, connection, get, maybe_streamable_attribute, maybe_streamable_node, post_request, request, sanitize, secret=

Constructor Details

#initialize(username) ⇒ Auth

Returns a new instance of Auth.



5
6
7
8
# File 'lib/scrobbler/auth.rb', line 5

def initialize(username)
  super()
  @username = username
end

Instance Method Details

#session(token) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/scrobbler/auth.rb', line 10

def session(token)
  doc = Base.request('auth.getsession', :signed => true, :token => token)
  asession = {}
  doc.root.children.each do |child1|
    next unless child1.name == 'session'
    child1.children.each do |child2|
      if child2.name == 'name'
        asession[:name] = child2.content
      elsif child2.name == 'key'
        asession[:key] = child2.content
      elsif child2.name == 'subscriber'
        asession[:subscriber] = true if child2.content == '1'
        asession[:subscriber] = false unless child2.content == '1'
      end   
    end
  end
  Scrobbler::Session.new(asession)
end

#tokenObject



29
30
31
32
33
34
35
36
37
# File 'lib/scrobbler/auth.rb', line 29

def token
  doc = Base.request('auth.gettoken', :signed => true)
  stoken = ''
  doc.root.children.each do |child|
    next unless child.name == 'token'
    stoken = child.content
  end
  stoken
end

#url(options = {}) ⇒ Object



39
40
41
42
43
# File 'lib/scrobbler/auth.rb', line 39

def url(options={})
  options[:token] = token if options[:token].nil?
  options[:api_key] = @@api_key
  "http://www.last.fm/api/auth/?api_key=#{options[:api_key]}&token=#{options[:token]}"
end