Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supported :image_size as Symbol in authentication options #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/omniauth/strategies/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ def request_phase

def image_url
original_url = options[:secure_image_url] ? raw_info['profile_image_url_https'] : raw_info['profile_image_url']
case options[:image_size]
## Allowing :image_size to specify as Symbol
# Converting :image_size to String if :image_size is non String
image_size = options[:image_size].is_a?(String) ? options[:image_size] : options[:image_size].to_s
case image_size
when 'mini'
original_url.sub('normal', 'mini')
when 'bigger'
Expand Down
8 changes: 8 additions & 0 deletions spec/omniauth/strategies/twitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
)
expect(subject.info[:image]).to eq('http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0.png')
end

it 'should return image when size specified as Symbol' do
@options = { image_size: :original }
allow(subject).to receive(:raw_info).and_return(
{ 'profile_image_url' => 'http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' }
)
expect(subject.info[:image]).to eq('http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0.png')
end

it 'should return bigger image when bigger size specified' do
@options = { :image_size => 'bigger' }
Expand Down