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) ⇒ Object

Creates a new list for a client.



14
15
16
17
18
19
20
21
22
# File 'lib/createsend/list.rb', line 14

def self.create(client_id, title, unsubscribe_page, confirmed_opt_in, confirmation_success_page)
  options = { :body => {
    :Title => title,
    :UnsubscribePage => unsubscribe_page,
    :ConfirmedOptIn => confirmed_opt_in,
    :ConfirmationSuccessPage => confirmation_success_page }.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.



155
156
157
158
# File 'lib/createsend/list.rb', line 155

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.



79
80
81
82
83
84
85
86
87
88
# File 'lib/createsend/list.rb', line 79

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.



91
92
93
94
95
96
97
98
99
100
# File 'lib/createsend/list.rb', line 91

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.



30
31
32
33
34
35
36
37
# File 'lib/createsend/list.rb', line 30

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”.



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

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.



61
62
63
64
# File 'lib/createsend/list.rb', line 61

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.



161
162
163
164
# File 'lib/createsend/list.rb', line 161

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

#deleteObject

Deletes this list.



25
26
27
# File 'lib/createsend/list.rb', line 25

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.



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

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.



150
151
152
# File 'lib/createsend/list.rb', line 150

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

#detailsObject

Gets the details of this list.



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

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

#segmentsObject

Gets the segments for this list.



67
68
69
70
# File 'lib/createsend/list.rb', line 67

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

#statsObject

Gets the stats for this list.



73
74
75
76
# File 'lib/createsend/list.rb', line 73

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.



144
145
146
147
# File 'lib/createsend/list.rb', line 144

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.



103
104
105
106
107
108
109
110
111
112
# File 'lib/createsend/list.rb', line 103

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) ⇒ Object

Updates this list.



115
116
117
118
119
120
121
122
# File 'lib/createsend/list.rb', line 115

def update(title, unsubscribe_page, confirmed_opt_in, confirmation_success_page)
  options = { :body => {
    :Title => title,
    :UnsubscribePage => unsubscribe_page,
    :ConfirmedOptIn => confirmed_opt_in,
    :ConfirmationSuccessPage => confirmation_success_page }.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.



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

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.



125
126
127
128
# File 'lib/createsend/list.rb', line 125

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