Sha256: 10fc43dc8bc57569a0276df5227e2f0ce9ae3bda5c8bb7f951946f87c2f4cd49

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

module LinkedIn
  module API
    module Invitation
      def connect_with(recipient_selector, subject, message, type: :friend, x_auth_token: nil)
        if x_auth_token.blank?
          target_profile = profile recipient_selector, Fields::PROFILE_API_STD_PROFILE_REQ
          x_auth_token = target_profile.body.apiStandardProfileRequest_.headers_.values_.first.value
        end

        x_auth_name, x_auth_value = *x_auth_token.split(':')

        connection_body = build_connection_body selector: recipient_selector, subject: subject,
                                                message: message, type: type,
                                                auth_name: x_auth_name, auth_value: x_auth_value

        execute 'people/~/mailbox', method: :post, body: connection_body
      end

      private

      def build_connection_body(**args)
        [:selector, :subject, :message, :type, :auth_name, :auth_value].each do |key|
          raise ArgumentError.new "Missing / blank argument `#{key}`" if args[key].blank?
        end

        { recipients: { values: [ { person: { _path: "/people/#{args[:selector].to_param}" } } ] },
          subject: args[:subject],
          body: args[:message],
          'item-content' => {
            'invitation-request' => {
              'connect-type' => args[:type],
              authorization: { name: args[:auth_name], value: args[:auth_value] }
            }
          }
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
linkedin2-0.0.17 lib/linkedin/api/invitation.rb