Class: OmniAuth::Strategies::Tumblr
- Defined in:
- lib/omniauth/strategies/tumblr.rb
Overview
Authenticate to Tumblr via OAuth and retrieve basic user information.
Usage:
use OmniAuth::Strategies::Tumblr, '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) ⇒ Tumblr
constructor
Initialize the middleware.
- #user ⇒ Object
- #user_hash ⇒ Object
- #user_info ⇒ Object
Methods inherited from OAuth
#callback_phase, #consumer, #request_phase, #unique_id
Constructor Details
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Tumblr
Initialize the middleware
17 18 19 20 21 22 23 24 |
# File 'lib/omniauth/strategies/tumblr.rb', line 17 def initialize(app, consumer_key = nil, consumer_secret = nil, = {}, &block) = { :site => 'http://www.tumblr.com' } [:authorize_path] = '/oauth/authorize' unless [:sign_in] == false super(app, :tumblr, consumer_key, consumer_secret, , ) end |
Instance Method Details
#auth_hash ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/omniauth/strategies/tumblr.rb', line 26 def auth_hash OmniAuth::Utils.deep_merge(super, { 'uid' => user['name'], 'user_info' => user_info, 'extra' => { 'user_hash' => user } }) end |
#user ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/omniauth/strategies/tumblr.rb', line 45 def user tumblelogs = user_hash['tumblr']['tumblelog'] if tumblelogs.kind_of?(Array) @user ||= tumblelogs[0] else @user ||= tumblelogs end end |
#user_hash ⇒ Object
54 55 56 57 |
# File 'lib/omniauth/strategies/tumblr.rb', line 54 def user_hash url = "http://www.tumblr.com/api/authenticate" @user_hash ||= Hash.from_xml(@access_token.get(url).body) end |
#user_info ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/omniauth/strategies/tumblr.rb', line 34 def user_info { 'nickname' => user['name'], 'name' => user['title'], 'image' => user['avatar_url'], 'urls' => { 'website' => user['url'], } } end |