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

Returns a new instance of Subscriber.



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

def initialize(emailAddress = nil, name = nil, date = nil, state = nil, customFields = nil, opts={})
  @apiKey = opts[:apiKey] || CAMPAIGN_MONITOR_API_KEY
  @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, opts = {}) ⇒ Boolean

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

Aviable opts arguments are:

* :apiKey - optional API key to use to make request. Will use CAMPAIGN_MONITOR_API_KEY if not set.

Returns:

  • (Boolean)


130
131
132
133
134
135
136
137
138
# File 'lib/campaigning/subscriber.rb', line 130

def self.is_subscribed?(email, list_id, opts={})
  response = @@soap.getIsSubscribed(
  :apiKey => opts[: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, opts = {}) ⇒ 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).

Aviable opts arguments are:

* :apiKey - optional API key to use to make request. Will use CAMPAIGN_MONITOR_API_KEY if not set.


112
113
114
115
116
117
118
119
# File 'lib/campaigning/subscriber.rb', line 112

def self.unsubscribe!(email, list_id, opts={})
  response = @@soap.unsubscribe(
  :apiKey => opts[: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.



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

def add!(list_id, custom_fields={})
  params = {
    :apiKey => @apiKey,
    :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.



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

def add_and_resubscribe!(list_id, custom_fields={})
  params = {
    :apiKey => @apiKey,
    :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.

Returns:

  • (Boolean)


122
123
124
# File 'lib/campaigning/subscriber.rb', line 122

def is_subscribed?(list_id)
  Subscriber.is_subscribed?(@emailAddress, list_id, :apiKey=> @apiKey)
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.



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

def unsubscribe!(list_id)
  Subscriber.unsubscribe!(@emailAddress, list_id, :apiKey=> @apiKey)
end