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

add email in response closes #95 #96

Merged
merged 3 commits into from
Jun 21, 2015
Merged
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
3 changes: 2 additions & 1 deletion lib/omniauth/strategies/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Twitter < OmniAuth::Strategies::OAuth
{
:nickname => raw_info['screen_name'],
:name => raw_info['name'],
:email => raw_info["email"],
:location => raw_info['location'],
:image => image_url,
:description => raw_info['description'],
Expand All @@ -31,7 +32,7 @@ class Twitter < OmniAuth::Strategies::OAuth
end

def raw_info
@raw_info ||= JSON.load(access_token.get('/1.1/account/verify_credentials.json?include_entities=false&skip_status=true').body)
@raw_info ||= JSON.load(access_token.get('/1.1/account/verify_credentials.json?include_entities=false&skip_status=true&include_email=true').body)
rescue ::Errno::ETIMEDOUT
raise ::Timeout::Error
end
Expand Down
44 changes: 44 additions & 0 deletions spec/omniauth/strategies/twitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,37 @@
end
end

describe 'info' do
before do
allow(subject).to receive(:raw_info).and_return(raw_info_hash)
end

it 'should returns the nickname' do
expect(subject.info[:nickname]).to eq(raw_info_hash['screen_name'])
end

it 'should returns the name' do
expect(subject.info[:name]).to eq(raw_info_hash['name'])
end

it 'should returns the email' do
expect(subject.info[:email]).to eq(raw_info_hash['email'])
end

it 'should returns the location' do
expect(subject.info[:location]).to eq(raw_info_hash['location'])
end

it 'should returns the description' do
expect(subject.info[:description]).to eq(raw_info_hash['description'])
end

it 'should returns the urls' do
expect(subject.info[:urls]['Website']).to eq(raw_info_hash['url'])
expect(subject.info[:urls]['Twitter']).to eq("https://twitter.com/#{raw_info_hash['screen_name']}")
end
end

describe 'image_size option' do
context 'when user has an image' do
it 'should return image with size specified' do
Expand Down Expand Up @@ -113,3 +144,16 @@
end
end
end

private

def raw_info_hash
{
'screen_name' => 'foo',
'name' => 'Foo Bar',
'email' => 'foo@example.com',
'location' => 'India',
'description' => 'Developer',
'url' => 'example.com/foobar'
}
end