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

Commit

Permalink
Create Result directly from the xml and add #succeeded? & #failed? he…
Browse files Browse the repository at this point in the history
…lpers
  • Loading branch information
Empact authored and Andy Shen committed Aug 12, 2008
1 parent c5415dc commit 2030c98
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
5 changes: 2 additions & 3 deletions lib/campaign_monitor.rb
Expand Up @@ -168,12 +168,11 @@ def lists(client_id)
# @cm = CampaignMonitor.new()
# result = @cm.add_subscriber(12345, "ralph.wiggum@simpsons.net", "Ralph Wiggum")
#
# if result.code == 0
# if result.succeeded?
# puts "Subscriber Added to List"
# end
def add_subscriber(list_id, email, name)
response = Subscriber_Add("ListID" => list_id, "Email" => email, "Name" => name)
Result.new(response["Message"], response["Code"].to_i)
Result.new(Subscriber_Add("ListID" => list_id, "Email" => email, "Name" => name))
end

# Encapsulates
Expand Down
10 changes: 4 additions & 6 deletions lib/campaign_monitor/list.rb
Expand Up @@ -16,24 +16,22 @@ def initialize(id=nil, name=nil)
# @list = new List(12345)
# result = @list.add_subscriber("ralph.wiggum@simpsons.net")
#
# if result.code == 0
# if result.succeeded?
# puts "Added Subscriber"
# end
def add_subscriber(email, name = nil)
response = @cm_client.Subscriber_Add("ListID" => @id, "Email" => email, "Name" => name)
Result.new(response["Message"], response["Code"].to_i)
Result.new(@cm_client.Subscriber_Add("ListID" => @id, "Email" => email, "Name" => name))
end

# Example
# @list = new List(12345)
# result = @list.remove_subscriber("ralph.wiggum@simpsons.net")
#
# if result.code == 0
# if result.succeeded?
# puts "Deleted Subscriber"
# end
def remove_subscriber(email)
response = @cm_client.Subscriber_Unsubscribe("ListID" => @id, "Email" => email)
Result.new(response["Message"], response["Code"].to_i)
Result.new(@cm_client.Subscriber_Unsubscribe("ListID" => @id, "Email" => email))
end

# Example
Expand Down
14 changes: 11 additions & 3 deletions lib/campaign_monitor/result.rb
Expand Up @@ -3,9 +3,17 @@ class CampaignMonitor
class Result
attr_reader :message, :code

def initialize(message, code)
@message = message
@code = code
def initialize(response)
@message = response["Message"]
@code = response["Code"].to_i
end

def succeeded?
code == 0
end

def failed?
!succeeded?
end
end
end
9 changes: 3 additions & 6 deletions lib/campaign_monitor/subscriber.rb
Expand Up @@ -14,24 +14,21 @@ def initialize(email_address, name=nil, date=nil)
# @subscriber = Subscriber.new("ralph.wiggum@simpsons.net")
# @subscriber.add(12345)
def add(list_id)
response = @cm_client.Subscriber_Add("ListID" => list_id, "Email" => @email_address, "Name" => @name)
Result.new(response["Message"], response["Code"].to_i)
Result.new(@cm_client.Subscriber_Add("ListID" => list_id, "Email" => @email_address, "Name" => @name))
end

# Example
# @subscriber = Subscriber.new("ralph.wiggum@simpsons.net")
# @subscriber.add_and_resubscribe(12345)
def add_and_resubscribe(list_id)
response = @cm_client.Subscriber_AddAndResubscribe("ListID" => list_id, "Email" => @email_address, "Name" => @name)
Result.new(response["Message"], response["Code"].to_i)
Result.new(@cm_client.Subscriber_AddAndResubscribe("ListID" => list_id, "Email" => @email_address, "Name" => @name))
end

# Example
# @subscriber = Subscriber.new("ralph.wiggum@simpsons.net")
# @subscriber.unsubscribe(12345)
def unsubscribe(list_id)
response = @cm_client.Subscriber_Unsubscribe("ListID" => list_id, "Email" => @email_address)
Result.new(response["Message"], response["Code"].to_i)
Result.new(@cm_client.Subscriber_Unsubscribe("ListID" => list_id, "Email" => @email_address))
end
end
end

0 comments on commit 2030c98

Please sign in to comment.