Class: OmniAuth::Strategies::Gowalla

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/oauth2/gowalla.rb

Overview

Authenticate to Gowalla utilizing OAuth 2.0 and retrieve basic user information.

Examples:

Basic Usage

use OmniAuth::Strategies::Gowalla, 'API Key', 'Secret Key'

Instance Attribute Summary

Attributes inherited from OAuth2

#client_id, #client_options, #client_secret, #options

Instance Method Summary collapse

Methods inherited from OAuth2

#callback_url, #client

Constructor Details

#initialize(app, client_id = nil, client_secret = nil, options = {}, &block) ⇒ Gowalla

Returns a new instance of Gowalla.

Parameters:

  • app (Rack Application)

    standard middleware application parameter

  • client_id (String) (defaults to: nil)

    the application id as registered on Gowalla

  • client_secret (String) (defaults to: nil)

    the application secret as registered on Gowalla

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

    a customizable set of options

Options Hash (options):

  • :scope ('read', 'read-write') — default: 'read'

    the scope of your authorization request; must be read or read-write



16
17
18
19
20
21
22
# File 'lib/omniauth/strategies/oauth2/gowalla.rb', line 16

def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
  client_options = {
    :authorize_url => 'https://gowalla.com/api/oauth/new',
    :token_url => 'https://api.gowalla.com/api/oauth/token',
  }
  super(app, :gowalla, client_id, client_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/omniauth/strategies/oauth2/gowalla.rb', line 24

def auth_hash
  OmniAuth::Utils.deep_merge(
    super, {
      'uid' => user_data['url'].split('/').last,
      'user_info' => ,
      'extra' => {
        'user_hash' => user_data,
        'refresh_token' => refresh_token,
        'token_expires_at' => token_expires_at,
      },
    }
  )
end

#refresh_tokenObject



42
43
44
# File 'lib/omniauth/strategies/oauth2/gowalla.rb', line 42

def refresh_token
  @refresh_token ||= @access_token.refresh_token
end

#request_phaseObject



50
51
52
53
# File 'lib/omniauth/strategies/oauth2/gowalla.rb', line 50

def request_phase
  options[:scope] ||= 'read'
  super
end

#token_expires_atObject



46
47
48
# File 'lib/omniauth/strategies/oauth2/gowalla.rb', line 46

def token_expires_at
  @expires_at ||= @access_token.expires_at
end

#user_dataObject



38
39
40
# File 'lib/omniauth/strategies/oauth2/gowalla.rb', line 38

def user_data
  @data ||= MultiJson.decode(@access_token.get('/users/me.json'))
end

#user_infoObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/omniauth/strategies/oauth2/gowalla.rb', line 55

def 
  {
    'name' => "#{user_data['first_name']} #{user_data['last_name']}",
    'nickname' => user_data['username'],
    'first_name' => user_data['first_name'],
    'last_name' => user_data['last_name'],
    'location' => user_data['hometown'],
    'description' => user_data['bio'],
    'image' => user_data['image_url'],
    'urls' => {
      'Gowalla' => "http://www.gowalla.com#{user_data['url']}",
      'Website' => user_data['website'],
    },
  }
end