Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Commit

Permalink
a bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyw committed Jan 8, 2009
1 parent d94dba4 commit 60d2173
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 43 deletions.
35 changes: 2 additions & 33 deletions lib/campaign_monitor.rb
Expand Up @@ -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/)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions 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)
Expand Down
2 changes: 2 additions & 0 deletions 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
Expand Down
38 changes: 28 additions & 10 deletions 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
2 changes: 2 additions & 0 deletions lib/campaign_monitor/list.rb
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions 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

Expand Down

0 comments on commit 60d2173

Please sign in to comment.