Sha256: db6ca1cde059148bb6cebcc3b3d9bd94c4369d452ac6f617fe74c963dfee1720

Contents?: true

Size: 804 Bytes

Versions: 3

Compression:

Stored size: 804 Bytes

Contents

module LinkedIn
  module API
    module Messaging
      def message(subject, message, recipient_selectors, **opts)
        message_body = build_message_body selectors: [recipient_selectors].flatten,
                                          subject: subject, message: message

        execute 'people/~/mailbox', opts.merge(method: :post, body: message_body)
      end

      private

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

        recipients = args[:selectors].map { |sel| { person: { _path: "/people/#{sel.to_param}" } } }

        { recipients: { values: recipients }, subject: args[:subject], body: args[:message] }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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