Sha256: 1795c7e7cde2c413df2602cb5b6fabd8ac82fe046b1af904285b509ec0ac83ca

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

module LinkedIn
  class Client
    include Configuration
    include LinkedIn::API

    def initialize(**config, &block)
      configure config, &block
    end

    def credentials
      @credentials ||= Credentials.new configuration
    end

    def connection
      @connection ||= Faraday.new 'https://api.linkedin.com' do |conn|
        conn.request :json
        conn.request :url_encoded
        conn.request :linkedin_credentials, configuration
        conn.request :linkedin_format
        conn.request :linkedin_user_agent

        conn.response :linkedin_errors
        conn.response :mashify
        conn.response :logger, configuration.logger
        conn.response :json, content_type: /\bjson$/

        conn.adapter Faraday.default_adapter
      end
    end

    def headers
      @headers ||= {}
    end

    def params
      @params ||= {}
    end

    private

    def override(global, overrides)
      global.to_h.merge overrides.to_h
    end

    def execute(root, method: :get, selector: nil, fields: nil, **opts)
      rendered_fields = Fields.render fields
      query = ['v1', root, selector.to_param, opts[:path]].compact.join('/').concat(rendered_fields)

      response = connection.send method, query do |req|
        req.headers.update override(@headers, opts[:headers])
        req.params.update override(@params, opts[:params])
        req.body = opts[:body].to_json if opts[:body]
      end

      Response.new response
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
linkedin2-0.0.19 lib/linkedin/client.rb
linkedin2-0.0.18 lib/linkedin/client.rb
linkedin2-0.0.17 lib/linkedin/client.rb