-
Notifications
You must be signed in to change notification settings - Fork 402
Expand file tree
/
Copy pathapi_spec.rb
More file actions
320 lines (260 loc) · 13.6 KB
/
api_spec.rb
File metadata and controls
320 lines (260 loc) · 13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
require 'helper'
describe LinkedIn::Api do
before do
LinkedIn.default_profile_fields = nil
client.stub(:consumer).and_return(consumer)
client.authorize_from_access('atoken', 'asecret')
end
let(:client){LinkedIn::Client.new('token', 'secret')}
let(:consumer){OAuth::Consumer.new('token', 'secret', {:site => 'https://api.linkedin.com'})}
it "should be able to view the account profile" do
stub_request(:get, "https://api.linkedin.com/v1/people/~").to_return(:body => "{}")
client.profile.should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to view public profiles" do
stub_request(:get, "https://api.linkedin.com/v1/people/id=123").to_return(:body => "{}")
client.profile(:id => 123).should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to view the picture urls" do
stub_request(:get, "https://api.linkedin.com/v1/people/~/picture-urls::(original)").to_return(:body => "{}")
client.picture_urls.should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to view connections" do
stub_request(:get, "https://api.linkedin.com/v1/people/~/connections").to_return(:body => "{}")
client.connections.should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to view new connections" do
modified_since = Time.now.to_i * 1000
stub_request(:get, "https://api.linkedin.com/v1/people/~/connections?modified=new&modified-since=#{modified_since}").to_return(:body => "{}")
client.new_connections(modified_since).should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to view network_updates" do
stub_request(:get, "https://api.linkedin.com/v1/people/~/network/updates").to_return(:body => "{}")
client.network_updates.should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to view network_update's comments" do
stub_request(:get, "https://api.linkedin.com/v1/people/~/network/updates/key=network_update_key/update-comments").to_return(:body => "{}")
client.share_comments("network_update_key").should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to view network_update's likes" do
stub_request(:get, "https://api.linkedin.com/v1/people/~/network/updates/key=network_update_key/likes").to_return(:body => "{}")
client.share_likes("network_update_key").should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to search with a keyword if given a String" do
stub_request(:get, "https://api.linkedin.com/v1/people-search?keywords=business").to_return(:body => "{}")
client.search("business").should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to search with an option" do
stub_request(:get, "https://api.linkedin.com/v1/people-search?first-name=Javan").to_return(:body => "{}")
client.search(:first_name => "Javan").should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to search with an option and fetch specific fields" do
stub_request(:get, "https://api.linkedin.com/v1/people-search:(num-results,total)?first-name=Javan").to_return(
:body => "{}")
client.search(:first_name => "Javan", :fields => ["num_results", "total"]).should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to share a new status" do
stub_request(:post, "https://api.linkedin.com/v1/people/~/shares").to_return(:body => "", :status => 201)
response = client.add_share(:comment => "Testing, 1, 2, 3")
response.body.should == nil
response.code.should == "201"
end
it "should be able to share a new company status" do
stub_request(:post, "https://api.linkedin.com/v1/companies/123456/shares").to_return(:body => "", :status => 201)
response = client.add_company_share("123456", { :comment => "Testing, 1, 2, 3" })
response.body.should == nil
response.code.should == "201"
end
it "returns the shares for a person" do
stub_request(:get, "https://api.linkedin.com/v1/people/~/network/updates?type=SHAR&scope=self&after=1234&count=35").to_return(
:body => "{}")
client.shares(:after => 1234, :count => 35)
end
it "should be able to comment on network update" do
stub_request(:post, "https://api.linkedin.com/v1/people/~/network/updates/key=SOMEKEY/update-comments").to_return(
:body => "", :status => 201)
response = client.update_comment('SOMEKEY', "Testing, 1, 2, 3")
response.body.should == nil
response.code.should == "201"
end
it "should be able to like a network update" do
stub_request(:put, "https://api.linkedin.com/v1/people/~/network/updates/key=SOMEKEY/is-liked").
with(:body => "true").to_return(:body => "", :status => 201)
response = client.like_share('SOMEKEY')
response.body.should == nil
response.code.should == "201"
end
it "should be able to unlike a network update" do
stub_request(:put, "https://api.linkedin.com/v1/people/~/network/updates/key=SOMEKEY/is-liked").
with(:body => "false").to_return(:body => "", :status => 201)
response = client.unlike_share('SOMEKEY')
response.body.should == nil
response.code.should == "201"
end
it "should be able to pass down the additional arguments to OAuth's get_request_token" do
consumer.should_receive(:get_request_token).with(
{:oauth_callback => "http://localhost:3000/auth/callback"}, :scope => "rw_nus").and_return("request_token")
request_token = client.request_token(
{:oauth_callback => "http://localhost:3000/auth/callback"}, :scope => "rw_nus"
)
request_token.should == "request_token"
end
context "Company API" do
use_vcr_cassette
it "should be able to view a company profile" do
stub_request(:get, "https://api.linkedin.com/v1/companies/id=1586").to_return(:body => "{}")
client.company(:id => 1586).should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to view a company by universal name" do
stub_request(:get, "https://api.linkedin.com/v1/companies/universal-name=acme").to_return(:body => "{}")
client.company(:name => 'acme').should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to view a company by e-mail domain" do
stub_request(:get, "https://api.linkedin.com/v1/companies?email-domain=acme.com").to_return(:body => "{}")
client.company(:domain => 'acme.com').should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to view a user's company pages" do
stub_request(:get, "https://api.linkedin.com/v1/companies?is-company-admin=true").to_return(:body => "{}")
client.company(:is_admin => 'true').should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to page a user's company pages" do
stub_request(:get, "https://api.linkedin.com/v1/companies?is-company-admin=true&count=10&start=0").to_return(:body => "{}")
client.company(:is_admin => 'true', :count => 10, :start => 0).should be_an_instance_of(LinkedIn::Mash)
end
it "should load correct company data" do
client.company(:id => 1586).name.should == "Amazon"
data = client.company(:id => 1586, :fields => %w{ id name industry locations:(address:(city state country-code) is-headquarters) employee-count-range })
data.id.should == 1586
data.name.should == "Amazon"
data.employee_count_range.name.should == "10001+"
data.industry.should == "Internet"
data.locations.all[0].address.city.should == "Seattle"
data.locations.all[0].is_headquarters.should == true
end
it "should be able to view company_updates" do
stub_request(:get, "https://api.linkedin.com/v1/companies/id=1586/updates").to_return(:body => "{}")
client.company_updates(:id => 1586).should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to view company_statistic" do
stub_request(:get, "https://api.linkedin.com/v1/companies/id=1586/company-statistics").to_return(:body => "{}")
client.company_statistics(:id => 1586).should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to view company updates comments" do
stub_request(:get, "https://api.linkedin.com/v1/companies/id=1586/updates/key=company_update_key/update-comments").to_return(:body => "{}")
client.company_updates_comments("company_update_key", :id => 1586).should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to view company updates likes" do
stub_request(:get, "https://api.linkedin.com/v1/companies/id=1586/updates/key=company_update_key/likes").to_return(:body => "{}")
client.company_updates_likes("company_update_key", :id => 1586).should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to follow a company" do
stub_request(:post, "https://api.linkedin.com/v1/people/~/following/companies").to_return(:body => "", :status => 201)
response = client.follow_company(1586)
response.body.should == nil
response.code.should == "201"
end
it "should be able to unfollow a company" do
stub_request(:delete, "https://api.linkedin.com/v1/people/~/following/companies/id=1586").to_return(:body => "", :status => 201)
response = client.unfollow_company(1586)
response.body.should == nil
response.code.should == "201"
end
end
context "Job API" do
use_vcr_cassette
it "should be able to view a job listing" do
stub_request(:get, "https://api.linkedin.com/v1/jobs/id=1586").to_return(:body => "{}")
client.job(:id => 1586).should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to view its job bookmarks" do
stub_request(:get, "https://api.linkedin.com/v1/people/~/job-bookmarks").to_return(:body => "{}")
client.job_bookmarks.should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to view its job suggestion" do
stub_request(:get, "https://api.linkedin.com/v1/people/~/suggestions/job-suggestions").to_return(:body => "{}")
client.job_suggestions.should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to add a bookmark" do
stub_request(:post, "https://api.linkedin.com/v1/people/~/job-bookmarks").to_return(:body => "", :status => 201)
response = client.add_job_bookmark(:id => 1452577)
response.body.should == nil
response.code.should == "201"
end
end
context "Group API" do
it "should be able to list group memberships for a profile" do
stub_request(:get, "https://api.linkedin.com/v1/people/~/group-memberships").to_return(:body => "{}")
client.group_memberships.should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to list suggested groups for a profile" do
stub_request(:get, "https://api.linkedin.com/v1/people/~/suggestions/groups").to_return(:body => '{"id": "123"}')
response = client.group_suggestions
response.id.should == '123'
end
it "should be able to parse nested fields" do
stub_request(:get, "https://api.linkedin.com/v1/people/~/group-memberships:(group:(id,name,small-logo-url,short-description))").to_return(:body => "{}")
client.group_memberships(:fields => [{:group => ['id', 'name', 'small-logo-url', 'short-description']}]).should be_an_instance_of(LinkedIn::Mash)
end
it "should be able to join a group" do
stub_request(:put, "https://api.linkedin.com/v1/people/~/group-memberships/123").to_return(:body => "", :status => 201)
response = client.join_group(123)
response.body.should == nil
response.code.should == "201"
end
context '#group_profile' do
let(:options) do
{:id => 123}
end
before do
stub_request(:get, "https://api.linkedin.com/v1/groups/123").to_return(:body => '{"id": "123"}')
end
it "doesn't mangle the options hash with group_profile" do
original_options = options.dup
client.group_profile(options)
options.should == original_options
end
it "lists a group profile" do
response = client.group_profile(options)
response.id.should == options.fetch(:id).to_s
end
end
it "should be able to list group posts" do
stub_request(:get, "https://api.linkedin.com/v1/groups/123/posts").to_return(:body => '{"id": "123"}')
response = client.group_posts(:id => 123)
response.id.should == '123'
end
it 'should be able to post a discussion to a group' do
expected = {
'title' => 'New Discussion',
'summary' => 'New Summary',
'content' => {
"submitted-url" => "http://www.google.com"
}
}
stub_request(:post, "https://api.linkedin.com/v1/groups/123/posts").with(:body => expected).to_return(:body => "", :status => 201)
response = client.post_group_discussion(123, expected)
response.body.should == nil
response.code.should == '201'
end
it "should be able to share a new group status" do
stub_request(:post, "https://api.linkedin.com/v1/groups/1/posts").to_return(:body => "", :status => 201)
response = client.add_group_share(1, :comment => "Testing, 1, 2, 3")
response.body.should == nil
response.code.should == "201"
end
end
context "Communication API" do
it "should be able to send a message" do
stub_request(:post, "https://api.linkedin.com/v1/people/~/mailbox").to_return(:body => "", :status => 201)
response = client.send_message("subject", "body", ["recip1", "recip2"])
response.body.should == nil
response.code.should == "201"
end
end
context "Errors" do
it "should raise AccessDeniedError when LinkedIn returns 403 status code" do
stub_request(:get, "https://api.linkedin.com/v1/people-search?first-name=Javan").to_return(:body => "{}", :status => 403)
expect{ client.search(:first_name => "Javan") }.to raise_error(LinkedIn::Errors::AccessDeniedError)
end
end
end