Class: CreateSend::Campaign

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

Overview

Represents a campaign and provides associated funtionality.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(campaign_id) ⇒ Campaign

Returns a new instance of Campaign.



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

def initialize(campaign_id)
  @campaign_id = campaign_id
end

Instance Attribute Details

#campaign_idObject (readonly)

Returns the value of attribute campaign_id.



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

def campaign_id
  @campaign_id
end

Class Method Details

.create(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.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/createsend/campaign.rb', line 14

def self.create(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 }
  response = CreateSend.post "/campaigns/#{client_id}.json", options
  response.parsed_response
end

.create_from_template(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.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/createsend/campaign.rb', line 31

def self.create_from_template(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 }
  response = CreateSend.post(
    "/campaigns/#{client_id}/fromtemplate.json", options)
  response.parsed_response
end

Instance Method Details

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

Retrieves the bounces for this campaign.



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/createsend/campaign.rb', line 142

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

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

Retrieves the subscriber clicks for this campaign.



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/createsend/campaign.rb', line 116

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

#deleteObject

Deletes this campaign.



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

def delete
  response = CreateSend.delete "/campaigns/#{campaign_id}.json", {}
end

#lists_and_segmentsObject

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



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

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.



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

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

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

Retrieves the recipients of this campaign.



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

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.



59
60
61
62
63
64
# File 'lib/createsend/campaign.rb', line 59

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

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

Sends a preview of this campaign.



50
51
52
53
54
55
56
# File 'lib/createsend/campaign.rb', line 50

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

#summaryObject

Gets a summary of this campaign



78
79
80
81
# File 'lib/createsend/campaign.rb', line 78

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

#unscheduleObject

Unschedules this campaign if it is currently scheduled.



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

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

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

Retrieves the unsubscribes for this campaign.



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

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