module Cupid
class Session
def retrieve_email_folders(account)
soap_body = '
' + account.to_s + '
DataFolder
ID
Name
ParentFolder.ID
ParentFolder.Name
ContentType
like
email
'
response = build_request('Retrieve', 'RetrieveRequestMsg', soap_body)
response = Nokogiri::XML(response.http.body).remove_namespaces!
all_folders = response.css('Results').map{|f| {f.css('Name').to_a.map(&:text).join('/') => f.css('ID')[0].text}}
end
def create_email(subject, body, *args)
options = args.extract_options!
options[:subject] = CGI.escapeHTML subject.to_s
options[:body] = CGI.escapeHTML body.to_s
options[:email_type] = 'HTML'
options[:is_html_paste] = 'true' # ??
soap_body = '' +
create_email_object(options) +
''
response = build_request('Create', 'CreateRequest', soap_body)
response = Nokogiri::XML(response.http.body).remove_namespaces!
created_email_id = response.css('NewID').text
end
def create_folder(title, *args)
options = args.extract_options!
options[:title] = CGI.escapeHTML title.to_s
options[:description] ||= 'description'
options[:content_type] ||= 'email'
options[:is_active] ||= 'true'
options[:is_editable] ||= 'true'
options[:allow_children] ||= 'true'
soap_body = '' +
create_folder_object(options) +
''
response = build_request('Create', 'CreateRequest', soap_body)
response = Nokogiri::XML(response.http.body).remove_namespaces!
created_folder_id = response.css('NewID').text
end
def email_link(email_id)
"https://members.s4.exacttarget.com/Content/Email/EmailEdit.aspx?eid=" + email_id.to_s
end
def create_emails(*args)
raise NoMethodError.new "I will implement this method soon"
end
private
def create_email_object(options)
email_object = ''
email_object += '' + options[:client_id].to_s + '' if options[:client_id]
email_object += '' + options[:category_id].to_s + '' if options[:category_id]
email_object += '' + options[:name].to_s + '' if options[:name]
email_object += '' + options[:description].to_s + '' if options[:description]
email_object += '' + options[:subject] + '' +
'' + options[:body] + '' +
'' + options[:email_type] + '' +
'' + options[:is_html_paste] + ''
end
def create_folder_object(options)
folder_object = ''
folder_object += '' + options[:client_id].to_s + '' if options[:client_id]
folder_object += '' + options[:title].to_s + '' if options[:title]
folder_object += '' + options[:title].to_s + '' +
'' + options[:description].to_s + '' +
'' + options[:content_type].to_s + '' +
'' + options[:is_active].to_s + '' +
'' + options[:is_editable].to_s + '' +
'' + options[:allow_children].to_s + ''
if options[:parent]
folder_object += '
' + options[:parent].to_s + '
'
end
end
end
end