Class: CreateSend::Campaign

Inherits:
CreateSend show all
Defined in:
lib/createsend/campaign.rb

Overview

Represents a campaign and provides associated functionality.

Constant Summary

Constants included from CreateSend

USER_AGENT_STRING, VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth, campaign_id) ⇒ Campaign

Returns a new instance of Campaign.



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

def initialize(auth, campaign_id)
  @campaign_id = campaign_id
  super
end

Instance Attribute Details

#campaign_idObject (readonly)

Returns the value of attribute campaign_id.



4
5
6
# File 'lib/createsend/campaign.rb', line 4

def campaign_id
  @campaign_id
end

Class Method Details

.create(auth, client_id, subject, name, from_name, from_email, reply_to, html_url, text_url, list_ids, segment_ids) ⇒ Object

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

campaign will be created.

subject - String representing the subject of the campaign. name - String representing the name of the campaign. from_name - String representing the from name for the campaign. from_email - String representing the from address for the campaign. reply_to - String representing the reply-to address for the campaign. html_url - String representing the URL for the campaign HTML content. text_url - String representing the URL for the campaign text content.

Note that text_url is optional and if nil or an empty string, text
content will be automatically generated from the HTML content.

list_ids - Array of Strings representing the IDs of the lists to

which the campaign will be sent.

segment_ids - Array of Strings representing the IDs of the segments to

which the campaign will be sent.


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/createsend/campaign.rb', line 27

def self.create(auth, client_id, subject, name, from_name, from_email,
  reply_to, html_url, text_url, list_ids, segment_ids)
  options = { :body => {
    :Subject => subject,
    :Name => name,
    :FromName => from_name,
    :FromEmail => from_email,
    :ReplyTo => reply_to,
    :HtmlUrl => html_url,
    :TextUrl => text_url,
    :ListIDs => list_ids,
    :SegmentIDs => segment_ids }.to_json }
  cs = CreateSend.new auth
  response = cs.post "/campaigns/#{client_id}.json", options
  response.parsed_response
end

.create_from_template(auth, client_id, subject, name, from_name, from_email, reply_to, list_ids, segment_ids, template_id, template_content) ⇒ Object

Creates a new campaign for a client, from a template. client_id - String representing the ID of the client for whom the

campaign will be created.

subject - String representing the subject of the campaign. name - String representing the name of the campaign. from_name - String representing the from name for the campaign. from_email - String representing the from address for the campaign. reply_to - String representing the reply-to address for the campaign. list_ids - Array of Strings representing the IDs of the lists to

which the campaign will be sent.

segment_ids - Array of Strings representing the IDs of the segments to

which the campaign will be sent.

template_id - String representing the ID of the template on which

the campaign will be based.

template_content - Hash representing the content to be used for the

editable areas of the template. See documentation at
campaignmonitor.com/api/campaigns/#creating_a_campaign_from_template
for full details of template content format.


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/createsend/campaign.rb', line 62

def self.create_from_template(auth, client_id, subject, name, from_name,
  from_email, reply_to, list_ids, segment_ids, template_id,
  template_content)
  options = { :body => {
    :Subject => subject,
    :Name => name,
    :FromName => from_name,
    :FromEmail => from_email,
    :ReplyTo => reply_to,
    :ListIDs => list_ids,
    :SegmentIDs => segment_ids,
    :TemplateID => template_id,
    :TemplateContent => template_content }.to_json }
  cs = CreateSend.new auth
  response = cs.post(
    "/campaigns/#{client_id}/fromtemplate.json", options)
  response.parsed_response
end

Instance Method Details

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

Retrieves the bounces for this campaign.



169
170
171
172
173
# File 'lib/createsend/campaign.rb', line 169

def bounces(date="", page=1, page_size=1000, order_field="date",
  order_direction="asc")
  paged_result_by_date("bounces", date, page, page_size, order_field,
    order_direction)
end

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

Retrieves the subscriber clicks for this campaign.



148
149
150
151
152
# File 'lib/createsend/campaign.rb', line 148

def clicks(date="", page=1, page_size=1000, order_field="date",
  order_direction="asc")
  paged_result_by_date("clicks", date, page, page_size, order_field,
    order_direction)
end

#deleteObject

Deletes this campaign.



105
106
107
# File 'lib/createsend/campaign.rb', line 105

def delete
  super "/campaigns/#{campaign_id}.json", {}
end

#email_client_usageObject

Gets the email clients that subscribers used to open the campaign



116
117
118
119
# File 'lib/createsend/campaign.rb', line 116

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

#lists_and_segmentsObject

Retrieves the lists and segments to which this campaaign will be (or was) sent.



123
124
125
126
# File 'lib/createsend/campaign.rb', line 123

def lists_and_segments
  response = get "listsandsegments", {}
  Hashie::Mash.new(response)
end

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

Retrieves the opens for this campaign.



141
142
143
144
145
# File 'lib/createsend/campaign.rb', line 141

def opens(date="", page=1, page_size=1000, order_field="date",
  order_direction="asc")
  paged_result_by_date("opens", date, page, page_size, order_field,
    order_direction)
end

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

Retrieves the recipients of this campaign.



129
130
131
132
133
134
135
136
137
138
# File 'lib/createsend/campaign.rb', line 129

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

#send(confirmation_email, send_date = "immediately") ⇒ Object

Sends this campaign.



91
92
93
94
95
96
# File 'lib/createsend/campaign.rb', line 91

def send(confirmation_email, send_date="immediately")
  options = { :body => {
    :ConfirmationEmail => confirmation_email,
    :SendDate => send_date }.to_json }
  post "send", options
end

#send_preview(recipients, personalize = "fallback") ⇒ Object

Sends a preview of this campaign.



82
83
84
85
86
87
88
# File 'lib/createsend/campaign.rb', line 82

def send_preview(recipients, personalize="fallback")
  options = { :body => {
    :PreviewRecipients => recipients.kind_of?(String) ?
      [ recipients ] : recipients,
    :Personalize => personalize }.to_json }
  post "sendpreview", options
end

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

Retrieves the spam complaints for this campaign.



162
163
164
165
166
# File 'lib/createsend/campaign.rb', line 162

def spam(date="", page=1, page_size=1000, order_field="date",
  order_direction="asc")
  paged_result_by_date("spam", date, page, page_size, order_field,
    order_direction)
end

#summaryObject

Gets a summary of this campaign



110
111
112
113
# File 'lib/createsend/campaign.rb', line 110

def summary
  response = get "summary", {}
  Hashie::Mash.new(response)
end

#unscheduleObject

Unschedules this campaign if it is currently scheduled.



99
100
101
102
# File 'lib/createsend/campaign.rb', line 99

def unschedule
  options = { :body => "" }
  post "unschedule", options
end

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

Retrieves the unsubscribes for this campaign.



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

def unsubscribes(date="", page=1, page_size=1000, order_field="date",
  order_direction="asc")
  paged_result_by_date("unsubscribes", date, page, page_size, order_field,
    order_direction)
end