Skip to content

Commit

Permalink
remove support for ruby < 1.9, upgrade hash syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mkdynamic committed Jun 27, 2016
1 parent 28207f3 commit edc2169
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 99 deletions.
18 changes: 8 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ before_install:
- gem update --system 2.1.11
- gem --version
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- 2.0.0
- 2.1
- 2.3
- 2.2
- jruby
- rbx
matrix:
allow_failures:
- rvm: rbx
- 2.1
- 2.0
- 1.9.3
- 1.9.2
- jruby-19mode
- rbx-2
- ree
4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ source 'https://rubygems.org'

gemspec

platforms :ruby_18 do
gem 'hashie', '~> 2.0.5'
end

platforms :rbx do
gem 'rubysl', '~> 2.0'
end
81 changes: 37 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ For example, to request `email`, `user_birthday` and `read_stream` permissions a
```ruby
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'],
:scope => 'email,user_birthday,read_stream', :display => 'popup'
scope: 'email,user_birthday,read_stream', display: 'popup'
end
```

Expand All @@ -67,9 +67,9 @@ OmniAuth Facebook uses versioned API endpoints by default (current v2.6). You ca
```ruby
use OmniAuth::Builder do
provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'],
:client_options => {
:site => 'https://graph.facebook.com/v2.6',
:authorize_url => "https://www.facebook.com/v2.6/dialog/oauth"
client_options: {
site: 'https://graph.facebook.com/v2.6',
authorize_url: "https://www.facebook.com/v2.6/dialog/oauth"
}
end
```
Expand All @@ -84,38 +84,38 @@ Here's an example *Auth Hash* available in `request.env['omniauth.auth']`:

