Class: Contactology::Campaign

Inherits:
Stash
  • Object
show all
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.

Defined Under Namespace

Classes: Preview

Class Method Summary collapse

Instance Method Summary collapse

Methods included from API

query, request_headers

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, options = {})
  campaign = new(attributes)
  campaign.save(options) ? 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, options = {})
  query('Campaign_Get_Info', options.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, options = {})
  query('Campaign_Find', options.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(options = {})
  self.class.query('Campaign_Delete', options.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(options = {})
  self.class.query('Campaign_Preview', options.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.

Raises:

  • (NotImplementedError)


107
108
109
# File 'lib/contactology/campaign.rb', line 107

def save(options = {})
  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!(options = {})
  save(options) || raise(InvalidObjectError)
end

#start_timeObject



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