Class: CreateSend::List

Inherits:
Object
  • Object
show all
Defined in:
lib/createsend/list.rb

Overview

Represents a subscriber list and associated functionality.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list_id) ⇒ List

Returns a new instance of List.



9
10
11
# File 'lib/createsend/list.rb', line 9

def initialize(list_id)
  @list_id = list_id
end

Instance Attribute Details

#list_idObject (readonly)

Returns the value of attribute list_id.



7
8
9
# File 'lib/createsend/list.rb', line 7

def list_id
  @list_id
end

Class Method Details

.create(client_id, title, unsubscribe_page, confirmed_opt_in, confirmation_success_page, unsubscribe_setting = "AllClientLists") ⇒ Object

Creates a new list for a client. client_id - String representing the ID of the client for whom the list

will be created

title - String representing the list title/name unsubscribe_page - String representing the url of the unsubscribe

confirmation page

confirmed_opt_in - A Boolean representing whether this should be a

confirmed opt-in (double opt-in) list

confirmation_success_page - String representing the url of the

confirmation success page

unsubscribe_setting - A String which must be either “AllClientLists” or

"OnlyThisList". See the documentation for details:
http://www.campaignmonitor.com/api/lists/#creating_a_list


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/createsend/list.rb', line 26

def self.create(client_id, title, unsubscribe_page, confirmed_opt_in,
  confirmation_success_page, unsubscribe_setting="AllClientLists")
  options = { :body => {
    :Title => title,
    :UnsubscribePage => unsubscribe_page,
    :ConfirmedOptIn => confirmed_opt_in,
    :ConfirmationSuccessPage => confirmation_success_page,
    :UnsubscribeSetting => unsubscribe_setting }.to_json }
  response = CreateSend.post "/lists/#{client_id}.json", options
  response.parsed_response
end

Instance Method Details

#activate_webhook(webhook_id) ⇒ Object

Activates a webhook associated with this list.



247
248
249
250
# File 'lib/createsend/list.rb', line 247

def activate_webhook(webhook_id)
  options = { :body => '' }
  response = put "webhooks/#{webhook_id}/activate", options
end

#active(date = "", page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object

Gets the active subscribers for this list.



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/createsend/list.rb', line 120

def active(date="", page=1, page_size=1000, order_field="email",
  order_direction="asc")
  options = { :query => {
    :date => date,
    :page => page,
    :pagesize => page_size,
    :orderfield => order_field,
    :orderdirection => order_direction } }
  response = get "active", options
  Hashie::Mash.new(response)
end

#bounced(date = "", page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object

Gets the bounced subscribers for this list.



146
147
148
149
150
151
152
153
154
155
156
# File 'lib/createsend/list.rb', line 146

def bounced(date="", page=1, page_size=1000, order_field="email",
  order_direction="asc")
  options = { :query => {
    :date => date,
    :page => page,
    :pagesize => page_size,
    :orderfield => order_field,
    :orderdirection => order_direction } }
  response = get "bounced", options
  Hashie::Mash.new(response)
end

#create_custom_field(field_name, data_type, options = [], visible_in_preference_center = true) ⇒ Object

Creates a new custom field for this list. field_name - String representing the name to be given to the field data_type - String representing the data type of the field. Valid data

types are 'Text', 'Number', 'MultiSelectOne', 'MultiSelectMany',
'Date', 'Country', and 'USState'.

options - Array of Strings representing the options for the field if it

is of type 'MultiSelectOne' or 'MultiSelectMany'.

visible_in_preference_center - Boolean indicating whether or not the

field should be visible in the subscriber preference center


52
53
54
55
56
57
58
59
60
61
# File 'lib/createsend/list.rb', line 52

def create_custom_field(field_name, data_type, options=[],
  visible_in_preference_center=true)
  options = { :body => {
    :FieldName => field_name,
    :DataType => data_type,
    :Options => options,
    :VisibleInPreferenceCenter => visible_in_preference_center }.to_json }
  response = post "customfields", options
  response.parsed_response
