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.



209
210
211
212
# File 'lib/createsend/list.rb', line 209

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.



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/createsend/list.rb', line 95

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.



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/createsend/list.rb', line 108

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 = []) ⇒ Object

Creates a new custom field for this list.



44
45
46
47
48
49
50
51
# File 'lib/createsend/list.rb', line 44

def create_custom_field(field_name, data_type, options=[])
  options = { :body => {
    :FieldName => field_name,
    :DataType => data_type,
    :Options => options }.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”.



186
187
188
189
190
191
192
193
# File 'lib/createsend/list.rb', line 186

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.



77
78
79
80
# File 'lib/createsend/list.rb', line 77

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.



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

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.



54
55
56
57
58
# File 'lib/createsend/list.rb', line 54

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.



203
204
205
206
# File 'lib/createsend/list.rb', line 203

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.



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

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.



71
72
73
74
# File 'lib/createsend/list.rb', line 71

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

#segmentsObject

Gets the segments for this list.



83
84
85
86
# File 'lib/createsend/list.rb', line 83

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

#statsObject

Gets the stats for this list.



89
90
91
92
# File 'lib/createsend/list.rb', line 89

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.



197
198
199
200
# File 'lib/createsend/list.rb', line 197

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

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

Gets the unsubscribed subscribers for this list.



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

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


163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/createsend/list.rb', line 163

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_options(custom_field_key, new_options, keep_existing_options) ⇒ Object

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



61
62
63
64
65
66
67
68
# File 'lib/createsend/list.rb', line 61

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.



178
179
180
181
# File 'lib/createsend/list.rb', line 178

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