Class: OmniAuth::Strategies::Lastfm

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/omniauth/strategies/lastfm.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



21
22
23
# File 'lib/omniauth/strategies/lastfm.rb', line 21

def json
  @json
end

Instance Method Details

#callback_phaseObject



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
# File 'lib/omniauth/strategies/lastfm.rb', line 32

def callback_phase
  @json = {}
  token = request.params["token"]
  begin
    params = { :api_key => options.api_key,
               :token   => token,
               :api_sig =>  signature(token),
               :method  => "auth.getSession",
               :format  => 'json'}
    response = RestClient.get(options.client_options.api_url, { :params => params })
    session = MultiJson.decode(response.to_s)
    @json.merge!(session)

    params = {:api_key  => options.api_key,
              :user     => @json['session']['name'],
              :method   => 'user.getInfo',
              :format   => 'json'}
    response = RestClient.get(options.client_options.api_url, { :params => params })
    user = MultiJson.decode(response.to_s)
    @json.merge!(user)
  rescue ::RestClient::Exception
    raise ::Timeout::Error
  end
  super
end

#request_phaseObject



23
24
25
26
27
28
29
30
# File 'lib/omniauth/strategies/lastfm.rb', line 23

def request_phase
  params = {
    :api_key => options.api_key,
    :cb      => options.client_options["callback"]
  }
  query_string = params.map{ |key,value| "#{key}=#{value}" }.join("&")
  redirect "#{options.client_options.site}#{options.client_options.authorize_path}/?#{query_string}"
end