end

#create_webhook(events, url, payload_format) ⇒ Object

Creates a new webhook for the specified events (an array of strings). Valid events are “Subscribe”, “Deactivate”, and “Update”. Valid payload formats are “json”, and “xml”.



224
225
226
227
228
229
230
231
# File 'lib/createsend/list.rb', line 224

def create_webhook(events, url, payload_format)
  options = { :body => {
    :Events => events,
    :Url => url,
    :PayloadFormat => payload_format }.to_json }
  response = post "webhooks", options
  response.parsed_response
end

#custom_fieldsObject

Gets the custom fields for this list.



102
103
104
105
# File 'lib/createsend/list.rb', line 102

def custom_fields
  response = get "customfields"
  response.map{|item| Hashie::Mash.new(item)}
end

#deactivate_webhook(webhook_id) ⇒ Object

De-activates a webhook associated with this list.



253
254
255
256
# File 'lib/createsend/list.rb', line 253

def deactivate_webhook(webhook_id)
  options = { :body => '' }
  response = put "webhooks/#{webhook_id}/deactivate", options
end

#deleteObject

Deletes this list.



39
40
41
# File 'lib/createsend/list.rb', line 39

def delete
  response = CreateSend.delete "/lists/#{list_id}.json", {}
end

#delete_custom_field(custom_field_key) ⇒ Object

Deletes a custom field associated with this list.



79
80
81
82
83
# File 'lib/createsend/list.rb', line 79

def delete_custom_field(custom_field_key)
  custom_field_key = CGI.escape(custom_field_key)
  response = CreateSend.delete(
    "/lists/#{list_id}/customfields/#{custom_field_key}.json", {})
end

#delete_webhook(webhook_id) ⇒ Object

Deletes a webhook associated with this list.



241
242
243
244
# File 'lib/createsend/list.rb', line 241

def delete_webhook(webhook_id)
  response = CreateSend.delete(
    "/lists/#{list_id}/webhooks/#{webhook_id}.json", {})
end

#deleted(date = "", page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object

Gets the deleted subscribers for this list.



172
173
174
175
176
177
178
179
180
181
182
# File 'lib/createsend/list.rb', line 172

def deleted(date="", page=1, page_size=1000, order_field="email",
  order_direction="asc")
  options = { :query => {
    :date => date,
    :page => page,
    :pagesize => page_size,
    :orderfield => order_field,
    :orderdirection => order_direction } }
  response = get "deleted", options
  Hashie::Mash.new(response)
end

#detailsObject

Gets the details of this list.



96
97
98
99
# File 'lib/createsend/list.rb', line 96

def details
  response = CreateSend.get "/lists/#{list_id}.json", {}
  Hashie::Mash.new(response)
end

#segmentsObject

Gets the segments for this list.



108
109
110
111
# File 'lib/createsend/list.rb', line 108

def segments
  response = get "segments"
  response.map{|item| Hashie::Mash.new(item)}
end

#statsObject

Gets the stats for this list.



114
115
116
117
# File 'lib/createsend/list.rb', line 114

def stats
  response = get "stats"
  Hashie::Mash.new(response)
end

#test_webhook(webhook_id) ⇒ Object

Tests that a post can be made to the endpoint specified for the webhook identified by webhook_id.



235
236
237
238
# File 'lib/createsend/list.rb', line 235

def test_webhook(webhook_id)
  response = get "webhooks/#{webhook_id}/test"
  true # An exception will be raised if any error occurs
end

#unconfirmed(date = "", page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object

Gets the unconfirmed subscribers for this list.



133
134
135
136
137
138
139
140
141
142
143
# File 'lib/createsend/list.rb', line 133

def unconfirmed(date="", page=1, page_size=1000, order_field="email",
  order_direction="asc")
  options = { :query => {
    :date => date,
    :page => page,
    :pagesize => page_size,
    :orderfield => order_field,
    :orderdirection => order_direction } }
  response = get "unconfirmed", options
  Hashie::Mash.new(response)
