Module: LinkedinV2::Helpers::Handler

Included in:
Client
Defined in:
lib/linkedin_v2/helpers/handler.rb

Instance Method Summary collapse

Instance Method Details

#conn(api) ⇒ Object



12
13
14
# File 'lib/linkedin_v2/helpers/handler.rb', line 12

def conn(api)
  RestClient::Resource.new(api, headers: headers)
end

#headersObject



16
17
18
# File 'lib/linkedin_v2/helpers/handler.rb', line 16

def headers
  { "Authorization": "Bearer #{token}", "Content-Type": "application/json", }
end

#post_headersObject



20
21
22
# File 'lib/linkedin_v2/helpers/handler.rb', line 20

def post_headers
  { "X-Restli-Protocol-Version": "2.0.0" }
end

#request(method, endpoint, params = {}, additional_headers = {}, api = API_URL) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/linkedin_v2/helpers/handler.rb', line 4

def request(method, endpoint, params = {}, additional_headers = {}, api = API_URL)
  attrs = [ params, additional_headers ].reject(&:empty?)

  JSON.parse(conn(api)[endpoint].public_send(method, *attrs))
rescue RestClient::ExceptionWithResponse => exception
  raise LinkedinResponseError.new("response error", details: exception.response)
end