Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'omniauth/oauth' | ||
require 'multi_json' | ||
|
||
module OmniAuth | ||
module Strategies | ||
# | ||
# Authenticate to Gowalla utilizing OAuth 2.0 and retrieve | ||
# basic user information. | ||
# | ||
# Usage: | ||
# | ||
# use OmniAuth::Strategies::Gowalla, 'API Key', 'Secret Key' | ||
# | ||
# Options: | ||
# | ||
# <tt>:scope</tt> :: Extended permissions such as <tt>email</tt> and <tt>offline_access</tt> (which are the defaults). | ||
class Gowalla < OAuth2 | ||
def initialize(app, api_key, secret_key, options = {}) | ||
options[:site] = 'https://api.gowalla.com/api/oauth' | ||
options[:authorize_url] = 'https://gowalla.com/api/oauth/new' | ||
options[:access_token_url] = 'https://api.gowalla.com/api/oauth/token' | ||
super(app, :gowalla, api_key, secret_key, options) | ||
end | ||
|
||
def user_data | ||
@data ||= MultiJson.decode(@access_token.get("/users/me.json")) | ||
end | ||
|
||
def request_phase(options = {}) | ||
options[:scope] ||= "email,offline_access" | ||
super(options) | ||
end | ||
|
||
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"], | ||
'phone' => nil, | ||
'urls' => { | ||
'Gowalla' => "http://www.gowalla.com/#{user_data['url']}", | ||
'Website' => user_data["website"] | ||
} | ||
} | ||
end | ||
|
||
def auth_hash | ||
OmniAuth::Utils.deep_merge(super, { | ||
'uid' => user_data["url"].split('/').last, | ||
'user_info' => user_info, | ||
'extra' => {'user_hash' => user_data} | ||
}) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') | ||
|
||
describe OmniAuth::Strategies::Gowalla do | ||
|
||
it 'should subclass OAuth2' do | ||
OmniAuth::Strategies::Gowalla.should < OmniAuth::Strategies::OAuth2 | ||
end | ||
|
||
it 'should initialize with just api key and secret key' do | ||
lambda{OmniAuth::Strategies::Gowalla.new({},'api_key','secret_key')}.should_not raise_error | ||
end | ||
|
||
end |