linkedin2 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/example-linkedin.yml +4 -0
- data/lib/linkedin/api.rb +11 -0
- data/lib/linkedin/api/authentication.rb +1 -3
- data/lib/linkedin/api/companies.rb +14 -0
- data/lib/linkedin/api/groups.rb +6 -0
- data/lib/linkedin/api/industries.rb +173 -0
- data/lib/linkedin/api/jobs.rb +6 -0
- data/lib/linkedin/api/permissions.rb +43 -0
- data/lib/linkedin/api/profiles.rb +23 -0
- data/lib/linkedin/base.rb +28 -0
- data/lib/linkedin/client.rb +67 -9
- data/lib/linkedin/company.rb +20 -0
- data/lib/linkedin/configuration.rb +14 -28
- data/lib/linkedin/error.rb +21 -1
- data/lib/linkedin/faraday_middleware.rb +10 -0
- data/lib/linkedin/faraday_middleware/linkedin_error_response.rb +28 -0
- data/lib/linkedin/faraday_middleware/linkedin_format_request.rb +27 -0
- data/lib/linkedin/industry.rb +23 -0
- data/lib/linkedin/profile.rb +20 -0
- data/lib/linkedin/version.rb +1 -1
- data/lib/linkedin2.rb +52 -3
- data/linkedin.gemspec +5 -0
- data/spec/api/companies_spec.rb +37 -0
- data/spec/api/groups_spec.rb +22 -0
- data/spec/api/jobs_spec.rb +31 -0
- data/spec/api/profiles_spec.rb +109 -0
- data/spec/faraday_middleware/linkedin_error_response_spec.rb +47 -0
- data/spec/fixtures/requests/access_token.yml +37 -0
- data/spec/fixtures/requests/company-search/by_keywords_options_with_fields.yml +232 -0
- data/spec/fixtures/requests/company-search/by_keywords_string_parameter.yml +80 -0
- data/spec/fixtures/requests/company-search/by_single_keywords_option.yml +80 -0
- data/spec/fixtures/requests/company-search/by_single_keywords_option_with_facets_to_return.yml +80 -0
- data/spec/fixtures/requests/company-search/by_single_keywords_option_with_pagination.yml +74 -0
- data/spec/fixtures/requests/company.yml +81 -0
- data/spec/fixtures/requests/invalid.yml +53 -0
- data/spec/fixtures/requests/people-search/by_company_name_option.yml +93 -0
- data/spec/fixtures/requests/people-search/by_first_name_and_last_name_options.yml +100 -0
- data/spec/fixtures/requests/people-search/by_first_name_and_last_name_options_with_fields.yml +112 -0
- data/spec/fixtures/requests/people-search/by_keywords_string_parameter.yml +53 -0
- data/spec/fixtures/requests/people-search/by_single_keywords_option.yml +53 -0
- data/spec/fixtures/requests/people-search/by_single_keywords_option_with_pagination.yml +45 -0
- data/spec/fixtures/requests/request_token/request_token.yml +37 -0
- data/spec/fixtures/requests/request_token/with_callback.yml +37 -0
- data/spec/spec_helper.rb +17 -0
- metadata +132 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee1e973248a67cb339df26c8fc32d9565fb5ae4f
|
4
|
+
data.tar.gz: 73e5b542f4f95c0074531b3c1b32b558a3598ec0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61b1565caa8f7e6fcdbb2febec8ea75152b845fe5ad8cbb4d20d624178b416693ad3fcf9af6b6a327d613d2bddfc1bb98b34acaf21088343d83013b3daff7862
|
7
|
+
data.tar.gz: c2a429ebf3c5fbbb18251b915df6e5a2f7e00f2354b39ae4c56a80bcd427450bfe8332593da249ca4d9e676e31d34fb89e839690fe0a362c417ce93c063498ef
|
data/.gitignore
CHANGED
data/lib/linkedin/api.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'linkedin/api/authentication'
|
2
|
+
require 'linkedin/api/profiles'
|
3
|
+
require 'linkedin/api/companies'
|
4
|
+
require 'linkedin/api/groups'
|
5
|
+
require 'linkedin/api/industries'
|
6
|
+
require 'linkedin/api/jobs'
|
7
|
+
require 'linkedin/api/permissions'
|
8
|
+
|
9
|
+
include LinkedIn::API::Authentication
|
10
|
+
include LinkedIn::API::Profiles
|
11
|
+
include LinkedIn::API::Companies
|
@@ -2,7 +2,6 @@ module LinkedIn
|
|
2
2
|
module API
|
3
3
|
module Authentication
|
4
4
|
attr_reader :state
|
5
|
-
attr_accessor :access_token
|
6
5
|
|
7
6
|
def authorize_url(params={})
|
8
7
|
params.reverse_merge! defaults(:scope, :state, :redirect_uri)
|
@@ -15,8 +14,7 @@ module LinkedIn
|
|
15
14
|
params.reverse_merge! defaults(:redirect_uri)
|
16
15
|
opts = { mode: :query, param_name: 'oauth2_access_token' }
|
17
16
|
|
18
|
-
|
19
|
-
self.access_token = token_response.token
|
17
|
+
self.access_token = auth_code.get_token authorization_code, params, opts
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module LinkedIn
|
2
|
+
module API
|
3
|
+
module Companies
|
4
|
+
def company(options={})
|
5
|
+
selector = options[:selector].to_param
|
6
|
+
|
7
|
+
fields = options[:fields]
|
8
|
+
fields_string = fields.blank? ? '' : ":(#{Permissions.render_permissions fields})"
|
9
|
+
|
10
|
+
get "v1/companies/#{selector}#{fields_string}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
module LinkedIn
|
2
|
+
module API
|
3
|
+
module Industries
|
4
|
+
def self.all
|
5
|
+
INDUSTRIES
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.[](code)
|
9
|
+
find_by_code(code)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find_by_code(code)
|
13
|
+
INDUSTRIES.detect { |indust| indust[:code] == code }
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find_by_group(*groups)
|
17
|
+
INDUSTRIES.reject { |indust| (groups & indust[:group]) != groups }
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.find_by_description(description)
|
21
|
+
INDUSTRIES.detect { |indust| indust[:description].to_s.downcase == description.to_s.downcase }
|
22
|
+
end
|
23
|
+
|
24
|
+
INDUSTRIES = [ { code: 1, group: %i(gov tech), description: 'Defense & Space' },
|
25
|
+
{ code: 3, group: %i(tech), description: 'Computer Hardware' },
|
26
|
+
{ code: 4, group: %i(tech), description: 'Computer Software' },
|
27
|
+
{ code: 5, group: %i(tech), description: 'Computer Networking' },
|
28
|
+
{ code: 6, group: %i(tech), description: 'Internet' },
|
29
|
+
{ code: 7, group: %i(tech), description: 'Semiconductors' },
|
30
|
+
{ code: 8, group: %i(gov tech), description: 'Telecommunications' },
|
31
|
+
{ code: 9, group: %i(leg), description: 'Law Practice' },
|
32
|
+
{ code: 10, group: %i(leg), description: 'Legal Services' },
|
33
|
+
{ code: 11, group: %i(corp), description: 'Management Consulting' },
|
34
|
+
{ code: 12, group: %i(gov hlth tech), description: 'Biotechnology' },
|
35
|
+
{ code: 13, group: %i(hlth), description: 'Medical Practice' },
|
36
|
+
{ code: 14, group: %i(hlth), description: 'Hospital & Health Care' },
|
37
|
+
{ code: 15, group: %i(hlth tech), description: 'Pharmaceuticals' },
|
38
|
+
{ code: 16, group: %i(hlth), description: 'Veterinary' },
|
39
|
+
{ code: 17, group: %i(hlth), description: 'Medical Devices' },
|
40
|
+
{ code: 18, group: %i(good), description: 'Cosmetics' },
|
41
|
+
{ code: 19, group: %i(good), description: 'Apparel & Fashion' },
|
42
|
+
{ code: 20, group: %i(good rec), description: 'Sporting Goods' },
|
43
|
+
{ code: 21, group: %i(good), description: 'Tobacco' },
|
44
|
+
{ code: 22, group: %i(good), description: 'Supermarkets' },
|
45
|
+
{ code: 23, group: %i(good man serv), description: 'Food Production' },
|
46
|
+
{ code: 24, group: %i(good man), description: 'Consumer Electronics' },
|
47
|
+
{ code: 25, group: %i(good man), description: 'Consumer Goods' },
|
48
|
+
{ code: 26, group: %i(good man), description: 'Furniture' },
|
49
|
+
{ code: 27, group: %i(good man), description: 'Retail' },
|
50
|
+
{ code: 28, group: %i(med rec), description: 'Entertainment' },
|
51
|
+
{ code: 29, group: %i(rec), description: 'Gambling & Casinos' },
|
52
|
+
{ code: 30, group: %i(rec serv tran), description: 'Leisure, Travel & Tourism' },
|
53
|
+
{ code: 31, group: %i(rec serv tran), description: 'Hospitality' },
|
54
|
+
{ code: 32, group: %i(rec serv), description: 'Restaurants' },
|
55
|
+
{ code: 33, group: %i(rec), description: 'Sports' },
|
56
|
+
{ code: 34, group: %i(rec serv), description: 'Food & Beverages' },
|
57
|
+
{ code: 35, group: %i(art med rec), description: 'Motion Pictures and Film' },
|
58
|
+
{ code: 36, group: %i(med rec), description: 'Broadcast Media' },
|
59
|
+
{ code: 37, group: %i(art med rec), description: 'Museums and Institutions' },
|
60
|
+
{ code: 38, group: %i(art med rec), description: 'Fine Art' },
|
61
|
+
{ code: 39, group: %i(art med rec), description: 'Performing Arts' },
|
62
|
+
{ code: 40, group: %i(rec serv), description: 'Recreational Facilities and Services' },
|
63
|
+
{ code: 41, group: %i(fin), description: 'Banking' },
|
64
|
+
{ code: 42, group: %i(fin), description: 'Insurance' },
|
65
|
+
{ code: 43, group: %i(fin), description: 'Financial Services' },
|
66
|
+
{ code: 44, group: %i(cons fin good), description: 'Real Estate' },
|
67
|
+
{ code: 45, group: %i(fin), description: 'Investment Banking' },
|
68
|
+
{ code: 46, group: %i(fin), description: 'Investment Management' },
|
69
|
+
{ code: 47, group: %i(corp fin), description: 'Accounting' },
|
70
|
+
{ code: 48, group: %i(cons), description: 'Construction' },
|
71
|
+
{ code: 49, group: %i(cons), description: 'Building Materials' },
|
72
|
+
{ code: 50, group: %i(cons), description: 'Architecture & Planning' },
|
73
|
+
{ code: 51, group: %i(cons gov), description: 'Civil Engineering' },
|
74
|
+
{ code: 52, group: %i(gov man), description: 'Aviation & Aerospace' },
|
75
|
+
{ code: 53, group: %i(man), description: 'Automotive' },
|
76
|
+
{ code: 54, group: %i(man), description: 'Chemicals' },
|
77
|
+
{ code: 55, group: %i(man), description: 'Machinery' },
|
78
|
+
{ code: 56, group: %i(man), description: 'Mining & Metals' },
|
79
|
+
{ code: 57, group: %i(man), description: 'Oil & Energy' },
|
80
|
+
{ code: 58, group: %i(man), description: 'Shipbuilding' },
|
81
|
+
{ code: 59, group: %i(man), description: 'Utilities' },
|
82
|
+
{ code: 60, group: %i(man), description: 'Textiles' },
|
83
|
+
{ code: 61, group: %i(man), description: 'Paper & Forest Products' },
|
84
|
+
{ code: 62, group: %i(man), description: 'Railroad Manufacture' },
|
85
|
+
{ code: 63, group: %i(agr), description: 'Farming' },
|
86
|
+
{ code: 64, group: %i(agr), description: 'Ranching' },
|
87
|
+
{ code: 65, group: %i(agr), description: 'Dairy' },
|
88
|
+
{ code: 66, group: %i(agr), description: 'Fishery' },
|
89
|
+
{ code: 67, group: %i(edu), description: 'Primary/Secondary Education' },
|
90
|
+
{ code: 68, group: %i(edu), description: 'Higher Education' },
|
91
|
+
{ code: 69, group: %i(edu), description: 'Education Management' },
|
92
|
+
{ code: 70, group: %i(edu gov), description: 'Research' },
|
93
|
+
{ code: 71, group: %i(gov), description: 'Military' },
|
94
|
+
{ code: 72, group: %i(gov leg), description: 'Legislative Office' },
|
95
|
+
{ code: 73, group: %i(gov leg), description: 'Judiciary' },
|
96
|
+
{ code: 74, group: %i(gov), description: 'International Affairs' },
|
97
|
+
{ code: 75, group: %i(gov), description: 'Government Administration' },
|
98
|
+
{ code: 76, group: %i(gov), description: 'Executive Office' },
|
99
|
+
{ code: 77, group: %i(gov leg), description: 'Law Enforcement' },
|
100
|
+
{ code: 78, group: %i(gov), description: 'Public Safety' },
|
101
|
+
{ code: 79, group: %i(gov), description: 'Public Policy' },
|
102
|
+
{ code: 80, group: %i(corp med), description: 'Marketing and Advertising' },
|
103
|
+
{ code: 81, group: %i(med rec), description: 'Newspapers' },
|
104
|
+
{ code: 82, group: %i(med rec), description: 'Publishing' },
|
105
|
+
{ code: 83, group: %i(med rec), description: 'Printing' },
|
106
|
+
{ code: 84, group: %i(med serv), description: 'Information Services' },
|
107
|
+
{ code: 85, group: %i(med rec serv), description: 'Libraries' },
|
108
|
+
{ code: 86, group: %i(org serv), description: 'Environmental Services' },
|
109
|
+
{ code: 87, group: %i(serv tran), description: 'Package/Freight Delivery' },
|
110
|
+
{ code: 88, group: %i(org serv), description: 'Individual & Family Services' },
|
111
|
+
{ code: 89, group: %i(org serv), description: 'Religious Institutions' },
|
112
|
+
{ code: 90, group: %i(org serv), description: 'Civic & Social Organization' },
|
113
|
+
{ code: 91, group: %i(org serv), description: 'Consumer Services' },
|
114
|
+
{ code: 92, group: %i(tran), description: 'Transportation/Trucking/Railroad' },
|
115
|
+
{ code: 93, group: %i(tran), description: 'Warehousing' },
|
116
|
+
{ code: 94, group: %i(man tech tran), description: 'Airlines/Aviation' },
|
117
|
+
{ code: 95, group: %i(tran), description: 'Maritime' },
|
118
|
+
{ code: 96, group: %i(tech), description: 'Information Technology and Services' },
|
119
|
+
{ code: 97, group: %i(corp), description: 'Market Research' },
|
120
|
+
{ code: 98, group: %i(corp), description: 'Public Relations and Communications' },
|
121
|
+
{ code: 99, group: %i(art med), description: 'Design' },
|
122
|
+
{ code: 100, group: %i(org), description: 'Non-Profit Organization Management' },
|
123
|
+
{ code: 101, group: %i(org), description: 'Fund-Raising' },
|
124
|
+
{ code: 102, group: %i(corp org), description: 'Program Development' },
|
125
|
+
{ code: 103, group: %i(art med rec), description: 'Writing and Editing' },
|
126
|
+
{ code: 104, group: %i(corp), description: 'Staffing and Recruiting' },
|
127
|
+
{ code: 105, group: %i(corp), description: 'Professional Training & Coaching' },
|
128
|
+
{ code: 106, group: %i(fin tech), description: 'Venture Capital & Private Equity' },
|
129
|
+
{ code: 107, group: %i(gov org), description: 'Political Organization' },
|
130
|
+
{ code: 108, group: %i(corp gov serv), description: 'Translation and Localization' },
|
131
|
+
{ code: 109, group: %i(med rec), description: 'Computer Games' },
|
132
|
+
{ code: 110, group: %i(corp rec serv), description: 'Events Services' },
|
133
|
+
{ code: 111, group: %i(art med rec), description: 'Arts and Crafts' },
|
134
|
+
{ code: 112, group: %i(good man), description: 'Electrical/Electronic Manufacturing' },
|
135
|
+
{ code: 113, group: %i(med), description: 'Online Media' },
|
136
|
+
{ code: 114, group: %i(gov man tech), description: 'Nanotechnology' },
|
137
|
+
{ code: 115, group: %i(art rec), description: 'Music' },
|
138
|
+
{ code: 116, group: %i(corp tran), description: 'Logistics and Supply Chain' },
|
139
|
+
{ code: 117, group: %i(man), description: 'Plastics' },
|
140
|
+
{ code: 118, group: %i(tech), description: 'Computer & Network Security' },
|
141
|
+
{ code: 119, group: %i(tech), description: 'Wireless' },
|
142
|
+
{ code: 120, group: %i(leg org), description: 'Alternative Dispute Resolution' },
|
143
|
+
{ code: 121, group: %i(corp org serv), description: 'Security and Investigations' },
|
144
|
+
{ code: 122, group: %i(corp serv), description: 'Facilities Services' },
|
145
|
+
{ code: 123, group: %i(corp), description: 'Outsourcing/Offshoring' },
|
146
|
+
{ code: 124, group: %i(hlth rec), description: 'Health, Wellness and Fitness' },
|
147
|
+
{ code: 125, group: %i(hlth), description: 'Alternative Medicine' },
|
148
|
+
{ code: 126, group: %i(med rec), description: 'Media Production' },
|
149
|
+
{ code: 127, group: %i(art med), description: 'Animation' },
|
150
|
+
{ code: 128, group: %i(cons corp fin), description: 'Commercial Real Estate' },
|
151
|
+
{ code: 129, group: %i(fin), description: 'Capital Markets' },
|
152
|
+
{ code: 130, group: %i(gov org), description: 'Think Tanks' },
|
153
|
+
{ code: 131, group: %i(org), description: 'Philanthropy' },
|
154
|
+
{ code: 132, group: %i(edu org), description: 'E-Learning' },
|
155
|
+
{ code: 133, group: %i(good), description: 'Wholesale' },
|
156
|
+
{ code: 134, group: %i(corp good tran), description: 'Import and Export' },
|
157
|
+
{ code: 135, group: %i(cons gov man), description: 'Mechanical or Industrial Engineering' },
|
158
|
+
{ code: 136, group: %i(art med rec), description: 'Photography' },
|
159
|
+
{ code: 137, group: %i(corp), description: 'Human Resources' },
|
160
|
+
{ code: 138, group: %i(corp man), description: 'Business Supplies and Equipment' },
|
161
|
+
{ code: 139, group: %i(hlth), description: 'Mental Health Care' },
|
162
|
+
{ code: 140, group: %i(art med), description: 'Graphic Design' },
|
163
|
+
{ code: 141, group: %i(gov org tran), description: 'International Trade and Development' },
|
164
|
+
{ code: 142, group: %i(good man rec), description: 'Wine and Spirits' },
|
165
|
+
{ code: 143, group: %i(good), description: 'Luxury Goods & Jewelry' },
|
166
|
+
{ code: 144, group: %i(gov man org), description: 'Renewables & Environment' },
|
167
|
+
{ code: 145, group: %i(cons man), description: 'Glass, Ceramics & Concrete' },
|
168
|
+
{ code: 146, group: %i(good man), description: 'Packaging and Containers' },
|
169
|
+
{ code: 147, group: %i(cons man), description: 'Industrial Automation' },
|
170
|
+
{ code: 148, group: %i(gov), description: 'Government Relations' } ]
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'byebug'
|
2
|
+
module LinkedIn
|
3
|
+
module API
|
4
|
+
module Permissions
|
5
|
+
COMPANY = { 'company' => [ 'id', 'name', 'type', 'size', 'industry', 'ticker' ] }
|
6
|
+
LOCATION = { 'location' => ['name', { 'country' => 'code' } ] }
|
7
|
+
POSITIONS = { 'positions' => [ 'id', 'title', 'summary', 'start-date', 'end-date', 'is-current', COMPANY ] }
|
8
|
+
PROFILE_REQ = { 'api-standard-profile-request' => ['url', 'headers'] }
|
9
|
+
|
10
|
+
PROFILE_BASE = [ 'id', 'first-name', 'last-name','maiden-name', 'formatted-name', 'phonetic-first-name',
|
11
|
+
'phonetic-last-name', 'formatted-phonetic-name', 'headline', 'industry', 'distance',
|
12
|
+
'current-share', 'num-connections', 'num-connections-capped', 'summary', 'specialties',
|
13
|
+
'picture-url', 'site-standard-profile-request', 'public-profile-url',
|
14
|
+
LOCATION, POSITIONS, PROFILE_REQ ]
|
15
|
+
|
16
|
+
RELATION = { 'relation-to-viewer' => [ 'num-related-connections', 'related-connections' => PROFILE_BASE ] }
|
17
|
+
|
18
|
+
|
19
|
+
MEMBER_RESOURCES = { 'member-url-resources' => [ 'url', 'name' ] }
|
20
|
+
FULL_BASE = [ 'last-modified-timestamp', 'proposal-comments', 'associations', 'interests', 'publications',
|
21
|
+
'patents', 'languages', 'skills', 'certifications', 'educations', 'courses', 'volunteer',
|
22
|
+
'three-current-positions', 'three-past-positions', 'num-recommenders', 'recommendations-received',
|
23
|
+
'mfeed-rss-url', 'following', 'job-bookmarks', 'suggestions', 'date-of-birth',
|
24
|
+
'member-url-resources', 'related-profile-views', 'honors-awards' ]
|
25
|
+
|
26
|
+
R_BASICPROFILE = PROFILE_BASE + [ RELATION ]
|
27
|
+
R_EMAIL = [ 'email-address' ]
|
28
|
+
R_FULLPROFILE = FULL_BASE + [ MEMBER_RESOURCES ]
|
29
|
+
R_CONTACTINFO = [ 'phone-numbers', 'bound-account-types', 'im-accounts', 'main-address', 'twitter-accounts', 'primary-twitter-account']
|
30
|
+
R_NETWORK = [ 'connections' ]
|
31
|
+
RW_GROUPS = [ 'group-memberships' ]
|
32
|
+
RW_NUS = [ 'network' ]
|
33
|
+
|
34
|
+
def self.render_permissions (*fields)
|
35
|
+
fields = fields.first if fields.size == 1
|
36
|
+
|
37
|
+
return render_permissions(fields.map { |key, value| "#{key}:(#{render_permissions value})" }) if fields.respond_to? :keys
|
38
|
+
return fields.map { |value| render_permissions value }.join ',' if fields.respond_to? :each
|
39
|
+
fields.to_s
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module LinkedIn
|
2
|
+
module API
|
3
|
+
module Profiles
|
4
|
+
def profile(options={})
|
5
|
+
selector = options[:selector]
|
6
|
+
selector_string = '~' if selector.blank?
|
7
|
+
selector_string ||= selector.to_param
|
8
|
+
|
9
|
+
fields = options[:fields]
|
10
|
+
fields_string = fields.blank? ? '' : ":(#{Permissions.render_permissions fields})"
|
11
|
+
|
12
|
+
get "v1/people/#{selector_string}#{fields_string}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def connections(options={})
|
16
|
+
selector = options[:selector].to_param || '~'
|
17
|
+
selector_option = { selector: [ selector, 'connections' ].join('/') }
|
18
|
+
|
19
|
+
profile options.slice(:selector).merge(selector_option)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module LinkedIn
|
2
|
+
class Base
|
3
|
+
attr_reader :attributes
|
4
|
+
|
5
|
+
def initialize(attributes={})
|
6
|
+
@attributes = Hashie::Mash.new attributes
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def method_missing(method, *args, &block)
|
11
|
+
return @attributes.send(method, *args, &block) if @attributes.respond_to?(method)
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def respond_to?(method, include_all=false)
|
16
|
+
return true if @attributes.respond_to method, include_all
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def client
|
21
|
+
LinkedIn.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.client
|
25
|
+
LinkedIn.new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/linkedin/client.rb
CHANGED
@@ -1,33 +1,91 @@
|
|
1
|
-
require 'byebug'
|
2
|
-
|
3
1
|
module LinkedIn
|
4
2
|
class Client
|
3
|
+
extend Forwardable
|
4
|
+
|
5
5
|
include Configuration
|
6
|
-
include API
|
6
|
+
include API
|
7
|
+
|
8
|
+
attr_reader :access_token
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
def_delegators :@access_token, :expires?, :expired?, :request
|
11
|
+
|
12
|
+
def initialize(options={}, &block)
|
13
|
+
configure options, &block
|
14
|
+
self.access_token ||= self.config[:access_token].to_s
|
10
15
|
end
|
11
16
|
|
12
17
|
def connection
|
13
|
-
OAuth2::Client.new
|
18
|
+
@connection ||= OAuth2::Client.new(config.key, config.secret, oauth2_options) do |faraday|
|
19
|
+
faraday.request :url_encoded
|
20
|
+
faraday.request :json
|
21
|
+
faraday.request :linkedin_format, defaults(:request_format)
|
22
|
+
|
23
|
+
faraday.response :linkedin_errors
|
24
|
+
faraday.response :logger, config.logger
|
25
|
+
faraday.response :json, content_type: /\bjson$/
|
26
|
+
|
27
|
+
faraday.adapter :net_http
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def access_token=(token)
|
32
|
+
if token.kind_of? String
|
33
|
+
options = { access_token: token, mode: :query, param_name: 'oauth2_access_token' }
|
34
|
+
return @access_token = OAuth2::AccessToken.from_hash(connection, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
@access_token = token
|
38
|
+
end
|
39
|
+
|
40
|
+
def access_token_request(method, path, opts={}, &block)
|
41
|
+
response = access_token.send method, path, opts, &block
|
42
|
+
response.body
|
43
|
+
end
|
44
|
+
|
45
|
+
def method_missing(method, *args, &body)
|
46
|
+
return simple_request(method, args[0], (args[1] || {}), &body) if %i(get post put patch delete headers).include? method
|
47
|
+
super
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.default_config
|
51
|
+
{
|
52
|
+
authorize_path: '/uas/oauth2/authorization',
|
53
|
+
access_token_path: '/uas/oauth2/accessToken',
|
54
|
+
api_host: 'https://api.linkedin.com',
|
55
|
+
auth_host: 'https://www.linkedin.com',
|
56
|
+
request_format: :json,
|
57
|
+
|
58
|
+
key: nil,
|
59
|
+
secret: nil,
|
60
|
+
access_token: nil,
|
61
|
+
|
62
|
+
scope: 'r_basicprofile',
|
63
|
+
state: Utils.generate_random_state,
|
64
|
+
redirect_uri: 'http://localhost',
|
65
|
+
|
66
|
+
logger: Logger.new('/dev/null')
|
67
|
+
}
|
14
68
|
end
|
15
69
|
|
16
70
|
private
|
17
71
|
|
72
|
+
def simple_request(method, path, options={}, &body)
|
73
|
+
request(method, path, options, &body).body
|
74
|
+
end
|
75
|
+
|
18
76
|
def auth_code
|
19
77
|
connection.auth_code unless connection.nil?
|
20
78
|
end
|
21
79
|
|
22
80
|
def oauth2_options
|
23
|
-
{ site:
|
81
|
+
{ site: config.api_host,
|
24
82
|
authorize_url: url_for(:authorize),
|
25
83
|
token_url: url_for(:access_token) }
|
26
84
|
end
|
27
85
|
|
28
86
|
def url_for(option_key)
|
29
|
-
host =
|
30
|
-
path =
|
87
|
+
host = config.auth_host
|
88
|
+
path = config["#{option_key}_path".to_sym]
|
31
89
|
"#{host}#{path}"
|
32
90
|
end
|
33
91
|
end
|