Class: Campaigning::Subscriber

Inherits:
Object
  • Object
show all
Includes:
ModuleMixin
Defined in:
lib/campaigning/soap/generated/default.rb,
lib/campaigning/subscriber.rb

Overview

/Subscriber

emailAddress - SOAP::SOAPString
name - SOAP::SOAPString
date - SOAP::SOAPString
state - SOAP::SOAPString
customFields - Campaigning::ArrayOfSubscriberCustomField

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModuleMixin

#handle_response, included

Constructor Details

#initialize(emailAddress = nil, name = nil, date = nil, state = nil, customFields = nil) ⇒ Subscriber



14
15
16
17
18
19
20
# File 'lib/campaigning/subscriber.rb', line 14

def initialize(emailAddress = nil, name = nil, date = nil, state = nil, customFields = nil)
  @emailAddress = emailAddress
  @name = name
  @date = date
  @state = state
  @customFields = customFields
end

Instance Attribute Details

#customFieldsObject

Returns the value of attribute customFields.



12
13
14
# File 'lib/campaigning/subscriber.rb', line 12

def customFields
  @customFields
end

#dateObject

Returns the value of attribute date.



10
11
12
# File 'lib/campaigning/subscriber.rb', line 10

def date
  @date
end

#emailAddressObject

Returns the value of attribute emailAddress.



8
9
10
# File 'lib/campaigning/subscriber.rb', line 8

def emailAddress
  @emailAddress
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/campaigning/subscriber.rb', line 9

def name
  @name
end

#stateObject

Returns the value of attribute state.



11
12
13
# File 'lib/campaigning/subscriber.rb', line 11

def state
  @state
end

Class Method Details

.is_subscribed?(email, list_id) ⇒ Boolean

Returns True or False as to the existence of the given email address in the list supplied.



123
124
125
126
127
128
129
130
131
# File 'lib/campaigning/subscriber.rb', line 123

def self.is_subscribed?(email, list_id)
  response = @@soap.getIsSubscribed(
  :apiKey => CAMPAIGN_MONITOR_API_KEY,
  :listID => list_id,
  :email => email
  )
  response = handle_response response.subscribers_GetIsSubscribedResult
  response == 'True' ? true : false
end

.unsubscribe!(email, list_id) ⇒ Object

Changes the status of an Active Subscriber to an Unsubscribed Subscriber who will no longer receive campaigns sent to that Subscriber List (Same that the instance method with the same name).



108
109
110
111
112
113
114
115
# File 'lib/campaigning/subscriber.rb', line 108

def self.unsubscribe!(email, list_id)
  response = @@soap.unsubscribe(
  :apiKey => CAMPAIGN_MONITOR_API_KEY,
  :listID => list_id,
  :email => email
  )
  handle_response response.subscriber_UnsubscribeResult
end

Instance Method Details

#add!(list_id, custom_fields = {}) ⇒ Object

Adds a subscriber to a subscriber list, including adding custom field data for the subscriber. If the subscriber (email address) already exists, the name value is updated with whatever is passed in.

If the list has been set as double opt-in, they will be sent the verification email, otherwise they will be sent the confirmation email you have set up for the list being subscribed to.

Please note: If the subscriber is in an inactive state or has previously been unsubscribed, they will not be re-added to the active list. Therefore, this method should be used with caution and only where suitable.

Return:

Success: Upon a successful call, this method will return a Campaigning::Result object wich consists of a code and message fields containing a successful message.

Error: An Exception containing the cause of the error will be raised.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/campaigning/subscriber.rb', line 38

def add!(list_id, custom_fields={})
  params = {
    :apiKey => CAMPAIGN_MONITOR_API_KEY,
    :listID => list_id,
    :email => @emailAddress,
    :name => @name
  }
  if custom_fields.empty?
    response = @@soap.addSubscriber(params)
    handle_response response.subscriber_AddResult
  else
    params.merge!({:customFields => custom_fields_array(custom_fields)})
    response = @@soap.addSubscriberWithCustomFields(params)
    handle_response response.subscriber_AddWithCustomFieldsResult
  end  
end

#add_and_resubscribe!(list_id, custom_fields = {}) ⇒ Object

Adds a subscriber to a subscriber list, including adding custom field data for the subscriber. If the subscriber (email address) already exists, the name value is updated with whatever is passed in.

If the list has been set as double opt-in, they will be sent the verification email, otherwise they will be sent the confirmation email you have set up for the list being subscribed to.

Please note: If the subscriber is in an inactive state or has previously been unsubscribed, they will be re-added to the active list. Therefore, this method should be used with caution and only where suitable.

Return:

Success: Upon a successful call, this method will return a Campaigning::Result object wich consists of a code and message fields containing a successful message.

Error: An Exception containing the cause of the error will be raised.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/campaigning/subscriber.rb', line 71

def add_and_resubscribe!(list_id, custom_fields={})
  params = {
    :apiKey => CAMPAIGN_MONITOR_API_KEY,
    :listID => list_id,
    :email => @emailAddress,
    :name => @name
  }
  if custom_fields.empty?
    response = @@soap.addAndResubscribe(params)
    handle_response response.subscriber_AddAndResubscribeResult
  else
    params.merge!({:customFields => custom_fields_array(custom_fields)})
    response = @@soap.addAndResubscribeWithCustomFields(params)
    handle_response response.subscriber_AddAndResubscribeWithCustomFieldsResult
  end  
end

#is_subscribed?(list_id) ⇒ Boolean

Returns True or False as to the existence of the given email address in the list supplied.



118
119
120
# File 'lib/campaigning/subscriber.rb', line 118

def is_subscribed?(list_id)
  Subscriber.is_subscribed?(@emailAddress, list_id)
end

#unsubscribe(list_id) ⇒ Object

Changes the status of an Active Subscriber to an Unsubscribed Subscriber who will no longer receive campaigns sent to that Subscriber List.

If the list is set to add unsubscribing subscribers to the suppression list, then the subscriber’s email address will also be added to the suppression list.

Return:

Success: Upon a successful call, this method will return a Campaigning::Result object wich consists of a code and message fields containing a successful message.

Error: An Exception containing the cause of the error will be raised.



101
102
103
# File 'lib/campaigning/subscriber.rb', line 101

def unsubscribe(list_id)
  Subscriber.unsubscribe!(@emailAddress, list_id)
end