Sha256: b9f0e65f52ff98be12045fe8370a0171f094d56e8c88f30c1fd002ad8124ecf3

Contents?: true

Size: 1.61 KB

Versions: 12

Compression:

Stored size: 1.61 KB

Contents

require 'omniauth/oauth'
require 'multi_json'

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

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

      def user_info
        user = user_hash['person']
        {
          'nickname' => user['username'],
          'name' => user['display_name'],
          'location' => user['location'],
          'description' => user['bio'],
          'image' => user['portraits']['portrait'].select{|h| h['height'] == '300'}.first['_content'],
          'urls' => {
            'website' => user['url'],
            'vimeo' => user['profileurl']
          }
        }
      end

      def user_hash
        url = "http://vimeo.com/api/rest/v2?method=vimeo.people.getInfo&format=json"
        @user_hash ||= MultiJson.decode(@access_token.get(url).body)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
omniauth-0.2.6 oa-oauth/lib/omniauth/strategies/vimeo.rb
oa-oauth-0.2.6 lib/omniauth/strategies/vimeo.rb
omniauth-0.2.5 oa-oauth/lib/omniauth/strategies/vimeo.rb
oa-oauth-0.2.5 lib/omniauth/strategies/vimeo.rb
oa-oauth-0.2.4 lib/omniauth/strategies/vimeo.rb
oa-oauth-0.2.3 lib/omniauth/strategies/vimeo.rb
oa-oauth-0.2.2 lib/omniauth/strategies/vimeo.rb
oa-oauth-0.2.1 lib/omniauth/strategies/vimeo.rb
oa-oauth-0.2.0 lib/omniauth/strategies/vimeo.rb
oa-oauth-0.2.0.beta5 lib/omniauth/strategies/vimeo.rb
oa-oauth-0.2.0.beta4 lib/omniauth/strategies/vimeo.rb
oa-oauth-0.2.0.beta3 lib/omniauth/strategies/vimeo.rb