Sha256: 7c4707a69f6ccbfa85e5657670b5f73a53cca86f1fefce7a138e141fff8e8567

Contents?: true

Size: 1.71 KB

Versions: 3

Compression:

Stored size: 1.71 KB

Contents

module Messagemedia

    module SOAP

        #
        # This class is a light-weight wrapper around the Recipient structure used
        # by the MessageMedia SoapClient interface.
        #
        class Recipient

            attr_accessor :message_id, :destination_number

            #
            # Initialize an empty Recipient object.
            #
            # This object represents a single recipient of a message, and allows
            # an optional message ID (message_id) to be assigned to the message
            # that will be sent to that recipient.
            #
            # A destination number (destination_number) must be provided
            #
            def initialize(message_id, destination_number)
                @message_id = message_id
                @destination_number = destination_number
            end

            #
            # Return a hash that can be passed to the Savon SOAP library to
            # represent a recipient. This will be converted to XML of the form:
            #
            #     <api:recipient uid="1">+61422000000</api:recipient>
            #
            # If the recipient does not have a non-nil ID, then the 'uid'
            # attribute will be omitted.
            #
            def to_api_hash
                if @message_id.nil? then
                    {
                        :'api:recipient' => @destination_number
                    }
                else
                    {
                        :'api:recipient' => @destination_number,
                        :'attributes!' => {
                            :'api:recipient' => { 'uid' => @message_id }
                        }
                    }
                end
            end
        end
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
messagemedia-soap-0.6.4 lib/messagemedia/soap/recipient.rb
messagemedia-soap-0.6.3 lib/messagemedia/soap/recipient.rb
messagemedia-soap-0.6.2 lib/messagemedia/soap/recipient.rb