Sha256: b91bf58938af040820c9af8822e498ce6dc578f5f46d3aae33a89e10887c8db7

Contents?: true

Size: 1.5 KB

Versions: 7

Compression:

Stored size: 1.5 KB

Contents

module SilverPop
  class Client
    module Contact

      # Adds one new contact to an existing database.
      #
      # @param fields [Hash] The list of fields to be passed into SilverPop.
      # @param list_id [Integer] The ID of the database which you are adding the contact
      # @param contact_list_id [Array] The id of the contact list.
      # @return [Mash] Mashify body from the API call
      # @example Add a new email to the database and contact list
      #   s = SilverPop::Client.new(access_token)
      #   s.add_recipient({email: "test@example.com", firstname: "Hello"}, 12345, [4567])
      def add_recipient(fields, list_id, contact_list_id, created_from=1, options={})
        builder = Builder::XmlMarkup.new
        xml = builder.Envelope {
          builder.Body {
            builder.AddRecipient {
              builder.LIST_ID list_id
              builder.CREATED_FROM  created_from
              builder.CONTACT_LISTS {
                contact_list_id.each do |id|
                  builder.CONTACT_LIST_ID  id
                end
              }
              unless options.empty?
                options.each do |opt|
                  builder.tag! opt[0], opt[1]
                end
              end
              fields.each do |field|
                builder.COLUMN {
                  builder.NAME field[0].to_s
                  builder.VALUE field[1]
                }
              end
              }
            }
          }
        response = post(xml, options)
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
silverpop-0.0.8 lib/client/contact.rb
silverpop-0.0.7 lib/client/contact.rb
silverpop-0.0.6 lib/client/contact.rb
silverpop-0.0.5 lib/client/contact.rb
silverpop-0.0.4 lib/client/contact.rb
silverpop-0.0.3 lib/client/contact.rb
silverpop-0.0.2 lib/client/contact.rb