Silverpop Engage and Transact Ruby API -- Extracted from ShoeDazzle.com To install drop in your project's vendor/plugin folder. Built on Rails 2.1.0. Requires hpricot, net/http, net/ftp, and uri.
Ruby
Pull request Compare This branch is 19 commits ahead of mattstagit:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
tasks
test
vendor/cache
.gitignore
.rspec
.ruby-gemset
.ruby-version
BUILD.md
Gemfile
Gemfile.lock
MIT-LICENSE
README.md
Rakefile
init.rb
install.rb
silverpop.gemspec
uninstall.rb

README.md

Silverpop

Silverpop Engage and Transact API -- Extracted from ShoeDazzle.com

Silverpop allows for seamless integration from Ruby with the Engage and Transact API. Built on Rails 2.1.0. Requires hpricot, net/http, net/ftp, and uri.

Configurations

Silverpop.configure do |config| config.setup_urls(instance_number) config.engage_username = "mail@billfloat.com" config.engage_password = "password" config.engage_ftp_username = "mail@billfloat.com" config.engage_ftp_password = "password" end

Testing

ENGAGE_INSTANCE=5 ENGAGE_USERNAME='engage_username@billfloat.com' ENGAGE_PASSWORD='engage_password' ENGAGE_FTP_USERNAME='engage_ftp_username@billfloat.com' ENGAGE_FTP_PASSWORD='engage_ftp_password' INCLUDE_REMOTE=true rspec spec

Examples

ENGAGE

Creating an import map file:

map_file_path  = 'LIST_MAP.XML'

list_info = { :action       => 'ADD_AND_UPDATE',
              :list_id      => 1234567,
              :file_type    => 0,
              :has_headers  => true }

columns   = [ { :name=>'EMAIL',         :type=>9, :is_required=>true,   :key_column=>true },
              { :name=>'FIRST_NAME',    :type=>0, :is_required=>false,  :key_column=>false },
              { :name=>'LAST_NAME',     :type=>0, :is_required=>false,  :key_column=>false } ]

mappings  = [ { :index=>1,  :name=>'EMAIL' },
              { :index=>2,  :name=>'FIRST_NAME' },
              { :index=>3,  :name=>'LAST_NAME' } ]

engage_api = Silverpop::Engage.new
engage_api.create_map_file(map_file_path, list_info, columns, mappings)

Creating the gzipped CSV data file:

csv_file_path = 'LIST_DATA.csv.gz'
users = User.all()
Zlib::GzipWriter.open(csv_file_path) do |gz|
  gz.write [ 'EMAIL', 'FIRST_NAME', 'LAST_NAME' ].join(',') + "\n"
  users.each { |u| gz.write [ u.email, u.first_name, u.last_name ].join(',') + "\n" }
  gz.close
end

FTPing import map file and gzipped CSV file over to Silverpop:

engage_api = Silverpop::Engage.new
engage_api.login
engage_api.import_list(map_file_path, csv_file_path)
engage_api.logout

Grab a list of all the queries in Silverpop and recalculate them. (This is really handy after you update your email list):

api = Silverpop::Engage.new, []
api.login

doc = Hpricot::XML( api.get_lists(1, 1) ) # Public queries
(doc/:LIST).each { |n| api.calculate_query(n.at('ID').innerHTML) }

doc = Hpricot::XML( api.get_lists(0, 1) ) # Private queries
(doc/:LIST).each { |n| api.calculate_query(n.at('ID').innerHTML) }

api.logout

Other:

Please look through the functions in lib/engage.rb

TRANSACT

Defining recipients:

recipient = { :email            => 'test@test.com',
              :personalizations => [
                  {:tag_name => 'FIRST_NAME', :value => 'Joe'},
                  {:tag_name => 'LAST_NAME',  :value => 'Schmoe'}
              ] }
recipients = [  recipient,
                { :email            => 'test2@test.com',
                :personalizations => [
                    {:tag_name => 'FIRST_NAME', :value => 'John'},
                    {:tag_name => 'LAST_NAME',  :value => 'Smith'}
                ] },
                { :email            => 'test3@test.com',
                  :personalizations => [
                    {:tag_name => 'FIRST_NAME', :value => 'Jane'},
                    {:tag_name => 'LAST_NAME',  :value => 'Doe'}
                ] } ]

Transact HTTP Sample Usage:

campaign_id = 1234567
sp = Silverpop::Transact.new campaign_id, recipients
sp.query

Transact FTP Sample Usage:

campaign_id = 1234567
options.merge!( { :send_as_batch => 'true' } )

transact = Silverpop::Transact.new(campaign_id, recipients, options)
transact.save_xml     file_path
transact.submit_batch file_path

Copyright (c) 2010 George Truong, released under the MIT license