linkedin-oauth2 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +9 -9
  2. data/.gitignore +24 -39
  3. data/.travis.yml +4 -4
  4. data/.yardopts +2 -0
  5. data/CHANGELOG.md +10 -0
  6. data/CONTRIBUTING.md +1 -0
  7. data/Gemfile +6 -5
  8. data/LICENSE +19 -17
  9. data/README.md +399 -0
  10. data/Rakefile +15 -22
  11. data/lib/linked_in/access_token.rb +24 -0
  12. data/lib/linked_in/api.rb +96 -3
  13. data/lib/linked_in/api_resource.rb +165 -0
  14. data/lib/linked_in/communications.rb +40 -0
  15. data/lib/linked_in/companies.rb +146 -0
  16. data/lib/linked_in/configuration.rb +41 -0
  17. data/lib/linked_in/connection.rb +31 -0
  18. data/lib/linked_in/errors.rb +33 -13
  19. data/lib/linked_in/groups.rb +116 -0
  20. data/lib/linked_in/jobs.rb +68 -0
  21. data/lib/linked_in/mash.rb +34 -34
  22. data/lib/linked_in/oauth2.rb +223 -0
  23. data/lib/linked_in/people.rb +141 -0
  24. data/lib/linked_in/search.rb +58 -43
  25. data/lib/linked_in/share_and_social_stream.rb +128 -0
  26. data/lib/linked_in/version.rb +1 -9
  27. data/lib/linkedin-oauth2.rb +43 -25
  28. data/linkedin-oauth2.gemspec +35 -21
  29. data/spec/linked_in/api/api_spec.rb +41 -0
  30. data/spec/linked_in/api/communications_spec.rb +13 -0
  31. data/spec/linked_in/api/companies_spec.rb +59 -0
  32. data/spec/linked_in/api/groups_spec.rb +55 -0
  33. data/spec/linked_in/api/jobs_spec.rb +33 -0
  34. data/spec/linked_in/api/people_spec.rb +181 -0
  35. data/spec/linked_in/api/search_spec.rb +71 -0
  36. data/spec/linked_in/api/share_and_social_stream_spec.rb +60 -0
  37. data/spec/linked_in/configuration_spec.rb +46 -0
  38. data/spec/linked_in/connection_spec.rb +10 -0
  39. data/spec/linked_in/module_loading_spec.rb +23 -0
  40. data/spec/linked_in/oauth/access_token_spec.rb +27 -0
  41. data/spec/linked_in/oauth/auth_code_spec.rb +86 -0
  42. data/spec/linked_in/oauth/credentials_spec.rb +96 -0
  43. data/spec/linked_in/oauth/get_access_token_spec.rb +108 -0
  44. data/spec/spec_helper.rb +15 -0
  45. data/spec/vcr_cassettes/access_token_success.yml +84 -0
  46. data/spec/vcr_cassettes/bad_code.yml +78 -0
  47. data/spec/vcr_cassettes/companies_data.yml +44 -0
  48. data/spec/vcr_cassettes/invalid_access_token.yml +60 -0
  49. data/spec/vcr_cassettes/not_found.yml +64 -0
  50. data/spec/vcr_cassettes/people_picture_urls.yml +54 -0
  51. data/spec/vcr_cassettes/people_profile_connections_fields.yml +73 -0
  52. data/spec/vcr_cassettes/people_profile_connections_other.yml +78 -0
  53. data/spec/vcr_cassettes/people_profile_connections_self.yml +78 -0
  54. data/spec/vcr_cassettes/people_profile_fields_complex.yml +70 -0
  55. data/spec/vcr_cassettes/people_profile_fields_simple.yml +57 -0
  56. data/spec/vcr_cassettes/people_profile_lang_spanish.yml +59 -0
  57. data/spec/vcr_cassettes/people_profile_multiple_fields.yml +68 -0
  58. data/spec/vcr_cassettes/people_profile_multiple_uids.yml +70 -0
  59. data/spec/vcr_cassettes/people_profile_multiple_uids_and_urls.yml +76 -0
  60. data/spec/vcr_cassettes/people_profile_multiple_urls.yml +70 -0
  61. data/spec/vcr_cassettes/people_profile_new_connections_fields.yml +69 -0
  62. data/spec/vcr_cassettes/people_profile_new_connections_other.yml +72 -0
  63. data/spec/vcr_cassettes/people_profile_new_connections_self.yml +72 -0
  64. data/spec/vcr_cassettes/people_profile_other_uid.yml +59 -0
  65. data/spec/vcr_cassettes/people_profile_other_url.yml +59 -0
  66. data/spec/vcr_cassettes/people_profile_own.yml +59 -0
  67. data/spec/vcr_cassettes/people_profile_own_secure.yml +59 -0
  68. data/spec/vcr_cassettes/unauthorized.yml +61 -0
  69. data/spec/vcr_cassettes/unavailable.yml +81 -0
  70. metadata +145 -88
  71. data/.autotest +0 -14
  72. data/.document +0 -5
  73. data/.gemtest +0 -0
  74. data/.rspec +0 -1
  75. data/.ruby-gemset +0 -1
  76. data/.ruby-version +0 -1
  77. data/README.markdown +0 -121
  78. data/changelog.markdown +0 -94
  79. data/examples/authenticate.rb +0 -16
  80. data/examples/network.rb +0 -12
  81. data/examples/profile.rb +0 -18
  82. data/examples/sinatra.rb +0 -69
  83. data/examples/status.rb +0 -6
  84. data/lib/linked_in/api/query_methods.rb +0 -123
  85. data/lib/linked_in/api/update_methods.rb +0 -76
  86. data/lib/linked_in/client.rb +0 -31
  87. data/lib/linked_in/helpers.rb +0 -6
  88. data/lib/linked_in/helpers/authorization.rb +0 -106
  89. data/lib/linked_in/helpers/request.rb +0 -93
  90. data/spec/cases/api_spec.rb +0 -192
  91. data/spec/cases/linkedin_spec.rb +0 -37
  92. data/spec/cases/mash_spec.rb +0 -85
  93. data/spec/cases/oauth_spec.rb +0 -130
  94. data/spec/cases/search_spec.rb +0 -190
  95. data/spec/helper.rb +0 -30
