diff --git a/lib/constant_contact.rb b/lib/constant_contact.rb index f166e7b..dc53796 100644 --- a/lib/constant_contact.rb +++ b/lib/constant_contact.rb @@ -9,6 +9,7 @@ require File.join(directory, 'constant_contact', 'member') require File.join(directory, 'constant_contact', 'contact') require File.join(directory, 'constant_contact', 'campaign') +require File.join(directory, 'constant_contact', 'campaign_schedule') require File.join(directory, 'constant_contact', 'campaign_event', 'campaign_event_base') require File.join(directory, 'constant_contact', 'campaign_event', 'bounce_event') require File.join(directory, 'constant_contact', 'campaign_event', 'forward_event') diff --git a/lib/constant_contact/campaign.rb b/lib/constant_contact/campaign.rb index 0a765f6..a34d18c 100644 --- a/lib/constant_contact/campaign.rb +++ b/lib/constant_contact/campaign.rb @@ -6,15 +6,15 @@ class Campaign < Base # 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 - @@column_names = [: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] - + @@column_names = [: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] + # Setup defaults when creating a new object since # CC requires so many extraneous fields to be present @@ -24,24 +24,31 @@ def initialize(*args) obj.set_defaults obj end - + 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) + + xml.tag!("ContactLists") do + if self.contact_list.kind_of?(Array) then + self.contact_list.each {|x| xml.tag!("ContactList", :id => x)} + else + xml.tag!("ContactList", :id => self.contact_list) + end end - end + end end - + def from_email_url EmailAddress.find(self.from_email).id end @@ -49,8 +56,8 @@ def from_email_url def reply_to_email_url from_email_url end - - + + protected def set_defaults self.view_as_webpage = 'NO' unless attributes.has_key?('ViewAsWebpage') @@ -76,31 +83,31 @@ def set_defaults self.organization_country = 'US' unless attributes.has_key?('OrganizationCountry') self.organization_postal_code = '64108' unless attributes.has_key?('OrganizationPostalCode') end - + # Formats data if present. def before_save self.email_text_content = "#{email_text_content}" unless email_text_content.match /^\ 'http://ws.constantcontact.com/ns/1.0/', :id => schedule_url) do + self.attributes.reject {|k,v| k.to_s.camelize == 'CampaignId'}.each{|k, v| xml.tag!( k.to_s.camelize, v )} + end + end + + def campaign_url + 'http://api.constantcontact.com' + end + + def campaign_path + '/ws/customers/' + self.class.user + '/campaigns/' + self.prefix_options[:campaign_id].to_s + end + + def schedule_path + '/schedules/1' + end + + def schedule_url + campaign_url + campaign_path + schedule_path + end + + # Overridden from CTCT::Base + def encode + tn = Time.now.strftime(DATE_FORMAT) + " + + #{self.schedule_url} + #{tn} + #{tn} + WHERE, Inc + + #{self.to_xml} + + " + end + end +end diff --git a/lib/constant_contact/version.rb b/lib/constant_contact/version.rb index d818219..cf6cb7f 100644 --- a/lib/constant_contact/version.rb +++ b/lib/constant_contact/version.rb @@ -1,3 +1,3 @@ module ConstantContact - VERSION = '1.4.0'.freeze -end \ No newline at end of file + VERSION = '1.5.1'.freeze +end