diff --git a/lib/omniauth/strategies/linkedin.rb b/lib/omniauth/strategies/linkedin.rb index b6efb09..8987dca 100755 --- a/lib/omniauth/strategies/linkedin.rb +++ b/lib/omniauth/strategies/linkedin.rb @@ -93,7 +93,9 @@ def fields end def localized_field field_name - raw_info.dig(*[field_name, 'localized', field_locale(field_name)]) + return unless localized_field_available? field_name + + raw_info[field_name]['localized'][field_locale(field_name)] end def field_locale field_name @@ -101,6 +103,10 @@ def field_locale field_name "#{ raw_info[field_name]['preferredLocale']['country'] }" end + def localized_field_available? field_name + raw_info[field_name] && raw_info[field_name]['localized'] + end + def picture_url return unless picture_available? diff --git a/spec/omniauth/strategies/linkedin_spec.rb b/spec/omniauth/strategies/linkedin_spec.rb index 7a4e89b..9838d63 100755 --- a/spec/omniauth/strategies/linkedin_spec.rb +++ b/spec/omniauth/strategies/linkedin_spec.rb @@ -110,23 +110,4 @@ end end end - - describe '#localized_field' do - let(:raw_info) do - { - 'foo' => { - 'preferredLocale' => { - 'language' => 'bar', - 'country' => 'BAZ' - } - } - } - end - - before :each do - allow(subject).to receive(:raw_info).and_return raw_info - end - - specify { expect(subject.send(:field_locale,'foo')).to eq 'bar_BAZ' } - end end