Class: OmniAuth::Strategies::Plurk

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/oauth/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

Methods inherited from OAuth

#callback_phase, #consumer, #request_phase, #unique_id

Constructor Details

#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Plurk

Returns a new instance of Plurk.

Parameters:

  • app (Rack Application)

    standard middleware application parameter

  • consumer_key (String) (defaults to: nil)
  • consumer_secret (String) (defaults to: nil)

    App secret registered on plurk



17
18
19
20
21
22
23
24
25
# File 'lib/omniauth/strategies/oauth/plurk.rb', line 17

def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
  client_options = {
    :access_token_path => '/OAuth/access_token',
    :authorize_path => '/OAuth/authorize',
    :request_token_path => '/OAuth/request_token',
    :site => 'http://www.plurk.com',
  }
  super(app, :plurk, consumer_key, consumer_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/omniauth/strategies/oauth/plurk.rb', line 27

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

#user_hashObject



51
52
53
# File 'lib/omniauth/strategies/oauth/plurk.rb', line 51

def user_hash
  @user_hash  ||= MultiJson.decode(@access_token.get('/APP/Profile/getOwnProfile').body)['user_info']
end

#user_infoObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/omniauth/strategies/oauth/plurk.rb', line 40

def 
  user = self.user_hash
  {
    'name' => user['full_name'],
    'nickname' => user['display_name'] || user['nick_name'],
    'location' => user['location'],
    'image' => user['has_profile_image'] == 1 ? "http://avatars.plurk.com/#{user['id']}-medium#{user['avatar']}.gif" : 'http://www.plurk.com/static/default_medium.gif',
    'urls' => {'Plurk' => 'http://plurk.com/' + user['nick_name']},
  }
end