Class: OmniAuth::Strategies::Plurk

Inherits:
OAuth
  • Object
show all
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

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.

Parameters:

  • app (Rack Application)

    standard middleware application parameter

  • client_key (String) (defaults to: nil)
  • client_secret (String) (defaults to: nil)

    App secret registered on 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, options = {}, &block)
  client_options = { :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, client_options, options)
end

Instance Method Details

#auth_hashObject



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' => ,
    'extra' => {'user_hash' => user_hash}
  })
end

#user_hashObject



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_infoObject



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

def 
  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