Class: ConstantContact::Campaign

Inherits:
Base
  • Object
show all
Defined in:
lib/constant_contact/campaign.rb

Constant Summary

STATUS_CODES =
['SENT', 'SCHEDULED', 'DRAFT', 'RUNNING']
@@column_names =

SENT All campaigns that have been sent and not currently scheduled for resend SCHEDULED All campaigns that are currently scheduled to be sent some time in the future DRAFT All campaigns that have not yet been scheduled for delivery RUNNING All campaigns that are currently being processed and delivered

[:archive_status, :archive_url, :bounces, :campaign_type, :clicks, :contact_lists, :date, 
:email_content, :email_content_format, :email_text_content, :forward_email_link_text, :forwards, 
:from_email, :from_name, :greeting_name, :greeting_salutation, :greeting_string, 
:include_forward_email, :include_subscribe_link, :last_edit_date, :name, :opens, :opt_outs, 
:organization_address1, :organization_address2, :organization_address3, :organization_city, 
:organization_country, :organization_international_state, :organization_name, :organization_postal_code, 
:organization_state, :permission_reminder, :reply_to_email, :sent, :spam_reports, :status, 
:style_sheet, :subject, :subscribe_link_text, :view_as_webpage, :view_as_webpage_link_text, :view_as_webpage_text]

Constants inherited from Base

Base::DATE_FORMAT

Instance Method Summary collapse

Methods inherited from Base

#after_save, api_key, api_key=, collection_path, connection, element_path, #encode, find_every, #html_encode, #int_id, #method_missing, parse_id, #save, #update_attributes, #valid?

Constructor Details

#initialize(*args) ⇒ Campaign

Setup defaults when creating a new object since CC requires so many extraneous fields to be present when creating a new Campaign.



22
23
24
25
26
# File 'lib/constant_contact/campaign.rb', line 22

def initialize(*args)
  obj = super
  obj.set_defaults
  obj
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ConstantContact::Base

Instance Method Details

#from_email_urlObject



45
46
47
# File 'lib/constant_contact/campaign.rb', line 45

def from_email_url
  EmailAddress.find(self.from_email).id
end

#reply_to_email_urlObject



49
50
51
# File 'lib/constant_contact/campaign.rb', line 49

def reply_to_email_url
  from_email_url
end

#to_xmlObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/constant_contact/campaign.rb', line 28

def to_xml
  xml = Builder::XmlMarkup.new
  xml.tag!("Campaign", :xmlns => "http://ws.constantcontact.com/ns/1.0/") do
    self.attributes.reject {|k,v| k == 'FromEmail' || k == 'ReplyToEmail' || k == 'ContactList'}.each{|k, v| xml.tag!( k.to_s.camelize, v )}
    # Overrides the default formatting above to CC's required format.
  	xml.tag!("ReplyToEmail") do
      xml.tag!('Email', :id => self.reply_to_email_url)
	  end
  	xml.tag!("FromEmail") do
      xml.tag!('Email', :id => self.from_email_url)
	  end
  	xml.tag!("ContactLists") do 
  	  xml.tag!("ContactList", :id => self.contact_list)
  	end
  end        
end