Module: LinkedIn::API::Invitation

Defined in:
lib/linkedin/api/invitation.rb

Instance Method Summary collapse

Instance Method Details

#connect_with(recipient_selector, subject, message, type: :friend, x_auth_token: nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/linkedin/api/invitation.rb', line 4

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