bgetting-hominid 1.1.12 → 1.2.0
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/README.textile +16 -15
- data/Rakefile +0 -12
- data/VERSION.yml +2 -2
- data/hominid.gemspec +6 -6
- data/lib/hominid.rb +43 -54
- data/spec/hominid_spec.rb +29 -0
- data/spec/spec_helper.rb +3 -0
- metadata +6 -6
- data/test/hominid_test.rb +0 -11
- data/test/test_helper.rb +0 -3
data/README.textile
CHANGED
@@ -1,26 +1,27 @@
|
|
1
1
|
h1. Hominid
|
2
2
|
|
3
|
-
Hominid is a
|
3
|
+
Hominid is a Ruby gem for interacting with the "Mailchimp API":http://www.mailchimp.com/api/1.2/.
|
4
4
|
|
5
5
|
h2. Installation
|
6
6
|
|
7
|
-
Install
|
7
|
+
Install the gem:
|
8
8
|
|
9
|
-
<pre><code>
|
9
|
+
<pre><code>gem sources -a http://gems.github.com
|
10
|
+
sudo gem install bgetting-hominid</code></pre>
|
10
11
|
|
11
|
-
|
12
|
+
In your @environment.rb@ file:
|
12
13
|
|
13
|
-
<pre><code>
|
14
|
+
<pre><code>config.gem "bgetting-hominid", :lib => 'hominid', :source => "http://gems.github.com"</code></pre>
|
14
15
|
|
15
|
-
|
16
|
+
You can also install Hominid as a Rails plugin:
|
16
17
|
|
17
|
-
<pre><code>
|
18
|
+
<pre><code>script/plugin install git://github.com/bgetting/hominid.git</code></pre>
|
18
19
|
|
19
|
-
h2.
|
20
|
+
h2. Setup
|
20
21
|
|
21
|
-
|
22
|
+
Hominid expects to find a config file at @/config/hominid.yml@ in a Rails application, but you can also pass a hash of config options when creating a new Hominid object (thanks to "ron":http://github.com/ron).
|
22
23
|
|
23
|
-
You will also need to create a Mailchimp account to get your API key (available at "http://admin.mailchimp.com/account/api/":http://admin.mailchimp.com/account/api/)
|
24
|
+
You will also need to create a Mailchimp account to get your API key (available at "http://admin.mailchimp.com/account/api/":http://admin.mailchimp.com/account/api/) to configure a Hominid object.
|
24
25
|
|
25
26
|
h2. Example
|
26
27
|
|
@@ -43,17 +44,17 @@ def find_list_id(list_name)
|
|
43
44
|
end
|
44
45
|
</code></pre>
|
45
46
|
|
46
|
-
To subscribe
|
47
|
+
To subscribe:
|
47
48
|
|
48
|
-
<pre><code>@hominid.subscribe(@list_id, "email@example.com", {:FNAME => 'Bob', :LNAME => 'Smith'}, 'html')</code></pre>
|
49
|
+
<pre><code>@hominid.subscribe(@list_id, "email@example.com", :user_info => {:FNAME => 'Bob', :LNAME => 'Smith'}, :email_type => 'html')</code></pre>
|
49
50
|
|
50
|
-
To unsubscribe
|
51
|
+
To unsubscribe:
|
51
52
|
|
52
53
|
<pre><code>@hominid.unsubscribe(@list_id, "email@example.com")</code></pre>
|
53
54
|
|
54
|
-
To update a
|
55
|
+
To update a member:
|
55
56
|
|
56
|
-
<pre><code>@hominid.subscribe(@list_id, "email@example.com", {:FNAME => 'Robert', :EMAIL => 'another@example.com'}, 'html', true)</code></pre>
|
57
|
+
<pre><code>@hominid.subscribe(@list_id, "email@example.com", :user_info => {:FNAME => 'Robert', :EMAIL => 'another@example.com'}, :email_type => 'html', :update_existing => true)</code></pre>
|
57
58
|
|
58
59
|
_or_
|
59
60
|
|
data/Rakefile
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
2
|
require 'rake/rdoctask'
|
4
3
|
|
5
4
|
begin
|
@@ -16,17 +15,6 @@ rescue LoadError
|
|
16
15
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
16
|
end
|
18
17
|
|
19
|
-
desc 'Default: run unit tests.'
|
20
|
-
task :default => :test
|
21
|
-
|
22
|
-
desc 'Test the hominid plugin.'
|
23
|
-
Rake::TestTask.new(:test) do |t|
|
24
|
-
t.libs << 'lib'
|
25
|
-
t.libs << 'test'
|
26
|
-
t.pattern = 'test/**/*_test.rb'
|
27
|
-
t.verbose = true
|
28
|
-
end
|
29
|
-
|
30
18
|
desc 'Generate documentation for the hominid plugin.'
|
31
19
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
32
20
|
rdoc.rdoc_dir = 'rdoc'
|
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.
|
5
|
+
s.version = "1.2.0"
|
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-
|
9
|
+
s.date = %q{2009-09-24}
|
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 = [
|
@@ -23,8 +23,8 @@ Gem::Specification.new do |s|
|
|
23
23
|
"install.rb",
|
24
24
|
"lib/hominid.rb",
|
25
25
|
"rails/init.rb",
|
26
|
-
"
|
27
|
-
"
|
26
|
+
"spec/hominid_spec.rb",
|
27
|
+
"spec/spec_helper.rb",
|
28
28
|
"uninstall.rb"
|
29
29
|
]
|
30
30
|
s.homepage = %q{http://github.com/bgetting/hominid}
|
@@ -33,8 +33,8 @@ Gem::Specification.new do |s|
|
|
33
33
|
s.rubygems_version = %q{1.3.4}
|
34
34
|
s.summary = %q{Hominid is a Rails GemPlugin for interacting with the Mailchimp API}
|
35
35
|
s.test_files = [
|
36
|
-
"
|
37
|
-
"
|
36
|
+
"spec/hominid_spec.rb",
|
37
|
+
"spec/spec_helper.rb"
|
38
38
|
]
|
39
39
|
|
40
40
|
if s.respond_to? :specification_version then
|
data/lib/hominid.rb
CHANGED
@@ -17,55 +17,36 @@ class Hominid
|
|
17
17
|
# MailChimp API Documentation: http://www.mailchimp.com/api/1.2/
|
18
18
|
MAILCHIMP_API = "http://api.mailchimp.com/1.2/"
|
19
19
|
|
20
|
-
def initialize(config =
|
21
|
-
|
22
|
-
|
20
|
+
def initialize(config = {})
|
21
|
+
if defined?(RAILS_ROOT) && (!config || config.empty?)
|
22
|
+
config = YAML.load(File.open("#{RAILS_ROOT}/config/hominid.yml"))[RAILS_ENV].symbolize_keys
|
23
|
+
end
|
24
|
+
config.merge(:username => config[:username].to_s, :password => config[:password].to_s)
|
25
|
+
defaults = {:send_welcome => false, :double_opt_in => false, :update_existing => true, :replace_interests => true, :user_info => {}}
|
26
|
+
@config = defaults.merge(config).freeze
|
27
|
+
@chimpApi = XMLRPC::Client.new2(MAILCHIMP_API)
|
23
28
|
end
|
24
29
|
|
25
|
-
def load_monkey_brains(config)
|
26
|
-
config = YAML.load(File.open("#{RAILS_ROOT}/config/hominid.yml"))[RAILS_ENV].symbolize_keys unless config
|
27
|
-
@chimpUsername = config[:username].to_s
|
28
|
-
@chimpPassword = config[:password].to_s
|
29
|
-
@api_key = config[:api_key]
|
30
|
-
@send_goodbye = config[:send_goodbye]
|
31
|
-
@send_notify = config[:send_notify]
|
32
|
-
@double_opt = config[:double_opt]
|
33
|
-
end
|
34
|
-
|
35
30
|
## Security related methods
|
36
31
|
|
37
32
|
def add_api_key
|
38
|
-
|
39
|
-
@chimpApi ||= XMLRPC::Client.new2(MAILCHIMP_API)
|
40
|
-
@chimpApi.call("apikeyAdd", @chimpUsername, @chimpPassword, @api_key)
|
41
|
-
rescue
|
42
|
-
false
|
43
|
-
end
|
33
|
+
@chimpApi.call("apikeyAdd", *@config.values_at(:username, :password, :api_key))
|
44
34
|
end
|
45
35
|
|
46
36
|
def expire_api_key
|
47
|
-
|
48
|
-
@chimpApi ||= XMLRPC::Client.new2(MAILCHIMP_API)
|
49
|
-
@chimpApi.call("apikeyExpire", @chimpUsername, @chimpPassword, @api_key)
|
50
|
-
rescue
|
51
|
-
false
|
52
|
-
end
|
37
|
+
@chimpApi.call("apikeyExpire", *@config.values_at(:username, :password, :api_key))
|
53
38
|
end
|
54
39
|
|
55
40
|
def api_keys(include_expired = false)
|
56
|
-
|
57
|
-
|
58
|
-
@api_keys = @chimpApi.call("apikeys", @chimpUsername, @chimpPassword, include_expired)
|
59
|
-
rescue
|
60
|
-
return nil
|
61
|
-
end
|
41
|
+
username, password = *@config.values_at(:username, :password)
|
42
|
+
@chimpApi.call("apikeys", username, password, include_expired)
|
62
43
|
end
|
63
44
|
|
64
45
|
## Campaign related methods
|
65
46
|
|
66
47
|
def campaign_content(campaign_id)
|
67
48
|
# Get the content of a campaign
|
68
|
-
|
49
|
+
call("campaignContent", campaign_id)
|
69
50
|
end
|
70
51
|
|
71
52
|
def campaigns(filters = {}, start = 0, limit = 50)
|
@@ -83,7 +64,7 @@ class Hominid
|
|
83
64
|
# :sedtime_start = (string) Show campaigns sent after YYYY-MM-DD HH:mm:ss.
|
84
65
|
# :sendtime_end = (string) Show campaigns sent before YYYY-MM-DD HH:mm:ss.
|
85
66
|
# :subject = (boolean) Filter by exact values, or search within content for filter values.
|
86
|
-
|
67
|
+
call("campaigns", filters, start, limit)
|
87
68
|
end
|
88
69
|
|
89
70
|
# Attach Ecommerce Order Information to a Campaign.
|
@@ -108,22 +89,22 @@ class Hominid
|
|
108
89
|
# :qty = (double) the quantity of items ordered
|
109
90
|
# :cost = (double) the cost of a single item (i.e., not the extended cost of the line)
|
110
91
|
def campaign_ecomm_add_order(order)
|
111
|
-
|
92
|
+
call("campaignEcommAddOrder", order)
|
112
93
|
end
|
113
94
|
|
114
95
|
def create_campaign(type = 'regular', options = {}, content = {}, segment_options = {}, type_opts = {})
|
115
96
|
# Create a new campaign
|
116
|
-
|
97
|
+
call("campaignCreate", type, options, content, segment_options, type_opts)
|
117
98
|
end
|
118
99
|
|
119
100
|
def delete_campaign(campaign_id)
|
120
101
|
# Delete a campaign
|
121
|
-
|
102
|
+
call("campaignDelete", campaign_id)
|
122
103
|
end
|
123
104
|
|
124
105
|
def replicate_campaign(campaign_id)
|
125
106
|
# Replicate a campaign (returns ID of new campaign)
|
126
|
-
|
107
|
+
call("campaignReplicate", campaign_id)
|
127
108
|
end
|
128
109
|
|
129
110
|
def schedule_campaign(campaign_id, time = "#{1.day.from_now}")
|
@@ -144,7 +125,7 @@ class Hominid
|
|
144
125
|
|
145
126
|
def templates
|
146
127
|
# Get the templates
|
147
|
-
|
128
|
+
call("campaignTemplates")
|
148
129
|
end
|
149
130
|
|
150
131
|
def update_campaign(campaign_id, name, value)
|
@@ -161,19 +142,19 @@ class Hominid
|
|
161
142
|
|
162
143
|
def html_to_text(content)
|
163
144
|
# Convert HTML content to text
|
164
|
-
|
145
|
+
call("generateText", 'html', content)
|
165
146
|
end
|
166
147
|
|
167
148
|
def convert_css_to_inline(html, strip_css = false)
|
168
149
|
# Convert CSS styles to inline styles and (optionally) remove original styles
|
169
|
-
|
150
|
+
call("inlineCss", html, strip_css)
|
170
151
|
end
|
171
152
|
|
172
153
|
## List related methods
|
173
154
|
|
174
155
|
def lists
|
175
156
|
# Get all of the lists for this mailchimp account
|
176
|
-
|
157
|
+
call("lists")
|
177
158
|
end
|
178
159
|
|
179
160
|
def create_group(list_id, group)
|
@@ -198,12 +179,12 @@ class Hominid
|
|
198
179
|
|
199
180
|
def groups(list_id)
|
200
181
|
# Get the interest groups for a list
|
201
|
-
|
182
|
+
call("listInterestGroups", list_id)
|
202
183
|
end
|
203
184
|
|
204
185
|
def member(list_id, email)
|
205
186
|
# Get a member of a list
|
206
|
-
|
187
|
+
call("listMemberInfo", list_id, email)
|
207
188
|
end
|
208
189
|
|
209
190
|
def members(list_id, status = "subscribed", since = "2000-01-01 00:00:00", start = 0, limit = 100)
|
@@ -217,34 +198,38 @@ class Hominid
|
|
217
198
|
# Select members that have updated their status or profile by providing
|
218
199
|
# a "since" date in the format of YYYY-MM-DD HH:MM:SS
|
219
200
|
#
|
220
|
-
|
201
|
+
call("listMembers", list_id, status, since, start, limit)
|
221
202
|
end
|
222
203
|
|
223
204
|
def merge_tags(list_id)
|
224
205
|
# Get the merge tags for a list
|
225
|
-
|
206
|
+
call("listMergeVars", list_id)
|
226
207
|
end
|
227
208
|
|
228
|
-
def subscribe(list_id, email,
|
209
|
+
def subscribe(list_id, email, options = {})
|
210
|
+
options = apply_defaults_to({:email_type => "html"}.merge(options))
|
229
211
|
# Subscribe a member
|
230
|
-
call("listSubscribe", list_id, email, user_info, email_type, double_opt_in
|
212
|
+
call("listSubscribe", list_id, email, *options.values_at(:user_info, :email_type, :double_opt_in, :update_existing, :replace_interests, :send_welcome))
|
231
213
|
end
|
232
214
|
|
233
|
-
def subscribe_many(list_id, subscribers)
|
215
|
+
def subscribe_many(list_id, subscribers, options = {})
|
216
|
+
options = apply_defaults_to({:update_existing => true}.merge(options))
|
234
217
|
# Subscribe a batch of members
|
235
218
|
# subscribers = {:EMAIL => 'example@email.com', :EMAIL_TYPE => 'html'}
|
236
|
-
call("listBatchSubscribe", list_id, subscribers,
|
219
|
+
call("listBatchSubscribe", list_id, subscribers, *options.values_at(:double_opt_in, :update_existing, :replace_interests))
|
237
220
|
end
|
238
221
|
|
239
|
-
def unsubscribe(list_id, current_email)
|
222
|
+
def unsubscribe(list_id, current_email, options = {})
|
223
|
+
options = apply_defaults_to({:delete_member => true}.merge(options))
|
240
224
|
# Unsubscribe a list member
|
241
|
-
call("listUnsubscribe", list_id, current_email,
|
225
|
+
call("listUnsubscribe", list_id, current_email, *options.values_at(:delete_member, :send_goodbye, :send_notify))
|
242
226
|
end
|
243
227
|
|
244
|
-
def unsubscribe_many(list_id, emails)
|
228
|
+
def unsubscribe_many(list_id, emails, options = {})
|
229
|
+
options = apply_defaults_to({:delete_member => true}.merge(options))
|
245
230
|
# Unsubscribe an array of email addresses
|
246
231
|
# emails = ['first@email.com', 'second@email.com']
|
247
|
-
call("listBatchUnsubscribe", list_id, emails,
|
232
|
+
call("listBatchUnsubscribe", list_id, emails, *options.values_at(:delete_member, :send_goodbye, :send_notify))
|
248
233
|
end
|
249
234
|
|
250
235
|
def update_member(list_id, current_email, user_info = {}, email_type = "")
|
@@ -253,8 +238,12 @@ class Hominid
|
|
253
238
|
end
|
254
239
|
|
255
240
|
protected
|
241
|
+
def apply_defaults_to(options)
|
242
|
+
@config.merge(options)
|
243
|
+
end
|
244
|
+
|
256
245
|
def call(method, *args)
|
257
|
-
@chimpApi.call(method, @api_key, *args)
|
246
|
+
@chimpApi.call(method, @config[:api_key], *args)
|
258
247
|
rescue XMLRPC::FaultException => error
|
259
248
|
raise HominidError.new(error.message)
|
260
249
|
rescue Exception => error
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe Hominid do
|
4
|
+
before do
|
5
|
+
api_key = ENV['MAIL_CHIMP_API_KEY']
|
6
|
+
raise "You must set the MAIL_CHIMP_API_KEY environment variable to test" if api_key.empty?
|
7
|
+
@hominid = Hominid.new(:api_key => api_key)
|
8
|
+
@list_id = ENV['MAIL_CHIMP_TEST_LIST_ID']
|
9
|
+
raise "You must set the MAIL_CHIMP_TEST_LIST_ID environment variable to test" if @list_id.empty?
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#subscribe" do
|
13
|
+
context "when not supplying a double-opt-in argument" do
|
14
|
+
it "should not blow up" do
|
15
|
+
proc {
|
16
|
+
@hominid.subscribe(@list_id, Faker::Internet.email)
|
17
|
+
}.should_not raise_error
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#call" do
|
23
|
+
it "should raise HominidError on failure" do
|
24
|
+
proc {
|
25
|
+
Hominid.new.send(:call, 'bogusApi')
|
26
|
+
}.should raise_error(HominidError)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
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.
|
4
|
+
version: 1.2.0
|
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-
|
12
|
+
date: 2009-09-24 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -32,8 +32,8 @@ files:
|
|
32
32
|
- install.rb
|
33
33
|
- lib/hominid.rb
|
34
34
|
- rails/init.rb
|
35
|
-
-
|
36
|
-
-
|
35
|
+
- spec/hominid_spec.rb
|
36
|
+
- spec/spec_helper.rb
|
37
37
|
- uninstall.rb
|
38
38
|
has_rdoc: false
|
39
39
|
homepage: http://github.com/bgetting/hominid
|
@@ -63,5 +63,5 @@ signing_key:
|
|
63
63
|
specification_version: 3
|
64
64
|
summary: Hominid is a Rails GemPlugin for interacting with the Mailchimp API
|
65
65
|
test_files:
|
66
|
-
-
|
67
|
-
-
|
66
|
+
- spec/hominid_spec.rb
|
67
|
+
- spec/spec_helper.rb
|
data/test/hominid_test.rb
DELETED
data/test/test_helper.rb
DELETED