Class: OmniAuth::Strategies::Gowalla
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::Gowalla
show all
- Defined in:
- lib/omniauth/strategies/oauth2/gowalla.rb
Overview
Authenticate to Gowalla utilizing OAuth 2.0 and retrieve
basic user information.
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.
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_hash ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# 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' => user_info,
'credentials' => {'refresh_token' => @access_token.refresh_token},
'extra' => {
'user_hash' => user_data,
'refresh_token' => refresh_token,
'token_expires_at' => token_expires_at,
},
}
)
end
|
#build_access_token ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/omniauth/strategies/oauth2/gowalla.rb', line 84
def build_access_token
token=super
token=::OAuth2::AccessToken.new(token.client,token.token,{:expires_in=>token.expires_in,:refresh_token=>token.refresh_token}.merge(token.params))
if token.expired?
token=token.refresh!
token=::OAuth2::AccessToken.new(token.client,token.token,{:expires_in=>token.expires_in,:refresh_token=>token.refresh_token}.merge(token.params))
end
token
end
|
#refresh_token ⇒ Object
55
56
57
|
# File 'lib/omniauth/strategies/oauth2/gowalla.rb', line 55
def refresh_token
@refresh_token ||= @access_token.refresh_token
end
|
#request_phase ⇒ Object
63
64
65
66
|
# File 'lib/omniauth/strategies/oauth2/gowalla.rb', line 63
def request_phase
options[:scope] ||= 'read'
super
end
|
#token_expires_at ⇒ Object
59
60
61
|
# File 'lib/omniauth/strategies/oauth2/gowalla.rb', line 59
def token_expires_at
@expires_at ||= @access_token.expires_at
end
|
#user_data ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/omniauth/strategies/oauth2/gowalla.rb', line 38
def user_data
puts "user_data"
if(@data.nil?)
opts={
:raise_errors=>false,
:headers =>{:Accept => 'application/json','X-Gowalla-API-Key'=> self.client_id},
:params=>{:oauth_token=>@access_token.token}
}
response=@access_token.get('http://api.gowalla.com/users/me',opts)
@data = MultiJson.decode(response.body)
end
@data
end
|
#user_info ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/omniauth/strategies/oauth2/gowalla.rb', line 68
def user_info
{
'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
|