Class: OmniAuth::Strategies::MySpace
- Defined in:
- lib/omniauth/strategies/oauth/my_space.rb
Instance Attribute Summary
Attributes inherited from OAuth
#consumer_key, #consumer_options, #consumer_secret, #name
Instance Method Summary collapse
- #callback_phase ⇒ Object
- #consumer ⇒ Object
-
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ MySpace
constructor
A new instance of MySpace.
- #request_phase ⇒ Object
- #user_data ⇒ Object
- #user_hash(access_token) ⇒ Object
Methods inherited from OAuth
Constructor Details
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ MySpace
Returns a new instance of MySpace.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/omniauth/strategies/oauth/my_space.rb', line 8 def initialize(app, consumer_key=nil, consumer_secret=nil, ={}, &block) = { :site => 'http://api.myspace.com', :access_token_path => '/access_token', :authorize_path => '/authorize', :request_token_path => '/request_token', :http_method => "get" } .merge! :http_method => :get super(app, :my_space, consumer_key, consumer_secret, , , &block) end |
Instance Method Details
#callback_phase ⇒ Object
20 21 22 23 |
# File 'lib/omniauth/strategies/oauth/my_space.rb', line 20 def callback_phase session['oauth'][name.to_s]['callback_confirmed'] = true super end |
#consumer ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/omniauth/strategies/oauth/my_space.rb', line 48 def consumer ::OAuth::Consumer.new(consumer_key, consumer_secret, { :http_method=>"get", :site=>"http://api.myspace.com", :request_token_path=>"/request_token", :access_token_path=>"/access_token", :authorize_path=>"/authorize" }) end |
#request_phase ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/omniauth/strategies/oauth/my_space.rb', line 31 def request_phase request_token = consumer.get_request_token(:oauth_callback => callback_url) session['oauth'] ||= {} session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret} sleep 1 if request_token.callback_confirmed? redirect request_token.([:authorize_params]) else redirect request_token.([: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 |
#user_data ⇒ Object
25 26 27 28 29 |
# File 'lib/omniauth/strategies/oauth/my_space.rb', line 25 def user_data @access_token..merge!({:param_name => 'oauth_token', :mode => :query}) # response = @access_token.post('/simple/players.info') # @data ||= MultiJson.decode(response.body) end |
#user_hash(access_token) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/omniauth/strategies/oauth/my_space.rb', line 58 def user_hash(access_token) person = JSON.parse( access_token.get("/v2/people/@me/@self?format=json").body )["users"].first hash = { 'id' => person['id'], 'first_name' => person['first_name'], 'last_name' => person['last_name'], 'image' => person["photo_urls"]["large"], } end |