Class: OmniAuth::Strategies::Flattr

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

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, options={}, &block)
  client_options = {
    :site => 'https://api.flattr.com'
  }
  options[:authorize_params] = {:access_scope => "read,publish,click,extendedread"}
  super(app, :flattr, consumer_key, consumer_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



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

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

#user_hashObject

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_infoObject

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 
  {
    '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