Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

117 lines (75 sloc) 3.672 kB
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.
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
Jump to Line
Something went wrong with that request. Please try again.