Class: Contactology::Campaign
- Extended by:
- API
- Defined in:
- lib/contactology/campaign.rb,
lib/contactology/campaign/preview.rb
Overview
Campaigns represent mailing objects on Contactology. These objects may be “standard,” meaning that they go out to a List, or “transactional,” meaning that they’re generated per recipient and used multiple times.
Direct Known Subclasses
Contactology::Campaigns::Standard, Contactology::Campaigns::Transactional
Defined Under Namespace
Classes: Preview
Class Method Summary collapse
-
.create(attributes, options = {}) ⇒ Object
Public: Creates a new Campaign on Contactology.
-
.find(id, options = {}) ⇒ Object
Public: Load the campaign details for a given Contactology Campaign ID.
- .find_by_name(name, options = {}) ⇒ Object
Instance Method Summary collapse
-
#destroy(options = {}) ⇒ Object
Public: Removes the Campaign from Contactology.
- #preview(options = {}) ⇒ Object
-
#save(options = {}) ⇒ Object
Private: This method should be overridden by subclasses of Campaign.
-
#save!(options = {}) ⇒ Object
Public: Creates the instance on Contactology or raises an exception.
- #start_time ⇒ Object
Methods included from API
Methods inherited from Stash
Class Method Details
.create(attributes, options = {}) ⇒ Object
Public: Creates a new Campaign on Contactology. This method should not be directly called, but instead called through the Standard or Transactional campaign classes.
Returns a campaign instance when successful. Returns false when unsuccessful.
54 55 56 57 |
# File 'lib/contactology/campaign.rb', line 54 def self.create(attributes, = {}) campaign = new(attributes) campaign.save() ? campaign : false end |
.find(id, options = {}) ⇒ Object
Public: Load the campaign details for a given Contactology Campaign ID.
Returns a Contactology::Campaign instance when found. Returns nil for an unrecognized ID or network error.
65 66 67 68 69 70 |
# File 'lib/contactology/campaign.rb', line 65 def self.find(id, = {}) query('Campaign_Get_Info', .merge({ 'campaignId' => id, :on_success => Proc.new { |r| new_campaign_from_response(r) } })) end |
.find_by_name(name, options = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/contactology/campaign.rb', line 72 def self.find_by_name(name, = {}) query('Campaign_Find', .merge({ 'searchParameters' => { 'campaignName' => name }, :on_success => Proc.new { |r| unless r.nil? data = r.values.max { |a,b| a['startTime'] <=> b['startTime'] } new_campaign_from_response(data) end } })) end |
Instance Method Details
#destroy(options = {}) ⇒ Object
Public: Removes the Campaign from Contactology.
Returns true when successful. Returns false when unsuccessful or for a network error.
93 94 95 96 97 98 99 100 |
# File 'lib/contactology/campaign.rb', line 93 def destroy( = {}) self.class.query('Campaign_Delete', .merge({ 'campaignId' => id, :on_timeout => false, :on_error => false, :on_success => Proc.new { |response| response } })) end |
#preview(options = {}) ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/contactology/campaign.rb', line 127 def preview( = {}) self.class.query('Campaign_Preview', .merge({ 'campaignId' => id, :on_error => false, :on_timeout => false, :on_success => Proc.new { |response| Preview.new(response) } })) end |
#save(options = {}) ⇒ Object
Private: This method should be overridden by subclasses of Campaign.
Raises NotImplementedError.
107 108 109 |
# File 'lib/contactology/campaign.rb', line 107 def save( = {}) raise NotImplementedError end |
#save!(options = {}) ⇒ Object
Public: Creates the instance on Contactology or raises an exception.
Returns the campaign instance when successful. Raises InvalidObjectError when unsuccessful.
117 118 119 |
# File 'lib/contactology/campaign.rb', line 117 def save!( = {}) save() || raise(InvalidObjectError) end |
#start_time ⇒ Object
121 122 123 124 125 |
# File 'lib/contactology/campaign.rb', line 121 def start_time if self['start_time'] Time.strptime(self['start_time'] + 'Z', '%Y-%m-%d %H:%M:%S%Z') end end |