Sha256: f0f76a0a10a82dd5ceafa0dca4c3d0c051f6a108c105cb9f7504de2fd2af6d8b

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

require 'omniauth/oauth'
require 'multi_json'

module OmniAuth
  module Strategies
    #
    # Authenticate to Rdio via OAuth and retrieve basic user information.
    # Usage:
    #    use OmniAuth::Strategies::Rdio, 'consumerkey', 'consumersecret'
    #
    class Rdio < OmniAuth::Strategies::OAuth
      def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
        opts = {
          :site               => 'http://api.rdio.com',
          :request_token_path => "/oauth/request_token",
          :access_token_path  => "/oauth/access_token",
          :authorize_url      => "https://www.rdio.com/oauth/authorize"
        }
        super(app, :rdio, consumer_key, consumer_secret, opts, options, &block)
      end

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

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

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

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
omniauth-0.2.6 oa-oauth/lib/omniauth/strategies/rdio.rb
oa-oauth-0.2.6 lib/omniauth/strategies/rdio.rb
omniauth-0.2.5 oa-oauth/lib/omniauth/strategies/rdio.rb
oa-oauth-0.2.5 lib/omniauth/strategies/rdio.rb