Class: Contactology::Campaigns::Transactional

Inherits:
Contactology::Campaign show all
Defined in:
lib/contactology/campaigns/transactional.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Contactology::Campaign

#destroy, find, find_by_name, #preview, #save!, #start_time

Methods included from API

#query, #request_headers

Methods inherited from Stash

#[]=

Class Method Details

.create(attributes, options = {}) ⇒ Object



37
38
39
# File 'lib/contactology/campaigns/transactional.rb', line 37

def self.create(attributes, options = {})
  new(attributes).save(options)
end

Instance Method Details

#save(options = {}) ⇒ Object

Public: Stores the campaign information onto Contactology.

Returns a Transactional instance with the campaign ID when successful. Returns a Contactology::SendResult instance with issues on failure.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/contactology/campaigns/transactional.rb', line 48

def save(options = {})
  self.class.query('Campaign_Create_Transactional', options.merge({
    'campaignName' => name,
    'content' => content,
    'senderEmail' => sender_email,
    'senderName' => sender_name,
    'subject' => subject,
    'testContact' => test_contact,
    'testReplacements' => test_replacements,
    'optionalParameters' => {
      'authenticate' => authenticate,
      'automaticTweet' => automatic_tweet,
      'clickTaleCustomFields' => click_tale_custom_fields,
      'clickTaleName' => click_tale_name,
      'googleAnalyticsName' => google_analytics_name,
      'recipientName' => recipient_name,
      'replyToEmail' => reply_to_email,
      'replyToName' => reply_to_name,
      'showInArchive' => show_in_archive,
      'trackClickThruHTML' => track_click_thru_html,
      'trackClickThruText' => track_click_thru_text,
      'trackOpens' => track_opens,
      'trackReplies' => track_replies,
      'viewInBrowser' => view_in_browser
    },
    :on_error => Proc.new { |response| process_send_campaign_result response },
    :on_timeout => Proc.new { process_send_campaign_result('success' => false, 'issues' => {'issues' => [{'text' => 'Connection error'}]}) },
    :on_success => Proc.new { |response| self.id = response; self }
  }))
end

#send_campaign(*contacts) ⇒ Object

Public: Sends the campaign.

Returns an empty collection when successful. Returns a collection of issues when unsuccessful.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/contactology/campaigns/transactional.rb', line 86

def send_campaign(*contacts)
  options = contacts.extract_options!
  replacements = [options.delete(:replacements)].flatten.compact

  self.class.query('Campaign_Send_Transactional_Multiple', options.merge({
    'campaignId' => id,
    'contacts' => contacts.collect { |c| {'email' => c.email} },
    'source' => options[:source] || 'Customer',
    'replacements' => replacements,
    'optionalParameters' => { 'continueOnError' => true },
    :on_error => Proc.new { |response| process_send_campaign_result response },
    :on_timeout => Proc.new { process_send_campaign_result('success' => false, 'issues' => {'issues' => [{'text' => 'Connection error'}]}) },
    :on_success => Proc.new { process_send_campaign_result({'success' => true}) }
  }))
end