linkedin2 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bcc7473e7a7a37e92eb949a689bd760e1a29cf3
4
- data.tar.gz: 088fdd4b565abba39546f1d892d75e70d6d2e317
3
+ metadata.gz: e81d1df72a3862c66ddcdbe4aeb921af88ca33cc
4
+ data.tar.gz: 410375f89b5f5891fe969abd489f7cd5a2b71b51
5
5
  SHA512:
6
- metadata.gz: 92762c876e49c14e0142a2ba020979c7e0ac8f807de6a87136764f73a20e20d678937ffbfa11b560a17625a15161383c5f0332597a6531f86d9f6398e00dfd13
7
- data.tar.gz: 32f65366fd11de5b6fffe9756dc059ccd47f9429f9f61378c67d065800aebf26f0ee59440a2183148feaf9047d561358e000d1f22aee86be1ba2db965eff5ff9
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! defaults(:scope, :state, :redirect_uri)
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! defaults(:redirect_uri)
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
- R_EMAIL = [ 'email-address' ]
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 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}"
4
+ def profile_api(selector)
5
+ profile selector, Permissions::PROFILE_REQ
13
6
  end
14
7
 
15
- def connections(options={})
16
- selector = options[:selector].to_param || '~'
17
- selector_option = { selector: [ selector, 'connections' ].join('/') }
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
- profile options.slice(:selector).merge(selector_option)
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
@@ -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 connection
20
- @connection ||= OAuth2::Client.new(config.key, config.secret, oauth2_options) do |faraday|
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, defaults(:request_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 access_token_request(method, path, opts={}, &block)
43
- response = access_token.send method, path, opts, &block
44
- response.body
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: config.api_host,
84
- authorize_url: url_for(:authorize),
85
- token_url: url_for(:access_token) }
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
@@ -34,8 +34,8 @@ module LinkedIn
34
34
  configure config
35
35
  end
36
36
 
37
- def defaults(*keys)
38
- config.marshal_dump.slice *keys
37
+ def config(*keys)
38
+ config.marshal_dump.slice(*keys)
39
39
  end
40
40
  end
41
41
 
@@ -1,11 +1,10 @@
1
1
  module LinkedIn
2
2
  module FaradayMiddleware
3
3
  class LinkedinFormatRequest < Faraday::Middleware
4
- def initialize(app=nil, options={})
4
+ def initialize(app = nil, format = :json)
5
5
  super app
6
6
 
7
- @options = options
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', @request_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
@@ -1,3 +1,3 @@
1
1
  module LinkedIn
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
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
- require 'linkedin/api'
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
- def self.method_missing(method, *args, &block)
29
- Client.send(method, *args, &block) if Client.respond_to?(method)
30
- end
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.5
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-22 00:00:00.000000000 Z
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