linkedin-oauth2 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,130 @@
1
+ require 'helper'
2
+
3
+ describe "LinkedIn::Client" do
4
+
5
+ let(:client) do
6
+ client_id = ENV['LINKED_IN_CLIENT_KEY'] || 'stub_client_id'
7
+ client_secret = ENV['LINKED_IN_CLIENT_SECRET'] || 'stub_client_secret'
8
+ LinkedIn::Client.new(client_id, client_secret)
9
+ end
10
+
11
+ let(:authed_client) do
12
+ client_id = ENV['LINKED_IN_CLIENT_KEY'] || 'stub_client_id'
13
+ client_secret = ENV['LINKED_IN_CLIENT_SECRET'] || 'stub_client_secret'
14
+ access_token = ENV['LINKED_IN_ACCESS_TOKEN'] || 'stub_access_token'
15
+ LinkedIn::Client.new(client_id, client_secret, access_token)
16
+ end
17
+
18
+ describe "#oauth2_client" do
19
+ describe "default oauth options" do
20
+ let(:oauth2_client) { client.oauth2_client }
21
+
22
+ it "should return a configured OAuth oauth2_client" do
23
+ oauth2_client.site.should == 'https://api.linkedin.com'
24
+ oauth2_client.token_url.should == "https://www.linkedin.com/uas/oauth2/accessToken"
25
+ oauth2_client.authorize_url.should == "https://www.linkedin.com/uas/oauth2/authorization"
26
+ end
27
+ end
28
+
29
+ describe "different api and auth hosts options" do
30
+ let(:oauth2_client) do
31
+ LinkedIn::Client.new('1234', '1234', {
32
+ :token_url => 'https://token-url.com',
33
+ :authorize_url => 'https://authorize-url.com',
34
+ :site => "https://foo.com"
35
+ }).oauth2_client
36
+ end
37
+
38
+ it "should return a configured OAuth oauth2_client" do
39
+ oauth2_client.site.should == 'https://foo.com'
40
+ oauth2_client.token_url.should == "https://token-url.com"
41
+ oauth2_client.authorize_url.should == "https://authorize-url.com"
42
+ end
43
+ end
44
+
45
+ describe "different oauth paths" do
46
+ let(:oauth2_client) do
47
+ LinkedIn::Client.new('1234', '1234', {
48
+ :authorize_path => "/secure/oauth/authorize",
49
+ :access_token_path => "/secure/oauth/accessToken",
50
+ }).oauth2_client
51
+ end
52
+
53
+ it "should return a configured OAuth oauth2_client" do
54
+ oauth2_client.site.should == 'https://api.linkedin.com'
55
+ oauth2_client.token_url.should == "https://www.linkedin.com/uas/oauth2/accessToken"
56
+ oauth2_client.authorize_url.should == "https://www.linkedin.com/uas/oauth2/authorization"
57
+ end
58
+ end
59
+
60
+ describe "specify oauth urls" do
61
+ let(:oauth2_client) do
62
+ LinkedIn::Client.new('1234', '1234', {
63
+ :token_url => "https://api.josh.com/secure/oauth/requestToken",
64
+ :authorize_url => "https://api.josh.com/secure/oauth/accessToken",
65
+ }).oauth2_client
66
+ end
67
+
68
+ it "should return a configured OAuth oauth2_client" do
69
+ oauth2_client.site.should == 'https://api.linkedin.com'
70
+ oauth2_client.token_url.should == "https://api.josh.com/secure/oauth/requestToken"
71
+ # oauth2_client.authorize_url.should == "https://www.linkedin.com/uas/oauth2/authorization"
72
+ end
73
+ end
74
+
75
+ describe "use the :site option to specify the host of all oauth urls" do
76
+ let(:oauth2_client) do
77
+ LinkedIn::Client.new('1234', '1234', {
78
+ :site => "https://api.josh.com"
79
+ }).oauth2_client
80
+ end
81
+
82
+ it "should return a configured OAuth oauth2_client" do
83
+ oauth2_client.site.should == 'https://api.josh.com'
84
+ oauth2_client.token_url.should == "https://www.linkedin.com/uas/oauth2/accessToken"
85
+ # oauth2_client.authorize_url.should == "https://www.linkedin.com/uas/oauth2/authorization"
86
+ end
87
+ end
88
+ end
89
+
90
+ # describe "#request_access_token" do
91
+ # before(:each) do
92
+ # stub_request(:post, "https://www.linkedin.com/uas/oauth/accessToken?oauth2_access_token=#{client.access_token.token}").to_return(body: {access_token: "stub_access_token"})
93
+ # end
94
+
95
+ # describe "with default options" do
96
+ # use_vcr_cassette :record => :new_episodes
97
+
98
+ # it "should return a valid request token" do
99
+ # access_token = client.request_access_token("stub_code")
100
+ # a_request(:post, "https://www.linkedin.com/uas/oauth/accessToken").should have_been_made.once
101
+ # access_token.should be_a_kind_of OAuth2::AccessToken
102
+ # end
103
+ # end
104
+
105
+ # describe "with a callback url" do
106
+ # use_vcr_cassette :record => :new_episodes
107
+
108
+ # it "should return a valid access token" do
109
+ # access_token = client.request_access_token("stub_code", redirect_uri: 'http://www.josh.com')
110
+ # a_request(:post, "https://www.linkedin.com/uas/oauth/accessToken").should have_been_made.once
111
+ # access_token.should be_a_kind_of OAuth2::RequestToken
112
+
113
+ # access_token.callback_confirmed?.should == true
114
+
115
+ # end
116
+ # end
117
+ # end
118
+
119
+ describe "#access_token" do
120
+ let(:access_token) do
121
+ authed_client.access_token
122
+ end
123
+
124
+ it "should return a valid auth token" do
125
+ access_token.should be_a_kind_of OAuth2::AccessToken
126
+ access_token.token.should be_a_kind_of String
127
+ end
128
+ end
129
+
130
+ end
@@ -0,0 +1,190 @@
1
+ require 'helper'
2
+
3
+ describe LinkedIn::Search do
4
+
5
+ # if you remove the related cassettes you will need to inform valid
6
+ # tokens and secrets to regenerate them
7
+ #
8
+ let(:client) do
9
+ client_id = ENV['LINKED_IN_CLIENT_ID'] || 'stub_client_id'
10
+ client_secret = ENV['LINKED_IN_CLIENT_SECRET'] || 'stub_client_secret'
11
+ access_token = ENV['LINKED_IN_ACCESS_TOKEN'] || 'stub_access_token'
12
+ LinkedIn::Client.new(client_id, client_secret, access_token)
13
+ end
14
+
15
+ describe "#search_company" do
16
+ use_vcr_cassette record: :none
17
+
18
+ describe "by keywords string parameter" do
19
+
20
+ let(:results) do
21
+ client.search('apple', :company)
22
+ end
23
+
24
+ it "should perform a company search" do
25
+ results.companies.all.size.should == 10
26
+ results.companies.all.first.name.should == 'Apple'
27
+ results.companies.all.first.id.should == 162479
28
+ end
29
+ end
30
+
31
+ describe "by single keywords option" do
32
+
33
+ let(:results) do
34
+ options = {:keywords => 'apple'}
35
+ client.search(options, :company)
36
+ end
37
+
38
+ it "should perform a company search" do
39
+ results.companies.all.size.should == 10
40
+ results.companies.all.first.name.should == 'Apple'
41
+ results.companies.all.first.id.should == 162479
42
+ end
43
+ end
44
+
45
+ describe "by single keywords option with facets to return" do
46
+
47
+ let(:results) do
48
+ options = {:keywords => 'apple', :facets => [:industry]}
49
+ client.search(options, :company)
50
+ end
51
+
52
+ it "should return a facet" do
53
+ results.facets.all.first.buckets.all.first.name.should == 'Information Technology and Services'
54
+ end
55
+ end
56
+
57
+ describe "by single keywords option with pagination" do
58
+
59
+ let(:results) do
60
+ options = {:keywords => 'apple', :start => 5, :count => 5}
61
+ client.search(options, :company)
62
+ end
63
+
64
+ it "should perform a search" do
65
+ results.companies.all.size.should == 5
66
+ results.companies.all.first.name.should == 'iSquare - Apple Authorized Distributor in Greece & Cyprus'
67
+ results.companies.all.first.id.should == 2135525
68
+ results.companies.all.last.name.should == 'Apple Crumble'
69
+ results.companies.all.last.id.should == 1049054
70
+ end
71
+ end
72
+
73
+ describe "by keywords options with fields" do
74
+
75
+ let(:results) do
76
+ fields = [{:companies => [:id, :name, :industries, :description, :specialties]}, :num_results]
77
+ client.search({:keywords => 'apple', :fields => fields}, 'company')
78
+ end
79
+
80
+ it "should perform a search" do
81
+ results.companies.all.first.name.should == 'Apple'
82
+ results.companies.all.first.description.should == 'Apple designs Macs, the best personal computers in the world, along with OS X, iLife, iWork and professional software. Apple leads the digital music revolution with its iPods and iTunes online store. Apple has reinvented the mobile phone with its revolutionary iPhone and App Store, and is defining the future of mobile media and computing devices with iPad.'
83
+ results.companies.all.first.id.should == 162479
84
+ end
85
+ end
86
+
87
+ end
88
+
89
+ describe "#search" do
90
+
91
+ describe "by keywords string parameter" do
92
+
93
+ let(:results) do
94
+ client.search('github')
95
+ end
96
+
97
+ it "should perform a search" do
98
+ results.people.all.size.should == 6
99
+ results.people.all.first.first_name.should == 'Shay'
100
+ results.people.all.first.last_name.should == 'Frendt'
101
+ results.people.all.first.id.should == 'ucXjUw4M9J'
102
+ end
103
+ end
104
+
105
+ describe "by single keywords option" do
106
+
107
+ let(:results) do
108
+ client.search(:keywords => 'github')
109
+ end
110
+
111
+ it "should perform a search" do
112
+ results.people.all.size.should == 6
113
+ results.people.all.first.first_name.should == 'Shay'
114
+ results.people.all.first.last_name.should == 'Frendt'
115
+ results.people.all.first.id.should == 'ucXjUw4M9J'
116
+ end
117
+ end
118
+
119
+ describe "by single keywords option with pagination" do
120
+
121
+ let(:results) do
122
+ client.search(:keywords => 'github', :start => 5, :count => 5)
123
+ end
124
+
125
+ it "should perform a search" do
126
+ results.people.all.size.should == 1
127
+ results.people.all.first.first_name.should == 'Satish'
128
+ results.people.all.first.last_name.should == 'Talim'
129
+ results.people.all.first.id.should == 'V1FPuGot-I'
130
+ end
131
+ end
132
+
133
+ describe "by first_name and last_name options" do
134
+
135
+ let(:results) do
136
+ client.search(:first_name => 'Charles', :last_name => 'Garcia')
137
+ end
138
+
139
+ it "should perform a search" do
140
+ results.people.all.size.should == 10
141
+ results.people.all.first.first_name.should == 'Charles'
142
+ results.people.all.first.last_name.should == 'Garcia, CFA'
143
+ results.people.all.first.id.should == '2zk34r8TvA'
144
+ end
145
+ end
146
+
147
+ describe "by first_name and last_name options with fields" do
148
+
149
+ let(:results) do
150
+ fields = [{:people => [:id, :first_name, :last_name, :public_profile_url, :picture_url]}, :num_results]
151
+ client.search(:first_name => 'Charles', :last_name => 'Garcia', :fields => fields)
152
+ end
153
+
154
+ it "should perform a search" do
155
+ first_person = results.people.all.first
156
+ results.people.all.size.should == 10
157
+ first_person.first_name.should == 'Charles'
158
+ first_person.last_name.should == 'Garcia, CFA'
159
+ first_person.id.should == '2zk34r8TvA'
160
+ first_person.picture_url.should be_nil
161
+ first_person.public_profile_url.should == 'http://www.linkedin.com/in/charlesgarcia'
162
+ end
163
+ end
164
+
165
+ describe "by company_name option" do
166
+
167
+ let(:results) do
168
+ client.search(:company_name => 'IBM')
169
+ end
170
+
171
+ it "should perform a search" do
172
+ results.people.all.size.should == 6
173
+ results.people.all.first.first_name.should == 'Ryan'
174
+ results.people.all.first.last_name.should == 'Sue'
175
+ results.people.all.first.id.should == 'KHkgwBMaa-'
176
+ end
177
+ end
178
+
179
+ describe "#field_selector" do
180
+ it "should not modify the parameter object" do
181
+ fields = [{:people => [:id, :first_name]}]
182
+ fields_dup = fields.dup
183
+ client.send(:field_selector, fields)
184
+ fields.should eq fields_dup
185
+ end
186
+ end
187
+
188
+ end
189
+
190
+ end
@@ -0,0 +1,30 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'linkedin-oauth2'
6
+ require 'rspec'
7
+ require 'webmock/rspec'
8
+ require 'vcr'
9
+
10
+ VCR.config do |c|
11
+ c.cassette_library_dir = 'spec/fixtures/cassette_library'
12
+ c.stub_with :webmock
13
+ c.ignore_localhost = true
14
+ c.default_cassette_options = { :record => :none }
15
+ end
16
+
17
+ RSpec.configure do |c|
18
+ c.extend VCR::RSpec::Macros
19
+ end
20
+
21
+ def linkedin_url(url)
22
+ url =~ /^http/ ? url : "https://api.linkedin.com#{url}"
23
+ end
24
+
25
+ def expect_post(url, body, result = nil)
26
+ a_request(:post, linkedin_url(url)).with({
27
+ :body => fixture(body).read,
28
+ :headers => { :content_type => 'application/xml' }
29
+ }).should have_been_made.once
30
+ end
metadata ADDED
@@ -0,0 +1,236 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: linkedin-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Evan Morikawa
8
+ - Wynn Netherland
9
+ - Josh Kalderimis
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-07-30 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hashie
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '1.2'
22
+ - - <
23
+ - !ruby/object:Gem::Version
24
+ version: '2.1'
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '1.2'
32
+ - - <
33
+ - !ruby/object:Gem::Version
34
+ version: '2.1'
35
+ - !ruby/object:Gem::Dependency
36
+ name: multi_json
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '1.0'
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '1.0'
49
+ - !ruby/object:Gem::Dependency
50
+ name: oauth2
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '0.8'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '0.8'
63
+ - !ruby/object:Gem::Dependency
64
+ name: json
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.6'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '1.6'
77
+ - !ruby/object:Gem::Dependency
78
+ name: rake
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: '0.9'
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: '0.9'
91
+ - !ruby/object:Gem::Dependency
92
+ name: rdoc
93
+ requirement: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: '3.8'
98
+ type: :development
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ version: '3.8'
105
+ - !ruby/object:Gem::Dependency
106
+ name: rspec
107
+ requirement: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: '2.6'
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: '2.6'
119
+ - !ruby/object:Gem::Dependency
120
+ name: simplecov
121
+ requirement: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '0.5'
126
+ type: :development
127
+ prerelease: false
128
+ version_requirements: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ~>
131
+ - !ruby/object:Gem::Version
132
+ version: '0.5'
133
+ - !ruby/object:Gem::Dependency
134
+ name: vcr
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ~>
138
+ - !ruby/object:Gem::Version
139
+ version: '1.10'
140
+ type: :development
141
+ prerelease: false
142
+ version_requirements: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ~>
145
+ - !ruby/object:Gem::Version
146
+ version: '1.10'
147
+ - !ruby/object:Gem::Dependency
148
+ name: webmock
149
+ requirement: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ~>
152
+ - !ruby/object:Gem::Version
153
+ version: '1.9'
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ~>
159
+ - !ruby/object:Gem::Version
160
+ version: '1.9'
161
+ description: Ruby wrapper for the LinkedIn OAuth 2.0 API
162
+ email:
163
+ - evan@evanmorikawa.com
164
+ - wynn.netherland@gmail.com
165
+ - josh.kalderimis@gmail.com
166
+ executables: []
167
+ extensions: []
168
+ extra_rdoc_files: []
169
+ files:
170
+ - .autotest
171
+ - .document
172
+ - .gemtest
173
+ - .gitignore
174
+ - .rspec
175
+ - .ruby-gemset
176
+ - .ruby-version
177
+ - .travis.yml
178
+ - Gemfile
179
+ - LICENSE
180
+ - README.markdown
181
+ - Rakefile
182
+ - changelog.markdown
183
+ - examples/authenticate.rb
184
+ - examples/network.rb
185
+ - examples/profile.rb
186
+ - examples/sinatra.rb
187
+ - examples/status.rb
188
+ - lib/linked_in/api.rb
189
+ - lib/linked_in/api/query_methods.rb
190
+ - lib/linked_in/api/update_methods.rb
191
+ - lib/linked_in/client.rb
192
+ - lib/linked_in/errors.rb
193
+ - lib/linked_in/helpers.rb
194
+ - lib/linked_in/helpers/authorization.rb
195
+ - lib/linked_in/helpers/request.rb
196
+ - lib/linked_in/mash.rb
197
+ - lib/linked_in/search.rb
198
+ - lib/linked_in/version.rb
199
+ - lib/linkedin-oauth2.rb
200
+ - linkedin-oauth2.gemspec
201
+ - spec/cases/api_spec.rb
202
+ - spec/cases/linkedin_spec.rb
203
+ - spec/cases/mash_spec.rb
204
+ - spec/cases/oauth_spec.rb
205
+ - spec/cases/search_spec.rb
206
+ - spec/helper.rb
207
+ homepage: http://github.com/emorikawa/linkedin-oauth2
208
+ licenses: []
209
+ metadata: {}
210
+ post_install_message:
211
+ rdoc_options: []
212
+ require_paths:
213
+ - lib
214
+ required_ruby_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - ! '>='
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ required_rubygems_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ! '>='
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ requirements: []
225
+ rubyforge_project:
226
+ rubygems_version: 2.0.6
227
+ signing_key:
228
+ specification_version: 4
229
+ summary: Ruby wrapper for the LinkedIn OAuth 2.0 API
230
+ test_files:
231
+ - spec/cases/api_spec.rb
232
+ - spec/cases/linkedin_spec.rb
233
+ - spec/cases/mash_spec.rb
234
+ - spec/cases/oauth_spec.rb
235
+ - spec/cases/search_spec.rb
236
+ - spec/helper.rb