bgetting-hominid 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +1 -1
- data/hominid.gemspec +2 -2
- data/lib/hominid.rb +51 -139
- metadata +2 -2
data/VERSION.yml
CHANGED
data/hominid.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{hominid}
|
5
|
-
s.version = "1.1.
|
5
|
+
s.version = "1.1.5"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Brian Getting"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-26}
|
10
10
|
s.description = %q{Hominid is a Rails GemPlugin for interacting with the Mailchimp API}
|
11
11
|
s.email = %q{brian@terra-firma-design.com}
|
12
12
|
s.extra_rdoc_files = [
|
data/lib/hominid.rb
CHANGED
@@ -1,18 +1,30 @@
|
|
1
1
|
require 'xmlrpc/client'
|
2
2
|
|
3
|
+
class HominidError < RuntimeError
|
4
|
+
def initialize(message)
|
5
|
+
super(message)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class HominidCommunicationError < HominidError
|
10
|
+
def initialize(message)
|
11
|
+
super(message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
3
15
|
class Hominid
|
4
16
|
|
5
17
|
# MailChimp API Documentation: http://www.mailchimp.com/api/1.2/
|
6
18
|
MAILCHIMP_API = "http://api.mailchimp.com/1.2/"
|
7
19
|
|
8
|
-
def initialize(config=nil)
|
20
|
+
def initialize(config = nil)
|
9
21
|
load_monkey_brains(config)
|
10
22
|
@chimpApi ||= XMLRPC::Client.new2(MAILCHIMP_API)
|
11
|
-
return self
|
12
23
|
end
|
13
24
|
|
14
25
|
def load_monkey_brains(config)
|
15
26
|
config = YAML.load(File.open("#{RAILS_ROOT}/config/hominid.yml"))[RAILS_ENV].symbolize_keys unless config
|
27
|
+
|
16
28
|
@chimpUsername = config[:username].to_s
|
17
29
|
@chimpPassword = config[:password].to_s
|
18
30
|
@api_key = config[:api_key]
|
@@ -44,7 +56,7 @@ class Hominid
|
|
44
56
|
def api_keys(include_expired = false)
|
45
57
|
begin
|
46
58
|
@chimpApi ||= XMLRPC::Client.new2(MAILCHIMP_API)
|
47
|
-
@api_keys = @chimpApi.call("apikeys", @chimpUsername, @chimpPassword,
|
59
|
+
@api_keys = @chimpApi.call("apikeys", @chimpUsername, @chimpPassword, include_expired)
|
48
60
|
rescue
|
49
61
|
return nil
|
50
62
|
end
|
@@ -54,11 +66,7 @@ class Hominid
|
|
54
66
|
|
55
67
|
def campaign_content(campaign_id)
|
56
68
|
# Get the content of a campaign
|
57
|
-
|
58
|
-
@content = @chimpApi.call("campaignContent", @api_key, campaign_id)
|
59
|
-
rescue
|
60
|
-
return nil
|
61
|
-
end
|
69
|
+
@content = call("campaignContent", campaign_id)
|
62
70
|
end
|
63
71
|
|
64
72
|
def campaigns(filters = {}, start = 0, limit = 50)
|
@@ -76,178 +84,102 @@ class Hominid
|
|
76
84
|
# :sedtime_start = (string) Show campaigns sent after YYYY-MM-DD HH:mm:ss.
|
77
85
|
# :sendtime_end = (string) Show campaigns sent before YYYY-MM-DD HH:mm:ss.
|
78
86
|
# :subject = (boolean) Filter by exact values, or search within content for filter values.
|
79
|
-
|
80
|
-
@campaigns = @chimpApi.call("campaigns", @api_key, filters, start, limit)
|
81
|
-
rescue
|
82
|
-
return nil
|
83
|
-
end
|
87
|
+
@campaigns = call("campaigns", filters, start, limit)
|
84
88
|
end
|
85
89
|
|
86
90
|
def create_campaign(type = 'regular', options = {}, content = {}, segment_options = {}, type_opts = {})
|
87
91
|
# Create a new campaign
|
88
|
-
|
89
|
-
@campaign = @chimpApi.call("campaignCreate", @api_key, type, options, content, segment_options, type_opts)
|
90
|
-
rescue
|
91
|
-
return nil
|
92
|
-
end
|
92
|
+
@campaign = call("campaignCreate", type, options, content, segment_options, type_opts)
|
93
93
|
end
|
94
94
|
|
95
95
|
def delete_campaign(campaign_id)
|
96
96
|
# Delete a campaign
|
97
|
-
|
98
|
-
@campaign = @chimpApi.call("campaignDelete", @api_key, campaign_id)
|
99
|
-
rescue
|
100
|
-
false
|
101
|
-
end
|
97
|
+
@campaign = call("campaignDelete", campaign_id)
|
102
98
|
end
|
103
99
|
|
104
100
|
def replicate_campaign(campaign_id)
|
105
101
|
# Replicate a campaign (returns ID of new campaign)
|
106
|
-
|
107
|
-
@campaign = @chimpApi.call("campaignReplicate", @api_key, campaign_id)
|
108
|
-
rescue
|
109
|
-
false
|
110
|
-
end
|
102
|
+
@campaign = call("campaignReplicate", campaign_id)
|
111
103
|
end
|
112
104
|
|
113
105
|
def schedule_campaign(campaign_id, time = "#{1.day.from_now}")
|
114
106
|
# Schedule a campaign
|
115
107
|
## TODO: Add support for A/B Split scheduling
|
116
|
-
|
117
|
-
@chimpApi.call("campaignSchedule", @api_key, campaign_id, time)
|
118
|
-
rescue
|
119
|
-
false
|
120
|
-
end
|
108
|
+
call("campaignSchedule", campaign_id, time)
|
121
109
|
end
|
122
110
|
|
123
111
|
def send_now(campaign_id)
|
124
112
|
# Send a campaign
|
125
|
-
|
126
|
-
@chimpApi.call("campaignSendNow", @api_key, campaign_id)
|
127
|
-
rescue
|
128
|
-
false
|
129
|
-
end
|
113
|
+
call("campaignSendNow", campaign_id)
|
130
114
|
end
|
131
115
|
|
132
116
|
def send_test(campaign_id, emails = {})
|
133
117
|
# Send a test of a campaign
|
134
|
-
|
135
|
-
@chimpApi.call("campaignSendTest", @api_key, campaign_id, emails)
|
136
|
-
rescue
|
137
|
-
false
|
138
|
-
end
|
118
|
+
call("campaignSendTest", campaign_id, emails)
|
139
119
|
end
|
140
120
|
|
141
121
|
def templates
|
142
122
|
# Get the templates
|
143
|
-
|
144
|
-
@templates = @chimpApi.call("campaignTemplates", @api_key)
|
145
|
-
rescue
|
146
|
-
return nil
|
147
|
-
end
|
123
|
+
@templates = call("campaignTemplates", @api_key)
|
148
124
|
end
|
149
125
|
|
150
126
|
def update_campaign(campaign_id, name, value)
|
151
127
|
# Update a campaign
|
152
|
-
|
153
|
-
@chimpApi.call("campaignUpdate", @api_key, campaign_id, name, value)
|
154
|
-
rescue
|
155
|
-
false
|
156
|
-
end
|
128
|
+
call("campaignUpdate", campaign_id, name, value)
|
157
129
|
end
|
158
130
|
|
159
131
|
def unschedule_campaign(campaign_id)
|
160
132
|
# Unschedule a campaign
|
161
|
-
|
162
|
-
@chimpApi.call("campaignUnschedule", @api_key, campaign_id)
|
163
|
-
rescue
|
164
|
-
false
|
165
|
-
end
|
133
|
+
call("campaignUnschedule", campaign_id)
|
166
134
|
end
|
167
135
|
|
168
136
|
## Helper methods
|
169
137
|
|
170
138
|
def html_to_text(content)
|
171
139
|
# Convert HTML content to text
|
172
|
-
|
173
|
-
@html_to_text = @chimpApi.call("generateText", @api_key, 'html', content)
|
174
|
-
rescue
|
175
|
-
return nil
|
176
|
-
end
|
140
|
+
@html_to_text = call("generateText", 'html', content)
|
177
141
|
end
|
178
142
|
|
179
143
|
def convert_css_to_inline(html, strip_css = false)
|
180
144
|
# Convert CSS styles to inline styles and (optionally) remove original styles
|
181
|
-
|
182
|
-
@html_to_text = @chimpApi.call("inlineCss", @api_key, html, strip_css)
|
183
|
-
rescue
|
184
|
-
return nil
|
185
|
-
end
|
145
|
+
@html_to_text = call("inlineCss", html, strip_css)
|
186
146
|
end
|
187
147
|
|
188
148
|
## List related methods
|
189
149
|
|
190
150
|
def lists
|
191
151
|
# Get all of the lists for this mailchimp account
|
192
|
-
|
193
|
-
@lists = @chimpApi.call("lists", @api_key)
|
194
|
-
rescue
|
195
|
-
return nil
|
196
|
-
end
|
152
|
+
@lists = call("lists", @api_key)
|
197
153
|
end
|
198
154
|
|
199
155
|
def create_group(list_id, group)
|
200
156
|
# Add an interest group to a list
|
201
|
-
|
202
|
-
@chimpApi.call("listInterestGroupAdd", @api_key, list_id, group)
|
203
|
-
rescue
|
204
|
-
false
|
205
|
-
end
|
157
|
+
call("listInterestGroupAdd", list_id, group)
|
206
158
|
end
|
207
159
|
|
208
160
|
def create_tag(list_id, tag, name, required = false)
|
209
161
|
# Add a merge tag to a list
|
210
|
-
|
211
|
-
@chimpApi.call("listMergeVarAdd", @api_key, list_id, tag, name, required)
|
212
|
-
rescue
|
213
|
-
false
|
214
|
-
end
|
162
|
+
call("listMergeVarAdd", list_id, tag, name, required)
|
215
163
|
end
|
216
164
|
|
217
165
|
def delete_group(list_id, group)
|
218
166
|
# Delete an interest group for a list
|
219
|
-
|
220
|
-
@chimpApi.call("listInterestGroupDel", @api_key, list_id, group)
|
221
|
-
rescue
|
222
|
-
false
|
223
|
-
end
|
167
|
+
call("listInterestGroupDel", list_id, group)
|
224
168
|
end
|
225
169
|
|
226
170
|
def delete_tag(list_id, tag)
|
227
171
|
# Delete a merge tag and all its members
|
228
|
-
|
229
|
-
@chimpApi.call("listMergeVarDel", @api_key, list_id, tag)
|
230
|
-
rescue
|
231
|
-
false
|
232
|
-
end
|
172
|
+
call("listMergeVarDel", list_id, tag)
|
233
173
|
end
|
234
174
|
|
235
175
|
def groups(list_id)
|
236
176
|
# Get the interest groups for a list
|
237
|
-
|
238
|
-
@groups = @chimpApi.call("listInterestGroups", @api_key, list_id)
|
239
|
-
rescue
|
240
|
-
return nil
|
241
|
-
end
|
177
|
+
@groups = call("listInterestGroups", list_id)
|
242
178
|
end
|
243
179
|
|
244
180
|
def member(list_id, email)
|
245
181
|
# Get a member of a list
|
246
|
-
|
247
|
-
@member = @chimpApi.call("listMemberInfo", @api_key, list_id, email)
|
248
|
-
rescue
|
249
|
-
return nil
|
250
|
-
end
|
182
|
+
@member = call("listMemberInfo", list_id, email)
|
251
183
|
end
|
252
184
|
|
253
185
|
def members(list_id, status = "subscribed", since = "2000-01-01 00:00:00", start = 0, limit = 100)
|
@@ -261,67 +193,47 @@ class Hominid
|
|
261
193
|
# Select members that have updated their status or profile by providing
|
262
194
|
# a "since" date in the format of YYYY-MM-DD HH:MM:SS
|
263
195
|
#
|
264
|
-
|
265
|
-
@members = @chimpApi.call("listMembers", @api_key, list_id, status, since, start, limit)
|
266
|
-
rescue
|
267
|
-
return nil
|
268
|
-
end
|
196
|
+
@members = call("listMembers", list_id, status, since, start, limit)
|
269
197
|
end
|
270
198
|
|
271
199
|
def merge_tags(list_id)
|
272
200
|
# Get the merge tags for a list
|
273
|
-
|
274
|
-
@merge_tags = @chimpApi.call("listMergeVars", @api_key, list_id)
|
275
|
-
rescue
|
276
|
-
return nil
|
277
|
-
end
|
201
|
+
@merge_tags = call("listMergeVars", list_id)
|
278
202
|
end
|
279
203
|
|
280
204
|
def subscribe(list_id, email, user_info = {}, email_type = "html", update_existing = true, replace_interests = true, double_opt_in = nil)
|
281
205
|
# Subscribe a member
|
282
|
-
|
283
|
-
@chimpApi.call("listSubscribe", @api_key, list_id, email, user_info, email_type, double_opt_in || @double_opt, update_existing, replace_interests)
|
284
|
-
rescue
|
285
|
-
false
|
286
|
-
end
|
206
|
+
call("listSubscribe", list_id, email, user_info, email_type, double_opt_in || @double_opt, update_existing, replace_interests)
|
287
207
|
end
|
288
208
|
|
289
209
|
def subscribe_many(list_id, subscribers)
|
290
210
|
# Subscribe a batch of members
|
291
211
|
# subscribers = {:EMAIL => 'example@email.com', :EMAIL_TYPE => 'html'}
|
292
|
-
|
293
|
-
@chimpApi.call("listBatchSubscribe", @api_key, list_id, subscribers, @double_opt, true)
|
294
|
-
rescue
|
295
|
-
false
|
296
|
-
end
|
212
|
+
call("listBatchSubscribe", list_id, subscribers, @double_opt, true)
|
297
213
|
end
|
298
214
|
|
299
215
|
def unsubscribe(list_id, current_email)
|
300
216
|
# Unsubscribe a list member
|
301
|
-
|
302
|
-
@chimpApi.call("listUnsubscribe", @api_key, list_id, current_email, true, @send_goodbye, @send_notify)
|
303
|
-
rescue
|
304
|
-
false
|
305
|
-
end
|
217
|
+
call("listUnsubscribe", list_id, current_email, true, @send_goodbye, @send_notify)
|
306
218
|
end
|
307
219
|
|
308
220
|
def unsubscribe_many(list_id, emails)
|
309
221
|
# Unsubscribe an array of email addresses
|
310
222
|
# emails = ['first@email.com', 'second@email.com']
|
311
|
-
|
312
|
-
@chimpApi.call("listBatchUnsubscribe", @api_key, list_id, emails, true, @send_goodbye, @send_notify)
|
313
|
-
rescue
|
314
|
-
false
|
315
|
-
end
|
223
|
+
call("listBatchUnsubscribe", list_id, emails, true, @send_goodbye, @send_notify)
|
316
224
|
end
|
317
225
|
|
318
226
|
def update_member(list_id, current_email, user_info = {}, email_type = "")
|
319
227
|
# Update a member of this list
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
228
|
+
call("listUpdateMember", list_id, current_email, user_info, email_type, true)
|
229
|
+
end
|
230
|
+
|
231
|
+
protected
|
232
|
+
def call(method, *args)
|
233
|
+
@chimpApi.call(method, @api_key, *args)
|
234
|
+
rescue XMLRPC::FaultException => error
|
235
|
+
raise HominidError.new(error.message)
|
236
|
+
rescue Exception => error
|
237
|
+
raise HominidCommunicationError.new(error.message)
|
325
238
|
end
|
326
|
-
|
327
239
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bgetting-hominid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Getting
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-26 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|