Class: CreateSend::List
- Inherits:
-
CreateSend
- Object
- CreateSend
- CreateSend::List
- Defined in:
- lib/createsend/list.rb
Overview
Represents a subscriber list and associated functionality.
Constant Summary
Constants included from CreateSend
Instance Attribute Summary collapse
-
#list_id ⇒ Object
readonly
Returns the value of attribute list_id.
Class Method Summary collapse
-
.create(auth, client_id, title, unsubscribe_page, confirmed_opt_in, confirmation_success_page, unsubscribe_setting = "AllClientLists") ⇒ Object
Creates a new list for a client.
Instance Method Summary collapse
-
#activate_webhook(webhook_id) ⇒ Object
Activates a webhook associated with this list.
-
#active(date = "", page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object
Gets the active subscribers for this list.
-
#bounced(date = "", page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object
Gets the bounced subscribers for this list.
-
#create_custom_field(field_name, data_type, options = [], visible_in_preference_center = true) ⇒ Object
Creates a new custom field for this list.
-
#create_webhook(events, url, payload_format) ⇒ Object
Creates a new webhook for the specified events (an array of strings).
-
#custom_fields ⇒ Object
Gets the custom fields for this list.
-
#deactivate_webhook(webhook_id) ⇒ Object
De-activates a webhook associated with this list.
-
#delete ⇒ Object
Deletes this list.
-
#delete_custom_field(custom_field_key) ⇒ Object
Deletes a custom field associated with this list.
-
#delete_webhook(webhook_id) ⇒ Object
Deletes a webhook associated with this list.
-
#deleted(date = "", page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object
Gets the deleted subscribers for this list.
-
#details ⇒ Object
Gets the details of this list.
-
#initialize(auth, list_id) ⇒ List
constructor
A new instance of List.
-
#segments ⇒ Object
Gets the segments for this list.
-
#stats ⇒ Object
Gets the stats for this list.
-
#test_webhook(webhook_id) ⇒ Object
Tests that a post can be made to the endpoint specified for the webhook identified by webhook_id.
-
#unconfirmed(date = "", page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object
Gets the unconfirmed subscribers for this list.
-
#unsubscribed(date = "", page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object
Gets the unsubscribed subscribers for this list.
-
#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.
-
#update_custom_field(custom_field_key, field_name, visible_in_preference_center) ⇒ Object
Updates a custom field belonging to this list.
-
#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.
-
#webhooks ⇒ Object
Gets the webhooks for this list.
Constructor Details
#initialize(auth, list_id) ⇒ List
Returns a new instance of List.
6 7 8 9 |
# File 'lib/createsend/list.rb', line 6 def initialize(auth, list_id) @list_id = list_id super end |
Instance Attribute Details
#list_id ⇒ Object (readonly)
Returns the value of attribute list_id.
4 5 6 |
# File 'lib/createsend/list.rb', line 4 def list_id @list_id end |
Class Method Details
.create(auth, 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
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/createsend/list.rb', line 24 def self.create(auth, client_id, title, unsubscribe_page, confirmed_opt_in, confirmation_success_page, unsubscribe_setting="AllClientLists") = { :body => { :Title => title, :UnsubscribePage => unsubscribe_page, :ConfirmedOptIn => confirmed_opt_in, :ConfirmationSuccessPage => confirmation_success_page, :UnsubscribeSetting => unsubscribe_setting }.to_json } cs = CreateSend.new auth response = cs.post "/lists/#{client_id}.json", response.parsed_response end |
Instance Method Details
#activate_webhook(webhook_id) ⇒ Object
Activates a webhook associated with this list.
216 217 218 219 |
# File 'lib/createsend/list.rb', line 216 def activate_webhook(webhook_id) = { :body => '' } response = put "webhooks/#{webhook_id}/activate", end |
#active(date = "", page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object
Gets the active subscribers for this list.
119 120 121 122 123 |
# File 'lib/createsend/list.rb', line 119 def active(date="", page=1, page_size=1000, order_field="email", order_direction="asc") paged_result_by_date("active", date, page, page_size, order_field, order_direction) end |
#bounced(date = "", page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object
Gets the bounced subscribers for this list.
133 134 135 136 137 |
# File 'lib/createsend/list.rb', line 133 def bounced(date="", page=1, page_size=1000, order_field="email", order_direction="asc") paged_result_by_date("bounced", date, page, page_size, order_field, order_direction) 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
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/createsend/list.rb', line 51 def create_custom_field(field_name, data_type, =[], visible_in_preference_center=true) = { :body => { :FieldName => field_name, :DataType => data_type, :Options => , :VisibleInPreferenceCenter => visible_in_preference_center }.to_json } response = post "customfields", 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”.
193 194 195 196 197 198 199 200 |
# File 'lib/createsend/list.rb', line 193 def create_webhook(events, url, payload_format) = { :body => { :Events => events, :Url => url, :PayloadFormat => payload_format }.to_json } response = post "webhooks", response.parsed_response end |
#custom_fields ⇒ Object
Gets the custom fields for this list.
101 102 103 104 |
# File 'lib/createsend/list.rb', line 101 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.
222 223 224 225 |
# File 'lib/createsend/list.rb', line 222 def deactivate_webhook(webhook_id) = { :body => '' } response = put "webhooks/#{webhook_id}/deactivate", end |
#delete ⇒ Object
Deletes this list.
38 39 40 |
# File 'lib/createsend/list.rb', line 38 def delete response = super "/lists/#{list_id}.json", {} end |
#delete_custom_field(custom_field_key) ⇒ Object
Deletes a custom field associated with this list.
78 79 80 81 82 |
# File 'lib/createsend/list.rb', line 78 def delete_custom_field(custom_field_key) custom_field_key = CGI.escape(custom_field_key) response = cs_delete( "/lists/#{list_id}/customfields/#{custom_field_key}.json", {}) end |
#delete_webhook(webhook_id) ⇒ Object
Deletes a webhook associated with this list.
210 211 212 213 |
# File 'lib/createsend/list.rb', line 210 def delete_webhook(webhook_id) response = cs_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.
147 148 149 150 151 |
# File 'lib/createsend/list.rb', line 147 def deleted(date="", page=1, page_size=1000, order_field="email", order_direction="asc") paged_result_by_date("deleted", date, page, page_size, order_field, order_direction) end |
#details ⇒ Object
Gets the details of this list.
95 96 97 98 |
# File 'lib/createsend/list.rb', line 95 def details response = cs_get "/lists/#{list_id}.json" Hashie::Mash.new(response) end |
#segments ⇒ Object
Gets the segments for this list.
107 108 109 110 |
# File 'lib/createsend/list.rb', line 107 def segments response = get "segments" response.map{|item| Hashie::Mash.new(item)} end |
#stats ⇒ Object
Gets the stats for this list.
113 114 115 116 |
# File 'lib/createsend/list.rb', line 113 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.
204 205 206 207 |
# File 'lib/createsend/list.rb', line 204 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.
126 127 128 129 130 |
# File 'lib/createsend/list.rb', line 126 def unconfirmed(date="", page=1, page_size=1000, order_field="email", order_direction="asc") paged_result_by_date("unconfirmed", date, page, page_size, order_field, order_direction) end |
#unsubscribed(date = "", page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object
Gets the unsubscribed subscribers for this list.
140 141 142 143 144 |
# File 'lib/createsend/list.rb', line 140 def unsubscribed(date="", page=1, page_size=1000, order_field="email", order_direction="asc") paged_result_by_date("unsubscribed", date, page, page_size, order_field, order_direction) 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
170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/createsend/list.rb', line 170 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) = { :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 = cs_put "/lists/#{list_id}.json", 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
67 68 69 70 71 72 73 74 75 |
# File 'lib/createsend/list.rb', line 67 def update_custom_field(custom_field_key, field_name, visible_in_preference_center) custom_field_key = CGI.escape(custom_field_key) = { :body => { :FieldName => field_name, :VisibleInPreferenceCenter => visible_in_preference_center }.to_json } response = put "customfields/#{custom_field_key}", 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.
85 86 87 88 89 90 91 92 |
# File 'lib/createsend/list.rb', line 85 def (custom_field_key, , ) custom_field_key = CGI.escape(custom_field_key) = { :body => { :Options => , :KeepExistingOptions => }.to_json } response = put "customfields/#{custom_field_key}/options", end |
#webhooks ⇒ Object
Gets the webhooks for this list.
185 186 187 188 |
# File 'lib/createsend/list.rb', line 185 def webhooks response = get "webhooks" response.map{|item| Hashie::Mash.new(item)} end |