Class: Campaigning::Subscriber

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/campaigning/soap/generated/default.rb,
lib/campaigning/types/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 Helpers

#handle_request, handle_request

Constructor Details

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

Returns a new instance of Subscriber.



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

def initialize(emailAddress = nil, name = nil, date = nil, state = nil, customFields = nil)
  @emailAddress = emailAddress
  @name = name
  @date = date
  @state = state
  @customFields = customFields
  @soap = Campaigning::SOAPDriver.instance.get_driver
end

Instance Attribute Details

#customFieldsObject

Returns the value of attribute customFields.



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

def customFields
  @customFields
end

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#emailAddressObject

Returns the value of attribute emailAddress.



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

def emailAddress
  @emailAddress
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#stateObject

Returns the value of attribute state.



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

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.

Returns:

  • (Boolean)


160
161
162
163
164
165
166
167
168
# File 'lib/campaigning/types/subscriber.rb', line 160

def self.is_subscribed?(email, list_id)
  response = Campaigning::SOAPDriver.instance.get_driver.getIsSubscribed(
   :apiKey => CAMPAIGN_MONITOR_API_KEY,
   :listID => list_id,
   :email => email
  )
  response = Helpers.handle_request 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).



145
146
147
148
149
150
151
152
# File 'lib/campaigning/types/subscriber.rb', line 145

def self.unsubscribe(email, list_id)
  response = Campaigning::SOAPDriver.instance.get_driver.unsubscribe(
  :apiKey => CAMPAIGN_MONITOR_API_KEY,
  :listID => list_id,
  :email => email
  )
  Helpers.handle_request response.subscriber_UnsubscribeResult
end

Instance Method Details

#add(list_id) ⇒ Object

Adds a subscriber (email address, name) to an existing subscriber list. 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
# File 'lib/campaigning/types/subscriber.rb', line 39

def add(list_id)
  response = @soap.addSubscriber(
    :apiKey => CAMPAIGN_MONITOR_API_KEY,
    :listID => list_id,
    :email => @emailAddress,
    :name => @name
   )
  handle_request response.subscriber_AddResult
end

#add_and_resubscribe(list_id) ⇒ Object

Adds a subscriber (email address, name) to an existing subscriber list. 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.



64
65
66
67
68
69
70
71
72
# File 'lib/campaigning/types/subscriber.rb', line 64

def add_and_resubscribe(list_id)
  response = @soap.addAndResubscribe(
    :apiKey => CAMPAIGN_MONITOR_API_KEY,
    :listID => list_id,
    :email => @emailAddress,
    :name => @name
   )
  handle_request response.subscriber_AddAndResubscribeResult
end

#add_and_resubscribe_with_custom_fields(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, then the custom fields are 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.



90
91
92
93
94
95
96
97
98
99
# File 'lib/campaigning/types/subscriber.rb', line 90

def add_and_resubscribe_with_custom_fields(list_id, custom_fields)
  response = @soap.addAndResubscribeWithCustomFields(
  :apiKey => CAMPAIGN_MONITOR_API_KEY,
  :listID => list_id,
  :email => @emailAddress,
  :name => @name,
  :customFields => custom_fields_array(custom_fields)
  )
  handle_request response.subscriber_AddAndResubscribeWithCustomFieldsResult
end

#add_with_custom_fields(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, then the custom fields are 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.



116
117
118
119
120
121
122
123
124
125
# File 'lib/campaigning/types/subscriber.rb', line 116

def add_with_custom_fields(list_id, custom_fields)
  response = @soap.addSubscriberWithCustomFields(
  :apiKey => CAMPAIGN_MONITOR_API_KEY,
  :listID => list_id,
  :email => @emailAddress,
  :name => @name,
  :customFields => custom_fields_array(custom_fields)
  )
  handle_request response.subscriber_AddWithCustomFieldsResult
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)


155
156
157
# File 'lib/campaigning/types/subscriber.rb', line 155

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.



139
140
141
# File 'lib/campaigning/types/subscriber.rb', line 139

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