-
Notifications
You must be signed in to change notification settings - Fork 401
Expand file tree
/
Copy pathclient.rb
More file actions
73 lines (60 loc) · 1.78 KB
/
client.rb
File metadata and controls
73 lines (60 loc) · 1.78 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
require 'cgi'
require 'faraday'
require 'faraday_middleware'
module LinkedIn
class Client
include Helpers::Request
include Helpers::Authorization
include Api::QueryHelpers
include Api::People
include Api::Groups
include Api::Companies
include Api::Jobs
include Api::ShareAndSocialStream
include Api::Communications
include Search
attr_reader :consumer_token, :consumer_secret, :consumer_options
def initialize(ctoken=LinkedIn.token, csecret=LinkedIn.secret, options={})
@consumer_token = ctoken
@consumer_secret = csecret
@consumer_options = options
end
private
def authentication
{
:consumer_key => consumer_token,
:consumer_secret => consumer_secret,
:token => @auth_token,
:token_secret => @auth_secret
}
end
def authenticated?
authentication.values.all?
end
def connection_options
LinkedIn.faraday_options.merge({
:headers => {
'Accept' => "application/#{LinkedIn.format}",
'User-Agent' => LinkedIn.user_agent,
'x-li-format' => 'json'
},
:proxy => LinkedIn.proxy,
:ssl => {:verify => false},
:url => LinkedIn.endpoint
})
end
def connection
raise "Please authenticate first" unless authenticated?
@connection ||= Faraday.new(connection_options) do |builder|
builder.use ::Faraday::Request::OAuth, authentication
builder.use ::Faraday::Request::UrlEncoded
builder.use ::FaradayMiddleware::Mashify, :mash_class => LinkedIn::Mash
builder.use ::Faraday::Response::ParseJson
LinkedIn.middleware.each do |middle|
builder.use middle
end
builder.adapter(LinkedIn.adapter)
end
end
end
end