Class: ExactTarget::RequestBuilder
- Defined in:
- lib/exact_target/request_builder.rb
Instance Method Summary collapse
- #accountinfo_retrieve_attrbs ⇒ Object
- #batch_inquire(batch_id) ⇒ Object
- #email_add(name, subject, options) ⇒ Object
- #email_add_text(email_id, options) ⇒ Object
- #email_retrieve(name = nil, options = {}) ⇒ Object
- #email_retrieve_body(email_id) ⇒ Object
-
#initialize(config) ⇒ RequestBuilder
constructor
A new instance of RequestBuilder.
- #job_send(email_id, list_ids, options = {}) ⇒ Object
- #list_add(list_name, list_type = nil) ⇒ Object
- #list_bulkasync(list_id, list_status = nil) ⇒ Object
- #list_delete(id) ⇒ Object
- #list_edit(list_id, new_list_name) ⇒ Object
- #list_import(list_id, file_name, file_mapping, options = {}) ⇒ Object
- #list_importstatus(import_id) ⇒ Object
- #list_refresh_group(group_id) ⇒ Object
- #list_retrieve(id_or_name = nil) ⇒ Object
- #list_retrieve_sub(list_id, status = nil) ⇒ Object
- #list_retrievegroups ⇒ Object
- #subscriber_add(list_id, subscriber, options = {}) ⇒ Object
- #subscriber_bulkasync(list_id) ⇒ Object
- #subscriber_delete(id, email = nil) ⇒ Object
- #subscriber_edit(list_id, orig_email, subscriber, options = {}) ⇒ Object
- #subscriber_masterunsub(*email_addresses) ⇒ Object
- #subscriber_retrieve(id, email = nil) ⇒ Object
-
#tracking_bulkasync_all(job_id, start_date = nil, end_date = nil) ⇒ Object
“retrieves complete tracking data for an email send”.
- #tracking_bulkasync_all_attributes(job_id, start_date = nil, end_date = nil) ⇒ Object
- #tracking_sent_bulkasync_all(job_id) ⇒ Object
- #tracking_sent_bulkasync_all_attributes(job_id, start_date = nil, end_date = nil) ⇒ Object
- #triggered_send_add(external_key, channel_member_id, email_addresses, options = {}) ⇒ Object
- #triggeredsend_add(email, customer_key, attributes = {}) ⇒ Object
Constructor Details
#initialize(config) ⇒ RequestBuilder
6 7 8 |
# File 'lib/exact_target/request_builder.rb', line 6 def initialize(config) @config = config end |
Instance Method Details
#accountinfo_retrieve_attrbs ⇒ Object
10 11 12 13 |
# File 'lib/exact_target/request_builder.rb', line 10 def accountinfo_retrieve_attrbs ensure_executable!("accountinfo_retrieve_attrbs") build(:accountinfo, :retrieve_attrbs) end |
#batch_inquire(batch_id) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/exact_target/request_builder.rb', line 93 def batch_inquire(batch_id) ensure_executable!("batch_inquire") build( :batch, :inquire, :batchid, batch_id, :sub_action => nil, :search_value2 => nil ) end |
#email_add(name, subject, options) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/exact_target/request_builder.rb', line 187 def email_add(name, subject, ) ensure_executable!("email_add") build(:email, :add, :search_type => :omit, :search_value => :omit, :sub_action => 'HTMLPaste') do |em| em.category em.email_name name em.email_subject subject if .has_key? :body em.email_body { |eb| eb.cdata! [:body] } elsif .has_key? :file em.file_name [:file] end end end |
#email_add_text(email_id, options) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/exact_target/request_builder.rb', line 201 def email_add_text(email_id, ) ensure_executable!("email_add_text") build(:email, :add, :search_type => :emailid, :search_value => email_id, :sub_action => :text) do |em| if .has_key? :body em.email_body { |eb| eb.cdata! [:body] } elsif .has_key? :file em.file_name [:file] end end end |
#email_retrieve(name = nil, options = {}) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/exact_target/request_builder.rb', line 168 def email_retrieve(name=nil, ={}) ensure_executable!("email_retrieve") name, = nil, name if name.is_a?(Hash) start_date, end_date = %w(start_date end_date).map do |n| et_date [n.to_sym] end type = unless start_date.nil? and end_date.nil? name.nil? ? :daterange : :emailnameanddaterange else name.nil? ? nil : :emailname end build(:email, :retrieve, type, name, :sub_action => :all, :search_value2 => nil) do |em| em.daterange do |r| r.startdate start_date if start_date r.enddate end_date if end_date end end end |
#email_retrieve_body(email_id) ⇒ Object
213 214 215 216 217 218 219 |
# File 'lib/exact_target/request_builder.rb', line 213 def email_retrieve_body(email_id) ensure_executable!("email_retrieve_body") build(:email, :retrieve, :emailid, email_id, :sub_action => :htmlemail) do |em| em.search_value2 em.search_value3 end end |
#job_send(email_id, list_ids, options = {}) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/exact_target/request_builder.rb', line 248 def job_send(email_id, list_ids, ={}) ensure_executable!("job_send") = () build(:job, :send, :emailid, email_id) do |job| job. , :from_name, :from_email, :additional, :multipart_mime, :track_links, :send_date, :send_time job_send_id_list job, :lists, list_ids job_send_id_list job, :suppress, [:suppress_ids] job.test_send [:test_send] end end |
#list_add(list_name, list_type = nil) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/exact_target/request_builder.rb', line 15 def list_add(list_name, list_type=nil) ensure_executable!("list_add") list_type = :public unless %w(public private salesforce).include?(list_type.to_s) build(:list, :add) do |li| li.list_type list_type.to_s li.list_name list_name.to_s end end |
#list_bulkasync(list_id, list_status = nil) ⇒ Object
264 265 266 267 268 269 270 271 272 273 |
# File 'lib/exact_target/request_builder.rb', line 264 def list_bulkasync(list_id, list_status = nil) build( :list, :bulkasync, :sub_action => 'Subs_ToFTP', :search_type => :listid, :search_value => list_id ) do |xml| xml.search_status list_status if list_status end end |
#list_delete(id) ⇒ Object
72 73 74 75 |
# File 'lib/exact_target/request_builder.rb', line 72 def list_delete(id) ensure_executable!("list_delete") build(:list, :delete, :listid, id) end |
#list_edit(list_id, new_list_name) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/exact_target/request_builder.rb', line 24 def list_edit(list_id, new_list_name) ensure_executable!("list_edit") build(:list, :edit, :listid, list_id) do |li| li.list_name new_list_name.to_s end end |
#list_import(list_id, file_name, file_mapping, options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/exact_target/request_builder.rb', line 40 def list_import(list_id, file_name, file_mapping, ={}) ensure_executable!("list_import") = (, file_name) build(:list, :import, :listid, list_id) do |li| li. , :file_name, :email_address, :file_type, :column_headings li.file_mapping do |fm| file_mapping.each { |m| fm.field(m) } end li. , :import_type, :returnid, :encrypted, :encrypt_format end end |
#list_importstatus(import_id) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/exact_target/request_builder.rb', line 52 def list_importstatus(import_id) ensure_executable!("list_importstatus") build( :list, :import, :sub_action => :importstatus, :search_type => :omit, :search_value => import_id ) end |
#list_refresh_group(group_id) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/exact_target/request_builder.rb', line 82 def list_refresh_group(group_id) ensure_executable!("list_refresh_group") build( :list, :refresh_group, :sub_action => nil, :search_type => :omit, :search_value => group_id, :search_value2 => nil ) end |
#list_retrieve(id_or_name = nil) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/exact_target/request_builder.rb', line 31 def list_retrieve(id_or_name=nil) ensure_executable!("list_retrieve") if id_or_name.is_a?(Fixnum) or id_or_name =~ /^\d+$/ build(:list, :retrieve, :listid, id_or_name.to_i) else build(:list, :retrieve, :listname, id_or_name) end end |
#list_retrieve_sub(list_id, status = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/exact_target/request_builder.rb', line 62 def list_retrieve_sub(list_id, status=nil) ensure_executable!("list_retrieve_sub") unless status.nil? or %w(Active Unsubscribed Returned Undeliverable Deleted).include?(status) raise "Invalid status: #{status}" end build(:list, :retrieve_sub, :listid, list_id) do |li| li.search_status status unless status.nil? end end |
#list_retrievegroups ⇒ Object
77 78 79 80 |
# File 'lib/exact_target/request_builder.rb', line 77 def list_retrievegroups ensure_executable!("list_retrievegroups") build(:list, :retrievegroups, :groups) end |
#subscriber_add(list_id, subscriber, options = {}) ⇒ Object
122 123 124 125 |
# File 'lib/exact_target/request_builder.rb', line 122 def subscriber_add(list_id, subscriber, ={}) ensure_executable!("subscriber_add") subscriber_edit(list_id, nil, subscriber, ) end |
#subscriber_bulkasync(list_id) ⇒ Object
275 276 277 278 279 280 |
# File 'lib/exact_target/request_builder.rb', line 275 def subscriber_bulkasync(list_id) build(:subscriber, :BulkAsync, :sub_action => "SubsStatus_ToFTP", :search_type => "lid", :search_value => list_id) end |
#subscriber_delete(id, email = nil) ⇒ Object
151 152 153 154 155 |
# File 'lib/exact_target/request_builder.rb', line 151 def subscriber_delete(id, email=nil) ensure_executable!("subscriber_delete") type = email.blank? ? :subid : :listid build(:subscriber, :delete, type, id, :search_value2 => email) end |
#subscriber_edit(list_id, orig_email, subscriber, options = {}) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/exact_target/request_builder.rb', line 127 def subscriber_edit(list_id, orig_email, subscriber, ={}) ensure_executable!("subscriber_edit") = () subscriber = subscriber.to_et_hash if subscriber.is_a?(Subscriber) action = orig_email.nil? ? :add : :edit build(:subscriber, action, :listid, list_id, :search_value2 => orig_email) do |sub| sub.values do |vs| subscriber.each do |k, v| vs.tag!(k.to_s, v) unless k.to_s =~ /status/i end vs.status [:status].to_s vs.reason [:reason] if .has_key? :reason vs.ChannelMemberID [:ChannelMemberID] if .has_key? :ChannelMemberID end sub.update [:update] if orig_email.nil? end end |
#subscriber_masterunsub(*email_addresses) ⇒ Object
157 158 159 160 161 162 163 164 |
# File 'lib/exact_target/request_builder.rb', line 157 def subscriber_masterunsub(*email_addresses) ensure_executable!("subscriber_masterunsub") build(:subscriber, :masterunsub, :emailaddress, :search_value => :omit) do |sub| sub.search_value do |sv| email_addresses.flatten.each { |a| sv.emailaddress(a) } end end end |
#subscriber_retrieve(id, email = nil) ⇒ Object
145 146 147 148 149 |
# File 'lib/exact_target/request_builder.rb', line 145 def subscriber_retrieve(id, email=nil) ensure_executable!("subscriber_retrieve") type = email.blank? ? :subid : :listid build(:subscriber, :retrieve, type, id, :search_value2 => email) end |
#tracking_bulkasync_all(job_id, start_date = nil, end_date = nil) ⇒ Object
“retrieves complete tracking data for an email send”
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/exact_target/request_builder.rb', line 283 def tracking_bulkasync_all(job_id, start_date = nil, end_date = nil) build(:tracking, :BulkAsync, :sub_action => "all_ToFTP", :search_type => "jobID", :search_value => job_id) do |xml| if start_date || end_date start_date = start_date.strftime("%m/%d/%Y") if start_date.respond_to?(:strftime) end_date = end_date.strftime("%m/%d/%Y") if end_date.respond_to?(:strftime) xml.daterange do xml.startdate start_date xml.enddate end_date end end end end |
#tracking_bulkasync_all_attributes(job_id, start_date = nil, end_date = nil) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/exact_target/request_builder.rb', line 299 def tracking_bulkasync_all_attributes(job_id, start_date = nil, end_date = nil) build(:tracking, :BulkAsync, :sub_action => "all_attributes_ToFTP", :search_type => "jobID", :search_value => job_id) do |xml| if start_date || end_date start_date = start_date.strftime("%m/%d/%Y") if start_date.respond_to?(:strftime) end_date = end_date.strftime("%m/%d/%Y") if end_date.respond_to?(:strftime) xml.daterange do xml.startdate start_date xml.enddate end_date end end end end |
#tracking_sent_bulkasync_all(job_id) ⇒ Object
315 316 317 318 319 320 |
# File 'lib/exact_target/request_builder.rb', line 315 def tracking_sent_bulkasync_all(job_id) build(:tracking, :Sent_BulkAsync, :sub_action => "all_ToFTP", :search_type => "jobID", :search_value => job_id) end |
#tracking_sent_bulkasync_all_attributes(job_id, start_date = nil, end_date = nil) ⇒ Object
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/exact_target/request_builder.rb', line 322 def tracking_sent_bulkasync_all_attributes(job_id, start_date = nil, end_date = nil) build(:tracking, :Sent_BulkAsync, :sub_action => "all_attributes_ToFTP", :search_type => "jobID", :search_value => job_id) do |xml| if start_date || end_date start_date = start_date.strftime("%m/%d/%Y") if start_date.respond_to?(:strftime) end_date = end_date.strftime("%m/%d/%Y") if end_date.respond_to?(:strftime) xml.daterange do xml.startdate start_date xml.enddate end_date end end end end |
#triggered_send_add(external_key, channel_member_id, email_addresses, options = {}) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/exact_target/request_builder.rb', line 104 def triggered_send_add(external_key, channel_member_id, email_addresses, ={}) build(:triggeredsend, :add, :search_type => :omit, :search_value => :omit) do |operation| operation.TriggeredSend('xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema', 'xmlns' => 'http://exacttarget.com/wsdl/partnerAPI') do |ts| ts.TriggeredSendDefinition do |tsd| tsd.CustomerKey external_key tsd.Priority 'High' end email_addresses.each do |addr| build_ts_subscriber(ts, channel_member_id, addr, ) end end end end |
#triggeredsend_add(email, customer_key, attributes = {}) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/exact_target/request_builder.rb', line 223 def triggeredsend_add(email, customer_key, attributes = {}) ensure_executable!("triggeredsend_add", email) build(:triggeredsend, :add) do |xml| xml.TriggeredSend :"xmlns:xsi" => "http://www.w3.org/2001/XMLSchemainstance", :"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema", :"xmlns" => "http://exacttarget.com/wsdl/partnerAPI" do xml.TriggeredSendDefinition do xml.CustomerKey customer_key end xml.Subscribers do xml.EmailAddress email xml.SubscriberKey email end attributes.each do |key, value| xml.Attributes do xml.Name key.to_s xml.Value {|v| v.cdata! value.to_s } end end end end end |