Class: OmniAuth::Strategies::Douban

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Douban

Returns a new instance of Douban.



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

def initialize(*args)
  super
  # taken from https://github.com/intridea/omniauth/blob/0-3-stable/oa-oauth/lib/omniauth/strategies/oauth/douban.rb#L15-21
  options.client_options = {
    :access_token_path => '/service/auth/access_token',
    :authorize_path => '/service/auth/authorize',
    :realm => 'OmniAuth',
    :request_token_path => '/service/auth/request_token',
    :site => 'http://www.douban.com'
  }
end

Instance Method Details

#consumerObject



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

def consumer
  consumer = ::OAuth::Consumer.new(options.consumer_key, options.consumer_secret, options.client_options)
  consumer
end

#raw_infoObject

taken from github.com/intridea/omniauth/blob/0-3-stable/oa-oauth/lib/omniauth/strategies/oauth/tsina.rb#L52-67 def request_phase

request_token = consumer.get_request_token(:oauth_callback => callback_url)
session['oauth'] ||= {}
session['oauth'][name.to_s] = {'callback_confirmed' => true, 'request_token' => request_token.token, 'request_secret' => request_token.secret}

if request_token.callback_confirmed?
  redirect request_token.authorize_url(options[:authorize_params])
else
  redirect request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url))
end

rescue ::Timeout::Error => e

fail!(:timeout, e)

rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e

fail!(:service_unavailable, e)

end



64
65
66
67
68
# File 'lib/omniauth/strategies/douban.rb', line 64

def raw_info
  @raw_info ||= MultiJson.decode(access_token.get('http://api.douban.com/people/%40me?alt=json').body)
rescue ::Errno::ETIMEDOUT
  raise ::Timeout::Error
end