```ruby
{
:provider => 'facebook',
:uid => '1234567',
:info => {
:email => '[email protected]',
:name => 'Joe Bloggs',
:first_name => 'Joe',
:last_name => 'Bloggs',
:image => 'http://graph.facebook.com/1234567/picture?type=square',
:urls => { :Facebook => 'http://www.facebook.com/jbloggs' },
:location => 'Palo Alto, California',
:verified => true
provider: 'facebook',
uid: '1234567',
info: {
email: '[email protected]',
name: 'Joe Bloggs',
first_name: 'Joe',
last_name: 'Bloggs',
image: 'http://graph.facebook.com/1234567/picture?type=square',
urls: { Facebook: 'http://www.facebook.com/jbloggs' },
location: 'Palo Alto, California',
verified: true
},
:credentials => {
:token => 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
:expires_at => 1321747205, # when the access token expires (it always will)
:expires => true # this will always be true
credentials: {
token: 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
expires_at: 1321747205, # when the access token expires (it always will)
expires: true # this will always be true
},
:extra => {
:raw_info => {
:id => '1234567',
:name => 'Joe Bloggs',
:first_name => 'Joe',
:last_name => 'Bloggs',
:link => 'http://www.facebook.com/jbloggs',
:username => 'jbloggs',
:location => { :id => '123456789', :name => 'Palo Alto, California' },
:gender => 'male',
:email => '[email protected]',
:timezone => -8,
:locale => 'en_US',
:verified => true,
:updated_time => '2011-11-11T06:21:03+0000'
extra: {
raw_info: {
id: '1234567',
name: 'Joe Bloggs',
first_name: 'Joe',
last_name: 'Bloggs',
link: 'http://www.facebook.com/jbloggs',
username: 'jbloggs',
location: { id: '123456789', name: 'Palo Alto, California' },
gender: 'male',
email: '[email protected]',
timezone: -8,
locale: 'en_US',
verified: true,
updated_time: '2011-11-11T06:21:03+0000'
}
}
}
Expand Down Expand Up @@ -157,16 +157,9 @@ If you use the server-side flow, Facebook will give you back a longer lived acce

## Supported Rubies

Actively tested with the following Ruby versions:

- MRI 2.2
- MRI 2.1
- MRI 2.0.0
- MRI 1.9.3
- MRI 1.9.2
- MRI 1.8.7 (use hashie ~> 2.0.5 in your Gemfile)
- JRuby 1.7.9
- Rubinius (latest stable)
- Ruby MRI (1.9.2+)
- JRuby (1.9 mode)
- RBX (2.1.1+)

## License

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Rake::TestTask.new do |task|
task.test_files = FileList['test/*_test.rb']
end

task :default => :test
task default: :test
2 changes: 1 addition & 1 deletion example/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ source 'https://rubygems.org'

gem 'sinatra'
gem 'sinatra-reloader'
gem 'omniauth-facebook', :path => '../'
gem 'omniauth-facebook', path: '../'
2 changes: 1 addition & 1 deletion example/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require 'bundler/setup'
require 'omniauth-facebook'
require './app.rb'

use Rack::Session::Cookie, :secret => 'abc123'
use Rack::Session::Cookie, secret: 'abc123'

use OmniAuth::Builder do
provider :facebook, ENV['APP_ID'], ENV['APP_SECRET']
Expand Down
22 changes: 11 additions & 11 deletions lib/omniauth/strategies/facebook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class NoAuthorizationCodeError < StandardError; end
DEFAULT_SCOPE = 'email'

option :client_options, {
:site => 'https://graph.facebook.com/v2.6',
:authorize_url => "https://www.facebook.com/v2.6/dialog/oauth",
:token_url => 'oauth/access_token'
site: 'https://graph.facebook.com/v2.6',
authorize_url: "https://www.facebook.com/v2.6/dialog/oauth",
token_url: 'oauth/access_token'
}

option :access_token_options, {
:header_format => 'OAuth %s',
:param_name => 'access_token'
header_format: 'OAuth %s',
param_name: 'access_token'
}

option :authorize_options, [:scope, :display, :auth_type]
Expand Down Expand Up @@ -55,11 +55,11 @@ def raw_info
end

def info_options
params = {:appsecret_proof => appsecret_proof}
params.merge!({:fields => (options[:info_fields] || 'name,email')})
params.merge!({:locale => options[:locale]}) if options[:locale]
params = {appsecret_proof: appsecret_proof}
params.merge!({fields: (options[:info_fields] || 'name,email')})
params.merge!({locale: options[:locale]}) if options[:locale]

{ :params => params }
{ params: params }
end

def callback_phase
Expand Down Expand Up @@ -158,10 +158,10 @@ def prune!(hash)
def image_url(uid, options)
uri_class = options[:secure_image_url] ? URI::HTTPS : URI::HTTP
site_uri = URI.parse(client.site)
url = uri_class.build({:host => site_uri.host, :path => "#{site_uri.path}/#{uid}/picture"})
url = uri_class.build({host: site_uri.host, path: "#{site_uri.path}/#{uid}/picture"})

query = if options[:image_size].is_a?(String) || options[:image_size].is_a?(Symbol)
{ :type => options[:image_size] }
{ type: options[:image_size] }
elsif options[:image_size].is_a?(Hash)
options[:image_size]
end
Expand Down
40 changes: 20 additions & 20 deletions test/strategy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ClientTest < StrategyTestCase
end

test 'has correct token url with versioning' do
@options = {:client_options => {:site => 'https://graph.facebook.net/v2.2'}}
@options = {client_options: {site: 'https://graph.facebook.net/v2.2'}}
assert_equal 'oauth/access_token', strategy.client.options[:token_url]
assert_equal 'https://graph.facebook.net/v2.2/oauth/access_token', strategy.client.token_url
end
Expand All @@ -33,7 +33,7 @@ class CallbackUrlTest < StrategyTestCase
end

test "returns path from callback_path option (omitting querystring)" do
@options = { :callback_path => "/auth/FB/done"}
@options = { callback_path: "/auth/FB/done"}
url_base = 'http://auth.request.com'
@request.stubs(:url).returns("#{url_base}/page/path")
strategy.stubs(:script_name).returns('') # as not to depend on Rack env
Expand All @@ -43,7 +43,7 @@ class CallbackUrlTest < StrategyTestCase

test "returns url from callback_url option" do
url = 'https://auth.myapp.com/auth/fb/callback'
@options = { :callback_url => url }
@options = { callback_url: url }
assert_equal url, strategy.callback_url
end
end
Expand Down Expand Up @@ -96,35 +96,35 @@ def setup

class InfoTest < StrategyTestCase
test 'returns the secure facebook avatar url when `secure_image_url` option is specified' do
@options = { :secure_image_url => true }
@options = { secure_image_url: true }
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info)
assert_equal 'https://graph.facebook.com/v2.6/321/picture', strategy.info['image']
end

test 'returns the image_url based of the client site' do
@options = { :secure_image_url => true, :client_options => {:site => "https://blah.facebook.com/v2.2"}}
@options = { secure_image_url: true, client_options: {site: "https://blah.facebook.com/v2.2"}}
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info)
assert_equal 'https://blah.facebook.com/v2.2/321/picture', strategy.info['image']
end

test 'returns the image with size specified in the `image_size` option' do
@options = { :image_size => 'normal' }
@options = { image_size: 'normal' }
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info)
assert_equal 'http://graph.facebook.com/v2.6/321/picture?type=normal', strategy.info['image']
end

test 'returns the image with size specified as a symbol in the `image_size` option' do
@options = { :image_size => :normal }
@options = { image_size: :normal }
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info)
assert_equal 'http://graph.facebook.com/v2.6/321/picture?type=normal', strategy.info['image']
end

test 'returns the image with width and height specified in the `image_size` option' do
@options = { :image_size => { :width => 123, :height => 987 } }
@options = { image_size: { width: 123, height: 987 } }
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info)
assert_match 'width=123', strategy.info['image']
Expand Down Expand Up @@ -255,39 +255,39 @@ def setup
super
@access_token = stub('OAuth2::AccessToken')
@appsecret_proof = 'appsecret_proof'
@options = {:appsecret_proof => @appsecret_proof, :fields => 'name,email'}
@options = {appsecret_proof: @appsecret_proof, fields: 'name,email'}
end

test 'performs a GET to https://graph.facebook.com/v2.6/me' do
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
strategy.stubs(:access_token).returns(@access_token)
params = {:params => @options}
params = {params: @options}
@access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
strategy.raw_info
end

test 'performs a GET to https://graph.facebook.com/v2.6/me with locale' do
@options.merge!({ :locale => 'cs_CZ' })
@options.merge!({ locale: 'cs_CZ' })
strategy.stubs(:access_token).returns(@access_token)
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
params = {:params => @options}
params = {params: @options}
@access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
strategy.raw_info
end

test 'performs a GET to https://graph.facebook.com/v2.6/me with info_fields' do
@options.merge!({:info_fields => 'about'})
@options.merge!({info_fields: 'about'})
strategy.stubs(:access_token).returns(@access_token)
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
params = {:params => {:appsecret_proof => @appsecret_proof, :fields => 'about'}}
params = {params: {appsecret_proof: @appsecret_proof, fields: 'about'}}
@access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
strategy.raw_info
end

test 'performs a GET to https://graph.facebook.com/v2.6/me with default info_fields' do
strategy.stubs(:access_token).returns(@access_token)
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
params = {:params => {:appsecret_proof => @appsecret_proof, :fields => 'name,email'}}
params = {params: {appsecret_proof: @appsecret_proof, fields: 'name,email'}}
@access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
strategy.raw_info
end
Expand All @@ -300,7 +300,7 @@ def setup
raw_response.stubs(:status).returns(200)
raw_response.stubs(:headers).returns({'Content-Type' => 'application/json' })
oauth2_response = OAuth2::Response.new(raw_response)
params = {:params => @options}
params = {params: @options}
@access_token.stubs(:get).with('me', params).returns(oauth2_response)
assert_kind_of Hash, strategy.raw_info
assert_equal 'thar', strategy.raw_info['ohai']
Expand All @@ -309,16 +309,16 @@ def setup
test 'returns an empty hash when the response is false' do
strategy.stubs(:access_token).returns(@access_token)
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
oauth2_response = stub('OAuth2::Response', :parsed => false)
params = {:params => @options}
oauth2_response = stub('OAuth2::Response', parsed: false)
params = {params: @options}
@access_token.stubs(:get).with('me', params).returns(oauth2_response)
assert_kind_of Hash, strategy.raw_info
assert_equal({}, strategy.raw_info)
end

test 'should not include raw_info in extras hash when skip_info is specified' do
@options = { :skip_info => true }
strategy.stubs(:raw_info).returns({:foo => 'bar' })
@options = { skip_info: true }
strategy.stubs(:raw_info).returns({foo: 'bar' })
refute_has_key 'raw_info', strategy.extra
end
end
Expand Down
Loading

0 comments on commit edc2169

Please sign in to comment.