Skip to content
Browse files

Merge pull request #333 from albb0920/master

Strategy for plurk (OAuth)
  • Loading branch information...
2 parents 9c456b4 + b9e8fd1 commit 440185157ae92954c1875dfcb514306099576138 @sferik sferik committed May 18, 2011
View
1 README.md
@@ -41,6 +41,7 @@ OmniAuth currently supports the following external providers:
* Miso (credit: [rickenharp](https://github.com/rickenharp))
* Mixi (credit: [kiyoshi](https://github.com/kiyoshi))
* Netflix (credit: [caged](https://github.com/caged))
+ * Plurk (credit: [albb0920](http://github.com/albb0920))
* Qzone (credit: [quake](https://github.com/quake))
* Rdio (via [brandonweiss](https://github.com/brandonweiss))
* Renren (credit: [quake](https://github.com/quake))
View
1 oa-oauth/lib/omniauth/oauth.rb
@@ -28,6 +28,7 @@ module Strategies
autoload :Mixi, 'omniauth/strategies/mixi'
autoload :Netflix, 'omniauth/strategies/netflix'
autoload :Qzone, 'omniauth/strategies/qzone'
+ autoload :Plurk, 'omniauth/strategies/plurk'
autoload :Rdio, 'omniauth/strategies/rdio'
autoload :Renren, 'omniauth/strategies/renren'
autoload :Salesforce, 'omniauth/strategies/salesforce'
View
58 oa-oauth/lib/omniauth/strategies/plurk.rb
@@ -0,0 +1,58 @@
+require 'omniauth/oauth'
+require 'multi_json'
+
+module OmniAuth
+ module Strategies
+ #
+ # 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
+ class Plurk < OmniAuth::Strategies::OAuth
+
+ # @param [Rack Application] app standard middleware application parameter
+ # @param [String] client_key App key [registered on plurk] (http://www.plurk.com/PlurkApp/register)
+ # @param [String] client_secret App secret registered on plurk
+ 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
+
+ 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
+
+ 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
+
+ def user_hash
+ @user_hash ||= MultiJson.decode(@access_token.get('/APP/Profile/getOwnProfile').body)['user_info']
+ end
+
+ end
+ end
+end
View
5 oa-oauth/spec/omniauth/strategies/plurk_spec.rb
@@ -0,0 +1,5 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe OmniAuth::Strategies::Plurk do
+ it_should_behave_like 'an oauth strategy'
+end

0 comments on commit 4401851

Please sign in to comment.
Something went wrong with that request. Please try again.