Class: LinkedIn::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
API::Authentication, API::Companies, API::NetworkUpdates, API::Profiles, Configuration
Defined in:
lib/linkedin/client.rb

Constant Summary collapse

HTTP_METHODS =
[:get, :post, :put, :patch, :delete, :headers].freeze

Instance Attribute Summary collapse

Attributes included from API::Authentication

#state

Class Method Summary collapse

Instance Method Summary collapse

Methods included from API::Companies

#company

Methods included from API::NetworkUpdates

#network_update_comments, #network_update_likes, #network_updates

Methods included from API::Profiles

#connect_with, #connections, #message, #profile, #profile_api, #search, #shared_connections

Methods included from API::Authentication

#authorize_url, #request_access_token

Methods included from Configuration

included

Methods included from LinkedIn::Configuration::InstanceConfiguration

#config, #reset

Methods included from LinkedIn::Configuration::BaseConfiguration

#config, #configure, #load

Constructor Details

#initialize(options = {}, &block) ⇒ Client

Returns a new instance of Client.



17
18
19
20
# File 'lib/linkedin/client.rb', line 17

def initialize(options={}, &block)
  configure options, &block
  self.access_token ||= self.config.access_token.to_s
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &body) ⇒ Object



57
58
59
60
# File 'lib/linkedin/client.rb', line 57

def method_missing(method, *args, &body)
  return simple_request(method, args[0], (args[1] || {}), &body) if HTTP_METHODS.include? method
  super
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



13
14
15
# File 'lib/linkedin/client.rb', line 13

def access_token
  @access_token
end

Class Method Details

.default_configObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/linkedin/client.rb', line 62

def self.default_config
  {
    request_format: :json,

    key: nil,
    secret: nil,
    access_token: nil,

    scope: 'r_basicprofile',
    state: Utils.generate_random_state,
    redirect_uri: 'http://localhost',

    logger: Logger.new('/dev/null')
  }
end

Instance Method Details

#connectionObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/linkedin/client.rb', line 26

def connection
  @connection ||= OAuth2::Client.new config.key, config.secret, oauth2_options do |faraday|
    faraday.request :url_encoded
    faraday.request :json
    faraday.request :linkedin_format, config.request_format

    faraday.response :mashify
    faraday.response :linkedin_errors
    faraday.response :logger, config.logger
    faraday.response :json, content_type: /\bjson$/

    faraday.adapter :net_http
  end
end

#profile_fieldsObject



50
51
52
53
54
55
# File 'lib/linkedin/client.rb', line 50

def profile_fields
  scopes = config.scope unless config.scope.respond_to?(:values)
  scopes ||= config.scope

  scopes.reduce([]) { |fields, scope| fields + LinkedIn.send(scope) }
end