Class: OmniAuth::Strategies::Flattr
- Defined in:
- lib/omniauth/strategies/oauth/flattr.rb
Overview
Authenticate to Flattr via OAuth and retrieve basic user information. Usage: use OmniAuth::Strategies::Flattr, 'consumerkey', 'consumersecret'
Instance Attribute Summary
Attributes inherited from OAuth
#consumer_key, #consumer_options, #consumer_secret, #name
Instance Method Summary collapse
- #auth_hash ⇒ Object
-
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Flattr
constructor
A new instance of Flattr.
-
#user_hash ⇒ Object
info as supplied by Flattr user summary response: "user"=>{"id"=>"82597", "username"=>"foo", "firstname"=>"Foo", "lastname"=>"Bar", "email"=>"[email protected]", "city"=>"", "country"=>"", "gravatar"=>"", "url"=>"", "description"=>"", "thingcount"=>"1", "language"=>"en_GB"}}.
-
#user_info ⇒ Object
user info according to schema.
Methods inherited from OAuth
#callback_phase, #consumer, #request_phase, #unique_id
Constructor Details
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Flattr
Returns a new instance of Flattr.
10 11 12 13 14 15 16 |
# File 'lib/omniauth/strategies/oauth/flattr.rb', line 10 def initialize(app, consumer_key=nil, consumer_secret=nil, ={}, &block) = { :site => 'https://api.flattr.com' } [:authorize_params] = {:access_scope => "read,publish,click,extendedread"} super(app, :flattr, consumer_key, consumer_secret, , , &block) end |
Instance Method Details
#auth_hash ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/omniauth/strategies/oauth/flattr.rb', line 18 def auth_hash ui = user_info OmniAuth::Utils.deep_merge(super, { 'uid' => user_hash['id'], 'user_info' => ui, 'extra' => {'user_hash' => user_hash} }) end |
#user_hash ⇒ Object
info as supplied by Flattr user summary response: "user"=>{"id"=>"82597", "username"=>"foo", "firstname"=>"Foo", "lastname"=>"Bar", "email"=>"[email protected]", "city"=>"", "country"=>"", "gravatar"=>"", "url"=>"", "description"=>"", "thingcount"=>"1", "language"=>"en_GB"}}
42 43 44 |
# File 'lib/omniauth/strategies/oauth/flattr.rb', line 42 def user_hash @user_hash ||= MultiXml.parse(@access_token.get('/rest/0.5/user/me').body)["flattr"]["user"] end |
#user_info ⇒ Object
user info according to schema
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/omniauth/strategies/oauth/flattr.rb', line 28 def user_info { 'uid' => user_hash['id'], 'nickname' => user_hash['username'], 'first_name' => user_hash['firstname'], 'last_name' => user_hash['lastname'], 'name' => [user_hash['firstname'],user_hash['lastname']].reject{ |n| n.nil? || n.empty? }.join(' '), 'email' => user_hash['email'], 'language' => user_hash['language'] } end |