Class: OmniAuth::Strategies::Rdio

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/oauth/rdio.rb

Overview

Authenticate to Rdio via OAuth and retrieve basic user information.

Usage: use OmniAuth::Strategies::Rdio, 'consumerkey', 'consumersecret'

Instance Attribute Summary

Attributes inherited from OAuth

#consumer_key, #consumer_options, #consumer_secret, #name

Instance Method Summary collapse

Methods inherited from OAuth

#callback_phase, #consumer, #request_phase, #unique_id

Constructor Details

#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Rdio

Returns a new instance of Rdio.



11
12
13
14
15
16
17
18
19
# File 'lib/omniauth/strategies/oauth/rdio.rb', line 11

def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
  client_options = {
    :access_token_path => '/oauth/access_token',
    :authorize_url => 'https://www.rdio.com/oauth/authorize',
    :request_token_path => '/oauth/request_token',
    :site => 'http://api.rdio.com',
  }
  super(app, :rdio, consumer_key, consumer_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/omniauth/strategies/oauth/rdio.rb', line 21

def auth_hash
  OmniAuth::Utils.deep_merge(
    super, {
      'uid' => user_hash['key'],
      'user_info' => ,
      'extra' => {
        'user_hash' => user_hash,
      },
    }
  )
end

#user_hashObject



43
44
45
# File 'lib/omniauth/strategies/oauth/rdio.rb', line 43

def user_hash
  @user_hash ||= MultiJson.decode(@access_token.post('http://api.rdio.com/1/', {:method => 'currentUser', :extras => 'username'}).body)['result']
end

#user_infoObject



33
34
35
36
37
38
39
40
41
# File 'lib/omniauth/strategies/oauth/rdio.rb', line 33

def 
  user = user_hash
  {
    'nickname' => user['username'],
    'first_name' => user['firstName'],
    'last_name' => user['lastName'],
    'name' => "#{user['firstName']} #{user['lastName']}"
  }
end