@@ -1,37 +0,0 @@
1
- require 'helper'
2
-
3
- describe LinkedIn do
4
-
5
- before(:each) do
6
- LinkedIn.client_id = nil
7
- LinkedIn.client_secret = nil
8
- LinkedIn.default_profile_fields = nil
9
- end
10
-
11
- it "should be able to set the client_id and client_secret" do
12
- LinkedIn.client_id = 'client_id'
13
- LinkedIn.client_secret = 'client_secret'
14
-
15
- LinkedIn.client_id.should == 'client_id'
16
- LinkedIn.client_secret.should == 'client_secret'
17
- end
18
-
19
- it "should be able to set the default profile fields" do
20
- LinkedIn.default_profile_fields = ['education', 'positions']
21
-
22
- LinkedIn.default_profile_fields.should == ['education', 'positions']
23
- end
24
-
25
- it "should be able to set the client_id and client_secret via a configure block" do
26
- LinkedIn.configure do |config|
27
- config.client_id = 'client_id'
28
- config.client_secret = 'client_secret'
29
- config.default_profile_fields = ['education', 'positions']
30
- end
31
-
32
- LinkedIn.client_id.should == 'client_id'
33
- LinkedIn.client_secret.should == 'client_secret'
34
- LinkedIn.default_profile_fields.should == ['education', 'positions']
35
- end
36
-
37
- end
@@ -1,85 +0,0 @@
1
- require 'helper'
2
-
3
- describe LinkedIn::Mash do
4
-
5
- describe ".from_json" do
6
- it "should convert a json string to a Mash" do
7
- json_string = "{\"name\":\"Josh Kalderimis\"}"
8
- mash = LinkedIn::Mash.from_json(json_string)
9
-
10
- mash.should have_key('name')
11
- mash.name.should == 'Josh Kalderimis'
12
- end
13
- end
14
-
15
- describe "#convert_keys" do
16
- let(:mash) do
17
- LinkedIn::Mash.new({
18
- 'firstName' => 'Josh',
19
- 'LastName' => 'Kalderimis',
20
- '_key' => 1234,
21
- '_total' => 1234,
22
- 'values' => {},
23
- 'numResults' => 'total_results'
24
- })
25
- end
26
-
27
- it "should convert camal cased hash keys to underscores" do
28
- mash.should have_key('first_name')
29
- mash.should have_key('last_name')
30
- end
31
-
32
- it "should convert the key _key to id" do
33
- mash.should have_key('id')
34
- end
35
-
36
- it "should convert the key _total to total" do
37
- mash.should have_key('total')
38
- end
39
-
40
- it "should convert the key values to all" do
41
- mash.should have_key('all')
42
- end
43
-
44
- it "should convert the key numResults to total_results" do
45
- mash.should have_key('total_results')
46
- end
47
- end
48
-
49
- describe '#timestamp' do
50
- it "should return a valid Time if a key of timestamp exists and the value is an int" do
51
- time_mash = LinkedIn::Mash.new({ 'timestamp' => 1297083249 })
52
-
53
- time_mash.timestamp.should be_a_kind_of(Time)
54
- time_mash.timestamp.to_i.should == 1297083249
55
- end
56
-
57
- it "should return a valid Time if a key of timestamp exists and the value is an int which is greater than 9999999999" do
58
- time_mash = LinkedIn::Mash.new({ 'timestamp' => 1297083249 * 1000 })
59
-
60
- time_mash.timestamp.should be_a_kind_of(Time)
61
- time_mash.timestamp.to_i.should == 1297083249
62
- end
63
-
64
- it "should not try to convert to a Time object if the value isn't an Integer" do
65
- time_mash = LinkedIn::Mash.new({ 'timestamp' => 'Foo' })
66
-
67
- time_mash.timestamp.class.should be String
68
- end
69
- end
70
-
71
- describe "#to_date" do
72
- let(:date_mash) do
73
- LinkedIn::Mash.new({
74
- 'year' => 2010,
75
- 'month' => 06,
76
- 'day' => 23
77
- })
78
- end
79
-
80
- it "should return a valid Date if the keys year, month, day all exist" do
81
- date_mash.to_date.should == Date.civil(2010, 06, 23)
82
- end
83
- end
84
-
85
- end
@@ -1,130 +0,0 @@
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
@@ -1,190 +0,0 @@
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
@@ -1,30 +0,0 @@
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