end

#unsubscribed(date = "", page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object

Gets the unsubscribed subscribers for this list.



159
160
161
162
163
164
165
166
167
168
169
# File 'lib/createsend/list.rb', line 159

def unsubscribed(date="", page=1, page_size=1000, order_field="email",
  order_direction="asc")
  options = { :query => {
    :date => date,
    :page => page,
    :pagesize => page_size,
    :orderfield => order_field,
    :orderdirection => order_direction } }
  response = get "unsubscribed", options
  Hashie::Mash.new(response)
end

#update(title, unsubscribe_page, confirmed_opt_in, confirmation_success_page, unsubscribe_setting = "AllClientLists", add_unsubscribes_to_supp_list = false, scrub_active_with_supp_list = false) ⇒ Object

Updates this list. title - String representing the list title/name unsubscribe_page - String representing the url of the unsubscribe

confirmation page

confirmed_opt_in - A Boolean representing whether this should be a

confirmed opt-in (double opt-in) list

confirmation_success_page - String representing the url of the

confirmation success page

unsubscribe_setting - A String which must be either “AllClientLists” or

"OnlyThisList". See the documentation for details:
http://www.campaignmonitor.com/api/lists/#updating_a_list

add_unsubscribes_to_supp_list - When unsubscribe_setting is

"AllClientLists", a Boolean which represents whether unsubscribes from
this list should be added to the suppression list

scrub_active_with_supp_list - When unsubscribe_setting is

"AllClientLists", a Boolean which represents whether active sunscribers
should be scrubbed against the suppression list


201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/createsend/list.rb', line 201

def update(title, unsubscribe_page, confirmed_opt_in,
  confirmation_success_page, unsubscribe_setting="AllClientLists",
  add_unsubscribes_to_supp_list=false, scrub_active_with_supp_list=false)
  options = { :body => {
    :Title => title,
    :UnsubscribePage => unsubscribe_page,
    :ConfirmedOptIn => confirmed_opt_in,
    :ConfirmationSuccessPage => confirmation_success_page,
    :UnsubscribeSetting => unsubscribe_setting,
    :AddUnsubscribesToSuppList => add_unsubscribes_to_supp_list,
    :ScrubActiveWithSuppList => scrub_active_with_supp_list }.to_json }
  response = CreateSend.put "/lists/#{list_id}.json", options
end

#update_custom_field(custom_field_key, field_name, visible_in_preference_center) ⇒ Object

Updates a custom field belonging to this list. custom_field_key - String which represents the key for the custom field field_name - String representing the name to be given to the field visible_in_preference_center - Boolean indicating whether or not the

field should be visible in the subscriber preference center


68
69
70
71
72
73
74
75
76
# File 'lib/createsend/list.rb', line 68

def update_custom_field(custom_field_key, field_name,
  visible_in_preference_center)
  custom_field_key = CGI.escape(custom_field_key)
  options = { :body => {
    :FieldName => field_name,
    :VisibleInPreferenceCenter => visible_in_preference_center }.to_json }
  response = put "customfields/#{custom_field_key}", options
  response.parsed_response
end

#update_custom_field_options(custom_field_key, new_options, keep_existing_options) ⇒ Object

Updates the options of a multi-optioned custom field on this list.



86
87
88
89
90
91
92
93
# File 'lib/createsend/list.rb', line 86

def update_custom_field_options(custom_field_key, new_options,
  keep_existing_options)
  custom_field_key = CGI.escape(custom_field_key)
  options = { :body => {
    :Options => new_options,
    :KeepExistingOptions => keep_existing_options }.to_json }
  response = put "customfields/#{custom_field_key}/options", options
end

#webhooksObject

Gets the webhooks for this list.



216
217
218
219
# File 'lib/createsend/list.rb', line 216

def webhooks
  response = get "webhooks"
  response.map{|item| Hashie::Mash.new(item)}
end