Sha256: 0adbb27a235f724a88b2ba925de12da574e0fe70ac213e12976c4a13e4748953

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

require 'omniauth/oauth'
require 'multi_json'

module OmniAuth
  module Strategies
    #
    # Authenticate to SoundCloud via OAuth and retrieve basic
    # user information.
    #
    # Usage:
    #
    #    use OmniAuth::Strategies::SoundCloud, 'consumerkey', 'consumersecret'
    #

    class SoundCloud < OmniAuth::Strategies::OAuth
      def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
        super(app, :soundcloud, consumer_key, consumer_secret, {:site => 'https://api.soundcloud.com'}, options)
      end

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

      def user_info
        user_hash = self.user_hash

        {
          'name' => user_hash['full_name'],
          'nickname' => user_hash['username'],
          'location' => user_hash['city'],
          'description' => user_hash['description'],
          'image' => user_hash['avatar_url'],
          'urls' => {'Website' => user_hash['website']}
        }
      end

      def user_hash
        @user_hash ||= MultiJson.decode(@access_token.get('/me.json').body)
      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/sound_cloud.rb
oa-oauth-0.2.6 lib/omniauth/strategies/sound_cloud.rb
omniauth-0.2.5 oa-oauth/lib/omniauth/strategies/sound_cloud.rb
oa-oauth-0.2.5 lib/omniauth/strategies/sound_cloud.rb