omniauth-linkedin 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,9 @@ require 'bundler/setup'
2
2
  require 'sinatra/base'
3
3
  require 'omniauth-linkedin'
4
4
 
5
+ ENV['LINKEDIN_CONSUMER_KEY'] = "eumx4m8w39qb"
6
+ ENV['LINKEDIN_CONSUMER_SECRET'] = "PczJNDDLYic6kQOL"
7
+
5
8
  class App < Sinatra::Base
6
9
  get '/' do
7
10
  redirect '/auth/linkedin'
@@ -18,7 +21,7 @@ class App < Sinatra::Base
18
21
  end
19
22
  end
20
23
 
21
- use Rack::Session::Cookie
24
+ use Rack::Session::Cookie, :secret => "change_me"
22
25
 
23
26
  use OmniAuth::Builder do
24
27
  #note that the scope is different from the default
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Linkedin
3
- VERSION = "0.0.8"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -19,14 +19,19 @@ module OmniAuth
19
19
  uid{ raw_info['id'] }
20
20
 
21
21
  info do
22
+ name = [raw_info['firstName'], raw_info['lastName']].compact.join(' ').strip || nil
23
+ name = nil_if_empty(name)
22
24
  {
25
+ :name => name,
23
26
  :email => raw_info['emailAddress'],
27
+ :nickname => name,
24
28
  :first_name => raw_info['firstName'],
25
29
  :last_name => raw_info['lastName'],
26
- :name => "#{raw_info['firstName']} #{raw_info['lastName']}",
27
- :headline => raw_info['headline'],
30
+ :location => parse_location(raw_info['location']),
28
31
  :description => raw_info['headline'],
29
32
  :image => raw_info['pictureUrl'],
33
+ :phone => nil,
34
+ :headline => raw_info['headline'],
30
35
  :industry => raw_info['industry'],
31
36
  :urls => {
32
37
  'public_profile' => raw_info['publicProfileUrl']
@@ -47,6 +52,33 @@ module OmniAuth
47
52
  options.request_params[:scope] = options.scope.gsub("+", " ")
48
53
  super
49
54
  end
55
+
56
+ private
57
+
58
+ def parse_location(location_hash = {})
59
+ location_hash ||= {}
60
+ location_name = extract_location_name(location_hash)
61
+ country_code = extract_country_code(location_hash)
62
+ build_location_value(location_name, country_code)
63
+ end
64
+
65
+ def extract_location_name(location_hash = {})
66
+ nil_if_empty(location_hash["name"])
67
+ end
68
+
69
+ def extract_country_code(location_hash = {})
70
+ country_hash = location_hash["country"] || {}
71
+ country_code = nil_if_empty(country_hash["code"])
72
+ country_code = (country_code ? country_code.upcase : nil)
73
+ end
74
+
75
+ def build_location_value(location_name, country_code)
76
+ nil_if_empty([location_name, country_code].compact.join(', '))
77
+ end
78
+
79
+ def nil_if_empty(value)
80
+ (value.nil? || value.empty?) ? nil : value
81
+ end
50
82
  end
51
83
  end
52
84
  end
@@ -36,4 +36,24 @@ describe "OmniAuth::Strategies::LinkedIn" do
36
36
  subject.uid.should eq('123')
37
37
  end
38
38
  end
39
+
40
+ context 'returns info hash conformant with omniauth auth hash schema' do
41
+ before :each do
42
+ subject.stub(:raw_info) { {} }
43
+ end
44
+
45
+ context 'and therefore has all the necessary fields' do
46
+ it {subject.info.should have_key :name}
47
+ it {subject.info.should have_key :name}
48
+ it {subject.info.should have_key :email}
49
+ it {subject.info.should have_key :nickname}
50
+ it {subject.info.should have_key :first_name}
51
+ it {subject.info.should have_key :last_name}
52
+ it {subject.info.should have_key :location}
53
+ it {subject.info.should have_key :description}
54
+ it {subject.info.should have_key :image}
55
+ it {subject.info.should have_key :phone}
56
+ it {subject.info.should have_key :urls}
57
+ end
58
+ end
39
59
  end
@@ -0,0 +1 @@
1
+ - need some more tests to make sure location can be parsed correctly
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-linkedin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-16 00:00:00.000000000 Z
12
+ date: 2013-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth-oauth
@@ -113,6 +113,7 @@ files:
113
113
  - omniauth-linkedin.gemspec
114
114
  - spec/omniauth/strategies/linkedin_spec.rb
115
115
  - spec/spec_helper.rb
116
+ - todo.txt
116
117
  homepage: https://github.com/skorks/omniauth-linkedin
117
118
  licenses: []
118
119
  post_install_message:
@@ -125,18 +126,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
126
  - - ! '>='
126
127
  - !ruby/object:Gem::Version
127
128
  version: '0'
129
+ segments:
130
+ - 0
131
+ hash: 2699125881048178184
128
132
  required_rubygems_version: !ruby/object:Gem::Requirement
129
133
  none: false
130
134
  requirements:
131
135
  - - ! '>='
132
136
  - !ruby/object:Gem::Version
133
137
  version: '0'
138
+ segments:
139
+ - 0
140
+ hash: 2699125881048178184
134
141
  requirements: []
135
142
  rubyforge_project:
136
- rubygems_version: 1.8.21
143
+ rubygems_version: 1.8.24
137
144
  signing_key:
138
145
  specification_version: 3
139
146
  summary: LinkedIn strategy for OmniAuth.
140
- test_files:
141
- - spec/omniauth/strategies/linkedin_spec.rb
142
- - spec/spec_helper.rb
147
+ test_files: []