Class: Hominid::Campaign
- Inherits:
-
Base
- Object
- Base
- Hominid::Campaign
show all
- Defined in:
- lib/hominid/campaign.rb
Constant Summary
Constants inherited
from Base
Base::MAILCHIMP_API_VERSION
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#add_api_key, #api_keys, #apply_defaults_to, #call, #clean_merge_tags, #expire_api_key
Constructor Details
#initialize(*args) ⇒ Campaign
Returns a new instance of Campaign.
11
12
13
14
15
16
17
|
# File 'lib/hominid/campaign.rb', line 11
def initialize(*args)
options = args.last.is_a?(Hash) ? args.last : {}
raise StandardError.new('Please provide a Campaign ID.') unless options[:id]
@campaign_id = options.delete(:id)
@attributes = options.delete(:attributes)
super(options)
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
9
10
11
|
# File 'lib/hominid/campaign.rb', line 9
def attributes
@attributes
end
|
#campaign_id ⇒ Object
8
9
10
|
# File 'lib/hominid/campaign.rb', line 8
def campaign_id
@campaign_id
end
|
Class Method Details
.all ⇒ Object
19
20
21
22
|
# File 'lib/hominid/campaign.rb', line 19
def self.all
new(:id => 0).call("campaigns").to_a.collect { |c| Campaign.new(:id => c.delete('id'), :attributes => c) }
end
|
.create(type = 'regular', options = {}, content = {}, segment_options = {}, type_opts = {}) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/hominid/campaign.rb', line 67
def self.create(type = 'regular', options = {}, content = {}, segment_options = {}, type_opts = {})
new(:id => 0).call("campaignCreate", type, options, content, segment_options, type_opts)
end
|
.find(id_or_web_id) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/hominid/campaign.rb', line 60
def self.find(id_or_web_id)
all = self.all
campaign = self.find_by_id(id_or_web_id.to_s).to_a + self.find_by_web_id(id_or_web_id.to_i).to_a
return campaign.blank? ? nil : campaign.first
end
|
.find_by_id(id) ⇒ Object
55
56
57
58
|
# File 'lib/hominid/campaign.rb', line 55
def self.find_by_id(id)
all.find { |campaign| (campaign.campaign_id == id.to_s) }
end
|
.find_by_list_id(list_id) ⇒ Object
28
29
30
31
|
# File 'lib/hominid/campaign.rb', line 28
def self.find_by_list_id(list_id)
new(:id => 0).call("campaigns", {:list_id => list_id}).to_a.collect { |c| Campaign.new(:id=> c.delete('id'), :attributes => c) }
end
|
.find_by_list_name(list_name) ⇒ Object
24
25
26
|
# File 'lib/hominid/campaign.rb', line 24
def self.find_by_list_name(list_name)
new(:id => 0).call("campaigns", {:list_id => List.find_by_name(list_name).list_id}).to_a.collect { |c| Campaign.new(:id=> c.delete('id'), :attributes => c) }
end
|
.find_by_title(title) ⇒ Object
33
34
35
36
|
# File 'lib/hominid/campaign.rb', line 33
def self.find_by_title(title)
all.find { |c| c.attributes['title'] =~ /#{title}/ }
end
|
.find_by_type(type) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/hominid/campaign.rb', line 38
def self.find_by_type(type)
all.find { |campaign| campaign.attributes['type'] =~ /#{type}/ }
end
|
.find_by_web_id(web_id) ⇒ Object
50
51
52
53
|
# File 'lib/hominid/campaign.rb', line 50
def self.find_by_web_id(web_id)
all.find { |campaign| campaign.attributes['web_id'] == web_id.to_i }
end
|
.templates ⇒ Object
93
94
95
96
|
# File 'lib/hominid/campaign.rb', line 93
def self.templates
new(:id => 0).call("campaignTemplates")
end
|
Instance Method Details
#add_order(order) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/hominid/campaign.rb', line 98
def add_order(order)
order = order.merge(:campaign_id => @campaign_id)
call("campaignEcommAddOrder", order)
end
|
#campaign_content(for_archive = true) ⇒ Object
Get the HTML & text content for a campaign :for_archive = (boolean) default true, true returns the content as it would appear in the archive, false returns the raw HTML/text
130
131
132
133
|
# File 'lib/hominid/campaign.rb', line 130
def campaign_content(for_archive = true)
call("campaignContent", @campaign_id, for_archive)
end
|
#campaign_stats ⇒ Object
123
124
125
126
|
# File 'lib/hominid/campaign.rb', line 123
def campaign_stats()
call("campaignStats", @campaign_id)
end
|
#delete_campaign ⇒ Object
135
136
137
138
|
# File 'lib/hominid/campaign.rb', line 135
def delete_campaign()
call("campaignDelete", @campaign_id)
end
|
#replicate_campaign ⇒ Object
140
141
142
143
|
# File 'lib/hominid/campaign.rb', line 140
def replicate_campaign()
call("campaignReplicate", @campaign_id)
end
|
#schedule_campaign(time = "#{1.day.from_now}") ⇒ Object
145
146
147
148
149
|
# File 'lib/hominid/campaign.rb', line 145
def schedule_campaign(time = "#{1.day.from_now}")
call("campaignSchedule", @campaign_id, time)
end
|
#send_now ⇒ Object
151
152
153
154
|
# File 'lib/hominid/campaign.rb', line 151
def send_now()
call("campaignSendNow", @campaign_id)
end
|
#send_test(emails = {}) ⇒ Object
Send a test of a campaign
157
158
159
|
# File 'lib/hominid/campaign.rb', line 157
def send_test(emails = {})
call("campaignSendTest", @campaign_id, emails)
end
|
#unschedule ⇒ Object
166
167
168
169
|
# File 'lib/hominid/campaign.rb', line 166
def unschedule()
call("campaignUnschedule", @campaign_id)
end
|
#update(name, value) ⇒ Object
161
162
163
164
|
# File 'lib/hominid/campaign.rb', line 161
def update(name, value)
call("campaignUpdate", @campaign_id, name, value)
end
|