hominid 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.textile +76 -0
- data/Rakefile +28 -0
- data/VERSION.yml +4 -0
- data/hominid.gemspec +53 -0
- data/hominid.yml.tpl +24 -0
- data/init.rb +1 -0
- data/install.rb +4 -0
- data/lib/hominid.rb +265 -0
- data/pkg/hominid-1.2.1.gem +0 -0
- data/rails/init.rb +1 -0
- data/spec/hominid_spec.rb +29 -0
- data/spec/spec_helper.rb +3 -0
- data/uninstall.rb +1 -0
- metadata +69 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [Brian Getting]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
h1. Hominid
|
2
|
+
|
3
|
+
Hominid is a Ruby gem for interacting with the "Mailchimp API":http://www.mailchimp.com/api/1.2/.
|
4
|
+
|
5
|
+
h2. Installation
|
6
|
+
|
7
|
+
Install the gem:
|
8
|
+
|
9
|
+
<pre><code>sudo gem install hominid</code></pre>
|
10
|
+
|
11
|
+
In your @environment.rb@ file:
|
12
|
+
|
13
|
+
<pre><code>config.gem "hominid"</code></pre>
|
14
|
+
|
15
|
+
You can also install Hominid as a Rails plugin:
|
16
|
+
|
17
|
+
<pre><code>script/plugin install git://github.com/bgetting/hominid.git</code></pre>
|
18
|
+
|
19
|
+
h2. Setup
|
20
|
+
|
21
|
+
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
|
+
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
|
+
h2. Example
|
26
|
+
|
27
|
+
To interact with the Mailchimp API, simply create a new Hominid object:
|
28
|
+
|
29
|
+
<pre><code>@hominid = Hominid.new</code></pre>
|
30
|
+
|
31
|
+
_or_
|
32
|
+
|
33
|
+
<pre><code>@hominid = Hominid.new({:username => 'USERNAME', :password => 'PASSWORD', :api_key => 'API_KEY', :send_goodbye => false, :send_notify => false, :double_opt => false})</code></pre>
|
34
|
+
|
35
|
+
You will need to have the @list ID@ of the mailing list you want to work with. You can find the @list ID@ of a list by:
|
36
|
+
|
37
|
+
<pre><code>
|
38
|
+
def find_list_id(list_name)
|
39
|
+
mailing_lists = @hominid.lists
|
40
|
+
unless mailing_lists.nil?
|
41
|
+
@list_id = mailing_lists.find {|list| list["name"] == list_name}["id"]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
</code></pre>
|
45
|
+
|
46
|
+
To subscribe:
|
47
|
+
|
48
|
+
<pre><code>@hominid.subscribe(@list_id, "email@example.com", :user_info => {:FNAME => 'Bob', :LNAME => 'Smith'}, :email_type => 'html')</code></pre>
|
49
|
+
|
50
|
+
To unsubscribe:
|
51
|
+
|
52
|
+
<pre><code>@hominid.unsubscribe(@list_id, "email@example.com")</code></pre>
|
53
|
+
|
54
|
+
To update a member:
|
55
|
+
|
56
|
+
<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
|
+
_or_
|
59
|
+
|
60
|
+
<pre><code>@hominid.update_member(@list_id, "email@example.com", {:FNAME => 'Robert', :EMAIL => 'another@example.com'})</code></pre>
|
61
|
+
|
62
|
+
Campaign methods are also supported. You can get all the campaigns for a particular list by:
|
63
|
+
|
64
|
+
<pre><code>@hominid.campaigns(@list_id)</code></pre>
|
65
|
+
|
66
|
+
Leave the @@list_id@ out and it will return all the campaigns for your Mailchimp account.
|
67
|
+
|
68
|
+
h2. Other Stuff
|
69
|
+
|
70
|
+
For the most part, this whole thing was an attempt to optimize the acts_as_mailchimp plugin, and incorporates all the great work from "C.G. Brown":http://www.projectlocker.com/ and "Kelly Mahan":http://digimedia.com/, as well as "Matthew Carlson":http://mandarinsoda.com/, whose plugin inspired nearly all of this work. Recently, "ron":http://github.com/ron and "netguru":http://github.com/netguru have also provided useful changes as well.
|
71
|
+
|
72
|
+
I encourage anyone using this gem to please fork it, improve it, and send me a pull request. I typically only use this gem in a minimal capacity, primarily for just managing whether or not a user is signed up for a mailing list. I do not intend to continue maintaining the "Acts As Mailchimp":http://github.com/bgetting/acts_as_mailchimp in the future, since I personally prefer to just use the Hominid gem.
|
73
|
+
|
74
|
+
So please, help us to improve this gem!
|
75
|
+
|
76
|
+
Copyright (c) 2009 Brian Getting, released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/rdoctask'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |s|
|
7
|
+
s.name = "hominid"
|
8
|
+
s.summary = "Hominid is a Ruby gem for interacting with the Mailchimp API."
|
9
|
+
s.email = "brian@terra-firma-design.com"
|
10
|
+
s.homepage = "http://terra-firma-design.com"
|
11
|
+
s.description = "Use the hominid gem to easily integrate with the Mailchimp email marketing service API."
|
12
|
+
s.authors = ["Brian Getting"]
|
13
|
+
end
|
14
|
+
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Generate documentation for the hominid plugin.'
|
22
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
23
|
+
rdoc.rdoc_dir = 'rdoc'
|
24
|
+
rdoc.title = 'Hominid'
|
25
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
26
|
+
rdoc.rdoc_files.include('README')
|
27
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
28
|
+
end
|
data/VERSION.yml
ADDED
data/hominid.gemspec
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{hominid}
|
8
|
+
s.version = "1.2.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Brian Getting"]
|
12
|
+
s.date = %q{2009-10-13}
|
13
|
+
s.description = %q{Use the hominid gem to easily integrate with the Mailchimp email marketing service API.}
|
14
|
+
s.email = %q{brian@terra-firma-design.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.textile"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README.textile",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION.yml",
|
23
|
+
"hominid.gemspec",
|
24
|
+
"hominid.yml.tpl",
|
25
|
+
"init.rb",
|
26
|
+
"install.rb",
|
27
|
+
"lib/hominid.rb",
|
28
|
+
"pkg/hominid-1.2.1.gem",
|
29
|
+
"rails/init.rb",
|
30
|
+
"spec/hominid_spec.rb",
|
31
|
+
"spec/spec_helper.rb",
|
32
|
+
"uninstall.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://terra-firma-design.com}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.5}
|
38
|
+
s.summary = %q{Hominid is a Ruby gem for interacting with the Mailchimp API.}
|
39
|
+
s.test_files = [
|
40
|
+
"spec/hominid_spec.rb",
|
41
|
+
"spec/spec_helper.rb"
|
42
|
+
]
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
49
|
+
else
|
50
|
+
end
|
51
|
+
else
|
52
|
+
end
|
53
|
+
end
|
data/hominid.yml.tpl
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Get your API key at http://admin.mailchimp.com/account/api/
|
2
|
+
development:
|
3
|
+
username:
|
4
|
+
password:
|
5
|
+
api_key:
|
6
|
+
send_goodbye: false
|
7
|
+
send_notify: false
|
8
|
+
double_opt: false
|
9
|
+
|
10
|
+
test:
|
11
|
+
username:
|
12
|
+
password:
|
13
|
+
api_key:
|
14
|
+
send_goodbye: false
|
15
|
+
send_notify: false
|
16
|
+
double_opt: false
|
17
|
+
|
18
|
+
production:
|
19
|
+
username:
|
20
|
+
password:
|
21
|
+
api_key:
|
22
|
+
send_goodbye: false
|
23
|
+
send_notify: false
|
24
|
+
double_opt: false
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/rails/init"
|
data/install.rb
ADDED
data/lib/hominid.rb
ADDED
@@ -0,0 +1,265 @@
|
|
1
|
+
require 'xmlrpc/client'
|
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
|
+
|
15
|
+
class Hominid
|
16
|
+
|
17
|
+
# MailChimp API Documentation: http://www.mailchimp.com/api/1.2/
|
18
|
+
MAILCHIMP_API = "http://api.mailchimp.com/1.2/"
|
19
|
+
|
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)
|
28
|
+
end
|
29
|
+
|
30
|
+
## Security related methods
|
31
|
+
|
32
|
+
def add_api_key
|
33
|
+
@chimpApi.call("apikeyAdd", *@config.values_at(:username, :password, :api_key))
|
34
|
+
end
|
35
|
+
|
36
|
+
def expire_api_key
|
37
|
+
@chimpApi.call("apikeyExpire", *@config.values_at(:username, :password, :api_key))
|
38
|
+
end
|
39
|
+
|
40
|
+
def api_keys(include_expired = false)
|
41
|
+
username, password = *@config.values_at(:username, :password)
|
42
|
+
@chimpApi.call("apikeys", username, password, include_expired)
|
43
|
+
end
|
44
|
+
|
45
|
+
## Campaign related methods
|
46
|
+
|
47
|
+
def campaign_stats(campaign_id)
|
48
|
+
# Get the stats of a campaign
|
49
|
+
call("campaignStats", campaign_id)
|
50
|
+
end
|
51
|
+
|
52
|
+
def campaign_content(campaign_id, for_archive = true)
|
53
|
+
# Get the content of a campaign
|
54
|
+
#
|
55
|
+
# for_archive controls whether we return the Archive version (true) or the Raw version (false), defaults to true
|
56
|
+
call("campaignContent", campaign_id, for_archive)
|
57
|
+
end
|
58
|
+
|
59
|
+
def campaigns(filters = {}, start = 0, limit = 50)
|
60
|
+
# Get the campaigns for this account
|
61
|
+
# API Version 1.2 requires that filters be sent as a hash
|
62
|
+
# Available options for the filters hash are:
|
63
|
+
#
|
64
|
+
# :campaign_id = (string) The ID of the campaign you wish to return.
|
65
|
+
# :list_id = (string) Show only campaigns with this list_id.
|
66
|
+
# :folder_id = (integer) Show only campaigns from this folder.
|
67
|
+
# :from_name = (string) Show only campaigns with this from_name.
|
68
|
+
# :from_email = (string) Show only campaigns with this from_email.
|
69
|
+
# :title = (string) Show only campaigns with this title.
|
70
|
+
# :subject = (string) Show only campaigns with this subject.
|
71
|
+
# :sedtime_start = (string) Show campaigns sent after YYYY-MM-DD HH:mm:ss.
|
72
|
+
# :sendtime_end = (string) Show campaigns sent before YYYY-MM-DD HH:mm:ss.
|
73
|
+
# :subject = (boolean) Filter by exact values, or search within content for filter values.
|
74
|
+
call("campaigns", filters, start, limit)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Attach Ecommerce Order Information to a Campaign.
|
78
|
+
# The order hash should be structured as follows:
|
79
|
+
#
|
80
|
+
# :id = (string) the order id
|
81
|
+
# :campaign_id = (string) the campaign id to track the order (mc_cid query string).
|
82
|
+
# :email_id = (string) email id of the subscriber (mc_eid query string)
|
83
|
+
# :total = (double) Show only campaigns with this from_name.
|
84
|
+
# :shipping = (string) *optional - the total paid for shipping fees.
|
85
|
+
# :tax = (string) *optional - the total tax paid.
|
86
|
+
# :store_id = (string) a unique id for the store sending the order in
|
87
|
+
# :store_name = (string) *optional - A readable name for the store, typicaly the hostname.
|
88
|
+
# :plugin_id = (string) the MailChimp-assigned Plugin Id. Using 1214 for the moment.
|
89
|
+
# :items = (array) the individual line items for an order, using the following keys:
|
90
|
+
#
|
91
|
+
# :line_num = (integer) *optional - line number of the item on the order
|
92
|
+
# :product_id = (integer) internal product id
|
93
|
+
# :product_name = (string) the name for the product_id associated with the item
|
94
|
+
# :category_id = (integer) internal id for the (main) category associated with product
|
95
|
+
# :category_name = (string) the category name for the category id
|
96
|
+
# :qty = (double) the quantity of items ordered
|
97
|
+
# :cost = (double) the cost of a single item (i.e., not the extended cost of the line)
|
98
|
+
def campaign_ecomm_add_order(order)
|
99
|
+
call("campaignEcommAddOrder", order)
|
100
|
+
end
|
101
|
+
|
102
|
+
def create_campaign(type = 'regular', options = {}, content = {}, segment_options = {}, type_opts = {})
|
103
|
+
# Create a new campaign
|
104
|
+
call("campaignCreate", type, options, content, segment_options, type_opts)
|
105
|
+
end
|
106
|
+
|
107
|
+
def delete_campaign(campaign_id)
|
108
|
+
# Delete a campaign
|
109
|
+
call("campaignDelete", campaign_id)
|
110
|
+
end
|
111
|
+
|
112
|
+
def replicate_campaign(campaign_id)
|
113
|
+
# Replicate a campaign (returns ID of new campaign)
|
114
|
+
call("campaignReplicate", campaign_id)
|
115
|
+
end
|
116
|
+
|
117
|
+
def schedule_campaign(campaign_id, time = "#{1.day.from_now}")
|
118
|
+
# Schedule a campaign
|
119
|
+
## TODO: Add support for A/B Split scheduling
|
120
|
+
call("campaignSchedule", campaign_id, time)
|
121
|
+
end
|
122
|
+
|
123
|
+
def send_now(campaign_id)
|
124
|
+
# Send a campaign
|
125
|
+
call("campaignSendNow", campaign_id)
|
126
|
+
end
|
127
|
+
|
128
|
+
def send_test(campaign_id, emails = {})
|
129
|
+
# Send a test of a campaign
|
130
|
+
call("campaignSendTest", campaign_id, emails)
|
131
|
+
end
|
132
|
+
|
133
|
+
def templates
|
134
|
+
# Get the templates
|
135
|
+
call("campaignTemplates")
|
136
|
+
end
|
137
|
+
|
138
|
+
def update_campaign(campaign_id, name, value)
|
139
|
+
# Update a campaign
|
140
|
+
call("campaignUpdate", campaign_id, name, value)
|
141
|
+
end
|
142
|
+
|
143
|
+
def unschedule_campaign(campaign_id)
|
144
|
+
# Unschedule a campaign
|
145
|
+
call("campaignUnschedule", campaign_id)
|
146
|
+
end
|
147
|
+
|
148
|
+
## Helper methods
|
149
|
+
|
150
|
+
def html_to_text(content)
|
151
|
+
# Convert HTML content to text
|
152
|
+
call("generateText", 'html', content)
|
153
|
+
end
|
154
|
+
|
155
|
+
def convert_css_to_inline(html, strip_css = false)
|
156
|
+
# Convert CSS styles to inline styles and (optionally) remove original styles
|
157
|
+
call("inlineCss", html, strip_css)
|
158
|
+
end
|
159
|
+
|
160
|
+
## List related methods
|
161
|
+
|
162
|
+
def lists
|
163
|
+
# Get all of the lists for this mailchimp account
|
164
|
+
call("lists")
|
165
|
+
end
|
166
|
+
|
167
|
+
def create_group(list_id, group)
|
168
|
+
# Add an interest group to a list
|
169
|
+
call("listInterestGroupAdd", list_id, group)
|
170
|
+
end
|
171
|
+
|
172
|
+
def create_tag(list_id, tag, name, required = false)
|
173
|
+
# Add a merge tag to a list
|
174
|
+
call("listMergeVarAdd", list_id, tag, name, required)
|
175
|
+
end
|
176
|
+
|
177
|
+
def delete_group(list_id, group)
|
178
|
+
# Delete an interest group for a list
|
179
|
+
call("listInterestGroupDel", list_id, group)
|
180
|
+
end
|
181
|
+
|
182
|
+
def delete_tag(list_id, tag)
|
183
|
+
# Delete a merge tag and all its members
|
184
|
+
call("listMergeVarDel", list_id, tag)
|
185
|
+
end
|
186
|
+
|
187
|
+
def groups(list_id)
|
188
|
+
# Get the interest groups for a list
|
189
|
+
call("listInterestGroups", list_id)
|
190
|
+
end
|
191
|
+
|
192
|
+
def member(list_id, email)
|
193
|
+
# Get a member of a list
|
194
|
+
call("listMemberInfo", list_id, email)
|
195
|
+
end
|
196
|
+
|
197
|
+
def members(list_id, status = "subscribed", since = "2000-01-01 00:00:00", start = 0, limit = 100)
|
198
|
+
# Get members of a list based on status
|
199
|
+
# Select members based on one of the following statuses:
|
200
|
+
# 'subscribed'
|
201
|
+
# 'unsubscribed'
|
202
|
+
# 'cleaned'
|
203
|
+
# 'updated'
|
204
|
+
#
|
205
|
+
# Select members that have updated their status or profile by providing
|
206
|
+
# a "since" date in the format of YYYY-MM-DD HH:MM:SS
|
207
|
+
#
|
208
|
+
call("listMembers", list_id, status, since, start, limit)
|
209
|
+
end
|
210
|
+
|
211
|
+
def merge_tags(list_id)
|
212
|
+
# Get the merge tags for a list
|
213
|
+
call("listMergeVars", list_id)
|
214
|
+
end
|
215
|
+
|
216
|
+
def subscribe(list_id, email, options = {})
|
217
|
+
options = apply_defaults_to({:email_type => "html"}.merge(options))
|
218
|
+
# Subscribe a member
|
219
|
+
call("listSubscribe", list_id, email, *options.values_at(:user_info, :email_type, :double_opt_in, :update_existing, :replace_interests, :send_welcome))
|
220
|
+
end
|
221
|
+
|
222
|
+
def subscribe_many(list_id, subscribers, options = {})
|
223
|
+
options = apply_defaults_to({:update_existing => true}.merge(options))
|
224
|
+
# Subscribe a batch of members
|
225
|
+
# subscribers = {:EMAIL => 'example@email.com', :EMAIL_TYPE => 'html'}
|
226
|
+
call("listBatchSubscribe", list_id, subscribers, *options.values_at(:double_opt_in, :update_existing, :replace_interests))
|
227
|
+
end
|
228
|
+
|
229
|
+
# Unsubscribe a user from a list
|
230
|
+
#
|
231
|
+
# Options
|
232
|
+
# :delete_member Delete user form list instead of marking them as unsubscribed
|
233
|
+
# :send_goodbye Send goodbye e-mail to user
|
234
|
+
# :send_notify Send unsubscribe email to email in list settings
|
235
|
+
def unsubscribe(list_id, current_email, options = {})
|
236
|
+
options = apply_defaults_to({:delete_member => true}.merge(options))
|
237
|
+
# Unsubscribe a list member
|
238
|
+
call("listUnsubscribe", list_id, current_email, *options.values_at(:delete_member, :send_goodbye, :send_notify))
|
239
|
+
end
|
240
|
+
|
241
|
+
def unsubscribe_many(list_id, emails, options = {})
|
242
|
+
options = apply_defaults_to({:delete_member => true}.merge(options))
|
243
|
+
# Unsubscribe an array of email addresses
|
244
|
+
# emails = ['first@email.com', 'second@email.com']
|
245
|
+
call("listBatchUnsubscribe", list_id, emails, *options.values_at(:delete_member, :send_goodbye, :send_notify))
|
246
|
+
end
|
247
|
+
|
248
|
+
def update_member(list_id, current_email, user_info = {}, email_type = "")
|
249
|
+
# Update a member of this list
|
250
|
+
call("listUpdateMember", list_id, current_email, user_info, email_type, true)
|
251
|
+
end
|
252
|
+
|
253
|
+
protected
|
254
|
+
def apply_defaults_to(options)
|
255
|
+
@config.merge(options)
|
256
|
+
end
|
257
|
+
|
258
|
+
def call(method, *args)
|
259
|
+
@chimpApi.call(method, @config[:api_key], *args)
|
260
|
+
rescue XMLRPC::FaultException => error
|
261
|
+
raise HominidError.new(error.message)
|
262
|
+
rescue Exception => error
|
263
|
+
raise HominidCommunicationError.new(error.message)
|
264
|
+
end
|
265
|
+
end
|
Binary file
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'hominid'
|
@@ -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
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hominid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Getting
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-13 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Use the hominid gem to easily integrate with the Mailchimp email marketing service API.
|
17
|
+
email: brian@terra-firma-design.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.textile
|
24
|
+
files:
|
25
|
+
- MIT-LICENSE
|
26
|
+
- README.textile
|
27
|
+
- Rakefile
|
28
|
+
- VERSION.yml
|
29
|
+
- hominid.gemspec
|
30
|
+
- hominid.yml.tpl
|
31
|
+
- init.rb
|
32
|
+
- install.rb
|
33
|
+
- lib/hominid.rb
|
34
|
+
- pkg/hominid-1.2.1.gem
|
35
|
+
- rails/init.rb
|
36
|
+
- spec/hominid_spec.rb
|
37
|
+
- spec/spec_helper.rb
|
38
|
+
- uninstall.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://terra-firma-design.com
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --charset=UTF-8
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.3.5
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Hominid is a Ruby gem for interacting with the Mailchimp API.
|
67
|
+
test_files:
|
68
|
+
- spec/hominid_spec.rb
|
69
|
+
- spec/spec_helper.rb
|