From 60d2173a9406c984bf2963525ddbc2182a096b97 Mon Sep 17 00:00:00 2001 From: Jeremy Weiskotten Date: Thu, 8 Jan 2009 11:37:35 -0500 Subject: [PATCH] a bit of cleanup --- lib/campaign_monitor.rb | 35 ++------------------------- lib/campaign_monitor/campaign.rb | 2 ++ lib/campaign_monitor/client.rb | 2 ++ lib/campaign_monitor/helpers.rb | 38 ++++++++++++++++++++++-------- lib/campaign_monitor/list.rb | 2 ++ lib/campaign_monitor/subscriber.rb | 2 ++ 6 files changed, 38 insertions(+), 43 deletions(-) diff --git a/lib/campaign_monitor.rb b/lib/campaign_monitor.rb index 184b5c9..a40f98d 100644 --- a/lib/campaign_monitor.rb +++ b/lib/campaign_monitor.rb @@ -68,6 +68,8 @@ end class CampaignMonitor + include CampaignMonitor::Helpers + attr_reader :api_key, :api_url # Replace this API key with your own (http://www.campaignmonitor.com/api/) @@ -175,39 +177,6 @@ def add_subscriber(list_id, email, name) Result.new(Subscriber_Add("ListID" => list_id, "Email" => email, "Name" => name)) end - - def handle_response(response) - return [] if response.empty? - - if response["Code"].to_i == 0 - # success! - yield(response) - else - # error! - raise response["Code"] + " - " + response["Message"] - end - end - - def wsdl_driver_factory - SOAP::WSDLDriverFactory.new("#{api_url}?WSDL") - end - - def using_soap - driver = wsdl_driver_factory.create_rpc_driver - response = yield(driver) - driver.reset_stream - end - - def timestamp_format - '%Y-%m-%d %H:%M:%S' - end - - def formatted_timestamp(datetime, format=timestamp_format) - datetime.strftime(format) - end - - - # Encapsulates class SubscriberBounce diff --git a/lib/campaign_monitor/campaign.rb b/lib/campaign_monitor/campaign.rb index 30c0e14..d1f0c05 100644 --- a/lib/campaign_monitor/campaign.rb +++ b/lib/campaign_monitor/campaign.rb @@ -1,6 +1,8 @@ class CampaignMonitor # Provides access to the information about a campaign class Campaign + include CampaignMonitor::Helpers + attr_reader :id, :subject, :sent_date, :total_recipients, :cm_client def initialize(id=nil, subject=nil, sent_date=nil, total_recipients=nil) diff --git a/lib/campaign_monitor/client.rb b/lib/campaign_monitor/client.rb index aad5eb8..35ed73d 100644 --- a/lib/campaign_monitor/client.rb +++ b/lib/campaign_monitor/client.rb @@ -1,6 +1,8 @@ class CampaignMonitor # Provides access to the lists and campaigns associated with a client class Client + include CampaignMonitor::Helpers + attr_reader :id, :name, :cm_client # Example diff --git a/lib/campaign_monitor/helpers.rb b/lib/campaign_monitor/helpers.rb index af6269d..7ece328 100644 --- a/lib/campaign_monitor/helpers.rb +++ b/lib/campaign_monitor/helpers.rb @@ -1,17 +1,35 @@ class CampaignMonitor module Helpers - def self.included(base) - base.class_eval do - extend ClassMethods - include InstanceMethods - end + + def handle_response(response) + return [] if response.empty? + + if response["Code"].to_i == 0 + # success! + yield(response) + else + # error! + raise response["Code"] + " - " + response["Message"] + end + end + + def wsdl_driver_factory + SOAP::WSDLDriverFactory.new("#{api_url}?WSDL") + end + + def using_soap + driver = wsdl_driver_factory.create_rpc_driver + response = yield(driver) + driver.reset_stream + end + + def timestamp_format + '%Y-%m-%d %H:%M:%S' end - module ClassMethods - end - - module InstanceMethods + def formatted_timestamp(datetime, format=timestamp_format) + datetime.strftime(format) end + end - end \ No newline at end of file diff --git a/lib/campaign_monitor/list.rb b/lib/campaign_monitor/list.rb index 0696b7f..d8dadfb 100644 --- a/lib/campaign_monitor/list.rb +++ b/lib/campaign_monitor/list.rb @@ -4,6 +4,8 @@ class CampaignMonitor # Provides access to the subscribers and info about subscribers # associated with a Mailing List class List + include CampaignMonitor::Helpers + attr_reader :id, :name, :cm_client # Example diff --git a/lib/campaign_monitor/subscriber.rb b/lib/campaign_monitor/subscriber.rb index 526b25e..15aa2a1 100644 --- a/lib/campaign_monitor/subscriber.rb +++ b/lib/campaign_monitor/subscriber.rb @@ -1,6 +1,8 @@ class CampaignMonitor # Provides the ability to add/remove subscribers from a list class Subscriber + include CampaignMonitor::Helpers + attr_accessor :email_address, :name, :date_subscribed attr_reader :cm_client