Class: CampaignMonitor::Subscriber

Inherits:
Base
  • Object
show all
Includes:
Helpers
Defined in:
lib/campaign_monitor/subscriber.rb

Overview

Provides the ability to add/remove subscribers from a list

Instance Attribute Summary collapse

Attributes inherited from Base

#attributes, #cm_client, #result

Instance Method Summary collapse

Methods included from Helpers

#formatted_timestamp, #handle_response, #timestamp_format

Methods inherited from Base

#[], #[]=, client, client=, #id, #id=

Constructor Details

#initialize(email_address, name = nil, date = nil) ⇒ Subscriber

Returns a new instance of Subscriber.



8
9
10
11
12
13
# File 'lib/campaign_monitor/subscriber.rb', line 8

def initialize(email_address, name=nil, date=nil)
  @email_address = email_address
  @name = name
  @date_subscribed = date_subscribed
  super
end

Instance Attribute Details

#date_subscribedObject

Returns the value of attribute date_subscribed.



6
7
8
# File 'lib/campaign_monitor/subscriber.rb', line 6

def date_subscribed
  @date_subscribed
end

#email_addressObject

Returns the value of attribute email_address.



6
7
8
# File 'lib/campaign_monitor/subscriber.rb', line 6

def email_address
  @email_address
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/campaign_monitor/subscriber.rb', line 6

def name
  @name
end

Instance Method Details

#add(list_id) ⇒ Object

Example

@subscriber = Subscriber.new("[email protected]")
@subscriber.add(12345)


18
19
20
# File 'lib/campaign_monitor/subscriber.rb', line 18

def add(list_id)
  Result.new(cm_client.Subscriber_Add("ListID" => list_id, "Email" => @email_address, "Name" => @name))
end

#add_and_resubscribe(list_id) ⇒ Object

Example

@subscriber = Subscriber.new("[email protected]")
@subscriber.add_and_resubscribe(12345)


25
26
27
# File 'lib/campaign_monitor/subscriber.rb', line 25

def add_and_resubscribe(list_id)
  Result.new(cm_client.Subscriber_AddAndResubscribe("ListID" => list_id, "Email" => @email_address, "Name" => @name))
end

#is_subscribed?(list_id) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/campaign_monitor/subscriber.rb', line 36

def is_subscribed?(list_id)
  result = cm_client.Subscribers_GetIsSubscribed("ListID" => list_id, "Email" => @email_address)
  return true if result == 'True'
  return false if result == 'False'
  raise "Invalid value for is_subscribed?: #{result}"
end

#unsubscribe(list_id) ⇒ Object

Example

@subscriber = Subscriber.new("[email protected]")
@subscriber.unsubscribe(12345)


32
33
34
# File 'lib/campaign_monitor/subscriber.rb', line 32

def unsubscribe(list_id)
  Result.new(cm_client.Subscriber_Unsubscribe("ListID" => list_id, "Email" => @email_address))
end