linkedin2 0.0.5 → 0.0.6
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/lib/linkedin/api/authentication.rb +4 -4
- data/lib/linkedin/api/permissions.rb +7 -2
- data/lib/linkedin/api/profiles.rb +34 -14
- data/lib/linkedin/client.rb +20 -20
- data/lib/linkedin/configuration.rb +2 -2
- data/lib/linkedin/faraday_middleware/linkedin_format_request.rb +3 -4
- data/lib/linkedin/version.rb +1 -1
- data/lib/linkedin2.rb +15 -32
- metadata +2 -3
- data/lib/linkedin/api.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e81d1df72a3862c66ddcdbe4aeb921af88ca33cc
|
4
|
+
data.tar.gz: 410375f89b5f5891fe969abd489f7cd5a2b71b51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6900a7eb801c6cdd5488893c22526179a72a67e82347b5aa96e191b2bb0c9c01cde4cb6900e2744b26c0cd064df4e82e89df35731f651dae241462f946a0afe6
|
7
|
+
data.tar.gz: 9e111665cd4a373e3270dcb3961bdeee9aefcb1b73e8a3e4d6e953455c0b59282768fdad6c57c02c08da73d95b02ebda90e427c6a37193b5f0ba4648c38135e1
|
@@ -3,15 +3,15 @@ module LinkedIn
|
|
3
3
|
module Authentication
|
4
4
|
attr_reader :state
|
5
5
|
|
6
|
-
def authorize_url(params={})
|
7
|
-
params.reverse_merge!
|
6
|
+
def authorize_url(params = {})
|
7
|
+
params.reverse_merge! config.to_h.slice :scope, :state, :redirect_uri
|
8
8
|
auth_code.authorize_url params
|
9
9
|
end
|
10
10
|
|
11
|
-
def request_access_token(authorization_code, params={})
|
11
|
+
def request_access_token(authorization_code, params = {})
|
12
12
|
raise Error::CSRF.new state, params[:state] if params[:state] && params[:state] != state
|
13
13
|
|
14
|
-
params.reverse_merge!
|
14
|
+
params.reverse_merge! redirect_uri: config.redirect_uri
|
15
15
|
opts = { mode: :query, param_name: 'oauth2_access_token' }
|
16
16
|
|
17
17
|
self.access_token = auth_code.get_token authorization_code, params, opts
|
@@ -14,7 +14,6 @@ module LinkedIn
|
|
14
14
|
|
15
15
|
RELATION = { 'relation-to-viewer' => [ 'num-related-connections', 'related-connections' => PROFILE_BASE ] }
|
16
16
|
|
17
|
-
|
18
17
|
MEMBER_RESOURCES = { 'member-url-resources' => [ 'url', 'name' ] }
|
19
18
|
FULL_BASE = [ 'last-modified-timestamp', 'proposal-comments', 'associations', 'interests', 'publications',
|
20
19
|
'patents', 'languages', 'skills', 'certifications', 'educations', 'courses', 'volunteer',
|
@@ -22,13 +21,19 @@ module LinkedIn
|
|
22
21
|
'mfeed-rss-url', 'following', 'job-bookmarks', 'suggestions', 'date-of-birth',
|
23
22
|
'member-url-resources', 'related-profile-views', 'honors-awards' ]
|
24
23
|
|
24
|
+
|
25
|
+
%i(company location positions profile_base relation member_resources full_base).each do |field|
|
26
|
+
private_constant field.upcase
|
27
|
+
end
|
28
|
+
|
25
29
|
R_BASICPROFILE = PROFILE_BASE + [ RELATION ]
|
26
|
-
|
30
|
+
R_EMAILADDRESS = [ 'email-address' ]
|
27
31
|
R_FULLPROFILE = FULL_BASE + [ MEMBER_RESOURCES ]
|
28
32
|
R_CONTACTINFO = [ 'phone-numbers', 'bound-account-types', 'im-accounts', 'main-address', 'twitter-accounts', 'primary-twitter-account']
|
29
33
|
R_NETWORK = [ 'connections' ]
|
30
34
|
RW_GROUPS = [ 'group-memberships' ]
|
31
35
|
RW_NUS = [ 'network' ]
|
36
|
+
W_MESSAGES = []
|
32
37
|
|
33
38
|
def self.render_permissions (*fields)
|
34
39
|
fields = fields.first if fields.size == 1
|
@@ -1,27 +1,47 @@
|
|
1
1
|
module LinkedIn
|
2
2
|
module API
|
3
3
|
module Profiles
|
4
|
-
def
|
5
|
-
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}"
|
4
|
+
def profile_api(selector)
|
5
|
+
profile selector, Permissions::PROFILE_REQ
|
13
6
|
end
|
14
7
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
8
|
+
def profile(selector = '~', fields = nil, token = nil)
|
9
|
+
fields ||= profile_fields
|
10
|
+
query = "#{selector.to_param}:(#{Permissions.render_permissions fields})"
|
11
|
+
get "v1/people/#{query}" do |req|
|
12
|
+
req.headers.merge! 'x-li-auth-token' => token unless token.blank?
|
13
|
+
end
|
14
|
+
end
|
18
15
|
|
19
|
-
|
16
|
+
def connections(selector = '~')
|
17
|
+
profile [selector, 'connections'].join '/'
|
20
18
|
end
|
21
19
|
|
22
|
-
def search(options={})
|
20
|
+
def search(options = {})
|
23
21
|
get "v1/people-search?#{options.to_param}"
|
24
22
|
end
|
23
|
+
|
24
|
+
def connect_with(selector, subject, message, type = :friend, auth_name = nil, auth_value = nil)
|
25
|
+
if auth_name.blank? || auth_value.blank?
|
26
|
+
profile = profile_api selector
|
27
|
+
token = profile.apiStandardProfileRequest_.headers_.values_.first.value
|
28
|
+
auth_name, auth_value = *token.split(':')
|
29
|
+
end
|
30
|
+
|
31
|
+
connection_request = { recipients: { values: [ { person: { _path: "/people/#{selector.to_param}" } } ] },
|
32
|
+
subject: subject,
|
33
|
+
body: message,
|
34
|
+
'item-content' => {
|
35
|
+
'invitation-request' => {
|
36
|
+
'connect-type' => type,
|
37
|
+
authorization: { name: auth_name, value: auth_value } } } }
|
38
|
+
|
39
|
+
post 'v1/people/~/mailbox' do |req|
|
40
|
+
req.headers['Content-Type'] = 'application/json'
|
41
|
+
req.headers['x-li-format'] = 'json'
|
42
|
+
req.body = connection_request.to_json
|
43
|
+
end
|
44
|
+
end
|
25
45
|
end
|
26
46
|
end
|
27
47
|
end
|
data/lib/linkedin/client.rb
CHANGED
@@ -3,7 +3,10 @@ module LinkedIn
|
|
3
3
|
extend Forwardable
|
4
4
|
|
5
5
|
include Configuration
|
6
|
-
include API
|
6
|
+
include LinkedIn::API::Authentication
|
7
|
+
include LinkedIn::API::Profiles
|
8
|
+
include LinkedIn::API::NetworkUpdates
|
9
|
+
include LinkedIn::API::Companies
|
7
10
|
|
8
11
|
HTTP_METHODS = [:get, :post, :put, :patch, :delete, :headers].freeze
|
9
12
|
|
@@ -16,12 +19,17 @@ module LinkedIn
|
|
16
19
|
self.access_token ||= self.config.access_token.to_s
|
17
20
|
end
|
18
21
|
|
19
|
-
def
|
20
|
-
|
22
|
+
def auth_code
|
23
|
+
connection.auth_code
|
24
|
+
end
|
25
|
+
|
26
|
+
def connection
|
27
|
+
@connection ||= OAuth2::Client.new config.key, config.secret, oauth2_options do |faraday|
|
21
28
|
faraday.request :url_encoded
|
22
29
|
faraday.request :json
|
23
|
-
faraday.request :linkedin_format,
|
30
|
+
faraday.request :linkedin_format, config.request_format
|
24
31
|
|
32
|
+
faraday.response :mashify
|
25
33
|
faraday.response :linkedin_errors
|
26
34
|
faraday.response :logger, config.logger
|
27
35
|
faraday.response :json, content_type: /\bjson$/
|
@@ -39,9 +47,11 @@ module LinkedIn
|
|
39
47
|
@access_token = token
|
40
48
|
end
|
41
49
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
50
|
+
def profile_fields
|
51
|
+
scopes = config.scope unless config.scope.respond_to?(:values)
|
52
|
+
scopes ||= config.scope
|
53
|
+
|
54
|
+
scopes.reduce([]) { |fields, scope| fields + LinkedIn.send(scope) }
|
45
55
|
end
|
46
56
|
|
47
57
|
def method_missing(method, *args, &body)
|
@@ -51,10 +61,6 @@ module LinkedIn
|
|
51
61
|
|
52
62
|
def self.default_config
|
53
63
|
{
|
54
|
-
authorize_path: '/uas/oauth2/authorization',
|
55
|
-
access_token_path: '/uas/oauth2/accessToken',
|
56
|
-
api_host: 'https://api.linkedin.com',
|
57
|
-
auth_host: 'https://www.linkedin.com',
|
58
64
|
request_format: :json,
|
59
65
|
|
60
66
|
key: nil,
|
@@ -80,15 +86,9 @@ module LinkedIn
|
|
80
86
|
end
|
81
87
|
|
82
88
|
def oauth2_options
|
83
|
-
{ site:
|
84
|
-
authorize_url:
|
85
|
-
token_url:
|
86
|
-
end
|
87
|
-
|
88
|
-
def url_for(option_key)
|
89
|
-
host = config.auth_host
|
90
|
-
path = config.send("#{option_key}_path")
|
91
|
-
"#{host}#{path}"
|
89
|
+
{ site: 'https://api.linkedin.com',
|
90
|
+
authorize_url: 'https://www.linkedin.com/uas/oauth2/authorization',
|
91
|
+
token_url: 'https://www.linkedin.com/uas/oauth2/accessToken' }
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module LinkedIn
|
2
2
|
module FaradayMiddleware
|
3
3
|
class LinkedinFormatRequest < Faraday::Middleware
|
4
|
-
def initialize(app=nil,
|
4
|
+
def initialize(app = nil, format = :json)
|
5
5
|
super app
|
6
6
|
|
7
|
-
@
|
8
|
-
@request_format = options[:request_format]
|
7
|
+
@format = format
|
9
8
|
end
|
10
9
|
|
11
10
|
def call(env)
|
@@ -19,7 +18,7 @@ module LinkedIn
|
|
19
18
|
end
|
20
19
|
|
21
20
|
def set_request_format!(url)
|
22
|
-
ar = URI.decode_www_form(url.query || '') << ['format', @
|
21
|
+
ar = URI.decode_www_form(url.query || '') << ['format', @format]
|
23
22
|
url.query = URI.encode_www_form(ar)
|
24
23
|
end
|
25
24
|
end
|
data/lib/linkedin/version.rb
CHANGED
data/lib/linkedin2.rb
CHANGED
@@ -17,43 +17,26 @@ require 'linkedin/profile'
|
|
17
17
|
require 'linkedin/company'
|
18
18
|
require 'linkedin/industry'
|
19
19
|
require 'linkedin/faraday_middleware'
|
20
|
-
|
20
|
+
|
21
|
+
require 'linkedin/api/authentication'
|
22
|
+
require 'linkedin/api/profiles'
|
23
|
+
require 'linkedin/api/network_updates'
|
24
|
+
require 'linkedin/api/companies'
|
25
|
+
require 'linkedin/api/groups'
|
26
|
+
require 'linkedin/api/industries'
|
27
|
+
require 'linkedin/api/jobs'
|
28
|
+
require 'linkedin/api/permissions'
|
29
|
+
|
21
30
|
require 'linkedin/client'
|
22
31
|
|
23
32
|
module LinkedIn
|
24
|
-
def new(options={}, &block)
|
33
|
+
def self.new(options = {}, &block)
|
25
34
|
Client.new options, &block
|
26
35
|
end
|
27
36
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def self.r_basicprofile
|
33
|
-
@@r_basicprofile ||= API::Permissions::R_BASICPROFILE
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.r_emailaddress
|
37
|
-
@@r_emailaddress ||= API::Permissions::R_EMAIL
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.r_fullprofile
|
41
|
-
@@r_fullprofile ||= API::Permissions::R_FULLPROFILE
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.r_contactinfo
|
45
|
-
@@r_contactinfo ||= API::Permissions::R_CONTACTINFO
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.r_network
|
49
|
-
@@r_network ||= API::Permissions::R_NETWORK
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.rw_groups
|
53
|
-
@@rw_groups ||= API::Permissions::RW_GROUPS
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.rw_nus
|
57
|
-
@@rw_nus ||= API::Permissions::RW_NUS
|
37
|
+
%i(r_basicprofile r_emailaddress r_fullprofile r_contactinfo r_network rw_groups rw_nus w_messages).each do |field|
|
38
|
+
define_singleton_method field do
|
39
|
+
API::Permissions.const_get field.to_s.upcase
|
40
|
+
end
|
58
41
|
end
|
59
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linkedin2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Breznak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|
@@ -179,7 +179,6 @@ files:
|
|
179
179
|
- README.md
|
180
180
|
- Rakefile
|
181
181
|
- example-linkedin.yml
|
182
|
-
- lib/linkedin/api.rb
|
183
182
|
- lib/linkedin/api/authentication.rb
|
184
183
|
- lib/linkedin/api/companies.rb
|
185
184
|
- lib/linkedin/api/groups.rb
|
data/lib/linkedin/api.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'linkedin/api/authentication'
|
2
|
-
require 'linkedin/api/profiles'
|
3
|
-
require 'linkedin/api/network_updates'
|
4
|
-
require 'linkedin/api/companies'
|
5
|
-
require 'linkedin/api/groups'
|
6
|
-
require 'linkedin/api/industries'
|
7
|
-
require 'linkedin/api/jobs'
|
8
|
-
require 'linkedin/api/permissions'
|
9
|
-
|
10
|
-
include LinkedIn::API::Authentication
|
11
|
-
include LinkedIn::API::Profiles
|
12
|
-
include LinkedIn::API::NetworkUpdates
|
13
|
-
include LinkedIn::API::Companies
|