Class: OmniAuth::Strategies::Tumblr

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/oauth/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

Methods inherited from OAuth

#callback_phase, #consumer, #request_phase, #unique_id

Constructor Details

#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Tumblr

Returns a new instance of Tumblr.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :sign_in (Boolean, true)

    When true, use the "Sign in with Tumblr" flow instead of the authorization flow.



12
13
14
15
16
17
18
# File 'lib/omniauth/strategies/oauth/tumblr.rb', line 12

def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
  client_options = {
    :site => 'http://www.tumblr.com',
  }
  client_options[:authorize_path] = '/oauth/authorize' unless options[:sign_in] == false
  super(app, :tumblr, consumer_key, consumer_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/omniauth/strategies/oauth/tumblr.rb', line 20

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

#userObject



43
44
45
46
47
48
49
50
# File 'lib/omniauth/strategies/oauth/tumblr.rb', line 43

def user
  tumblelogs = user_hash['tumblr']['tumblelog']
  if tumblelogs.kind_of?(Array)
    @user ||= tumblelogs[0]
  else
    @user ||= tumblelogs
  end
end

#user_hashObject



52
53
54
55
# File 'lib/omniauth/strategies/oauth/tumblr.rb', line 52

def user_hash
  url = 'http://www.tumblr.com/api/authenticate'
  @user_hash ||= Hash.from_xml(@access_token.get(url).body)
end

#user_infoObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/omniauth/strategies/oauth/tumblr.rb', line 32

def 
  {
    'nickname' => user['name'],
    'name' => user['title'],
    'image' => user['avatar_url'],
    'urls' => {
      'website' => user['url'],
    }
  }
end