Class: OmniAuth::Strategies::Plurk
- Defined in:
- lib/omniauth/strategies/plurk.rb
Overview
Authenticate to Plurk via OAuth and retrieve basic user info.
Please note that this strategy relies on Plurk API 2.0, which is still in Beta.
Usage: use OmniAuth::Strategies::Plurk
Instance Attribute Summary
Attributes inherited from OAuth
#consumer_key, #consumer_options, #consumer_secret, #name
Instance Method Summary collapse
- #auth_hash ⇒ Object
-
#initialize(app, client_key = nil, client_secret = nil, options = {}, &block) ⇒ Plurk
constructor
A new instance of Plurk.
- #user_hash ⇒ Object
- #user_info ⇒ Object
Methods inherited from OAuth
#callback_phase, #consumer, #request_phase, #unique_id
Constructor Details
#initialize(app, client_key = nil, client_secret = nil, options = {}, &block) ⇒ Plurk
Returns a new instance of Plurk.
19 20 21 22 23 24 25 26 |
# File 'lib/omniauth/strategies/plurk.rb', line 19 def initialize(app, client_key = nil, client_secret = nil, = {}, &block) = { :site => 'http://www.plurk.com', :request_token_path => '/OAuth/request_token', :access_token_path => '/OAuth/access_token', :authorize_path => '/OAuth/authorize' } super(app, :plurk, client_key, client_secret, , ) end |
Instance Method Details
#auth_hash ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/omniauth/strategies/plurk.rb', line 28 def auth_hash user = self.user_hash OmniAuth::Utils.deep_merge(super, { 'uid' => user['id'], 'user_info' => user_info, 'extra' => {'user_hash' => user_hash} }) end |
#user_hash ⇒ Object
52 53 54 |
# File 'lib/omniauth/strategies/plurk.rb', line 52 def user_hash @user_hash ||= MultiJson.decode(@access_token.get('/APP/Profile/getOwnProfile').body)['user_info'] end |
#user_info ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/omniauth/strategies/plurk.rb', line 37 def user_info user = self.user_hash { 'name' => user['full_name'], 'nickname' => user['display_name'] || user['nick_name'], 'location' => user['location'], 'image' => if user['has_profile_image'] == 1 "http://avatars.plurk.com/#{user['id']}-medium#{user['avatar']}.gif" else "http://www.plurk.com/static/default_medium.gif" end, 'urls' => { 'Plurk' => 'http://plurk.com/' + user['nick_name']} } end |