Empact-hominid 1.1.12
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/MIT-LICENSE +20 -0
- data/README.textile +77 -0
- data/Rakefile +37 -0
- data/VERSION.yml +4 -0
- data/hominid.gemspec +52 -0
- data/hominid.yml.tpl +24 -0
- data/init.rb +1 -0
- data/install.rb +4 -0
- data/lib/hominid.rb +263 -0
- data/rails/init.rb +1 -0
- data/spec/hominid_spec.rb +21 -0
- data/spec/spec_helper.rb +3 -0
- data/uninstall.rb +1 -0
- metadata +67 -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,77 @@
|
|
|
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>gem sources -a http://gems.github.com
|
|
10
|
+
sudo gem install bgetting-hominid</code></pre>
|
|
11
|
+
|
|
12
|
+
In your @environment.rb@ file:
|
|
13
|
+
|
|
14
|
+
<pre><code>config.gem "bgetting-hominid", :lib => 'hominid', :source => "http://gems.github.com"</code></pre>
|
|
15
|
+
|
|
16
|
+
You can also install Hominid as a Rails plugin:
|
|
17
|
+
|
|
18
|
+
<pre><code>script/plugin install git://github.com/bgetting/hominid.git</code></pre>
|
|
19
|
+
|
|
20
|
+
h2. Setup
|
|
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).
|
|
23
|
+
|
|
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.
|
|
25
|
+
|
|
26
|
+
h2. Example
|
|
27
|
+
|
|
28
|
+
To interact with the Mailchimp API, simply create a new Hominid object:
|
|
29
|
+
|
|
30
|
+
<pre><code>@hominid = Hominid.new</code></pre>
|
|
31
|
+
|
|
32
|
+
_or_
|
|
33
|
+
|
|
34
|
+
<pre><code>@hominid = Hominid.new({:username => 'USERNAME', :password => 'PASSWORD', :api_key => 'API_KEY', :send_goodbye => false, :send_notify => false, :double_opt => false})</code></pre>
|
|
35
|
+
|
|
36
|
+
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:
|
|
37
|
+
|
|
38
|
+
<pre><code>
|
|
39
|
+
def find_list_id(list_name)
|
|
40
|
+
mailing_lists = @hominid.lists
|
|
41
|
+
unless mailing_lists.nil?
|
|
42
|
+
@list_id = mailing_lists.find {|list| list["name"] == list_name}["id"]
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
</code></pre>
|
|
46
|
+
|
|
47
|
+
To subscribe:
|
|
48
|
+
|
|
49
|
+
<pre><code>@hominid.subscribe(@list_id, "email@example.com", {:FNAME => 'Bob', :LNAME => 'Smith'}, 'html')</code></pre>
|
|
50
|
+
|
|
51
|
+
To unsubscribe:
|
|
52
|
+
|
|
53
|
+
<pre><code>@hominid.unsubscribe(@list_id, "email@example.com")</code></pre>
|
|
54
|
+
|
|
55
|
+
To update a member:
|
|
56
|
+
|
|
57
|
+
<pre><code>@hominid.subscribe(@list_id, "email@example.com", {:FNAME => 'Robert', :EMAIL => 'another@example.com'}, 'html', true)</code></pre>
|
|
58
|
+
|
|
59
|
+
_or_
|
|
60
|
+
|
|
61
|
+
<pre><code>@hominid.update_member(@list_id, "email@example.com", {:FNAME => 'Robert', :EMAIL => 'another@example.com'})</code></pre>
|
|
62
|
+
|
|
63
|
+
Campaign methods are also supported. You can get all the campaigns for a particular list by:
|
|
64
|
+
|
|
65
|
+
<pre><code>@hominid.campaigns(@list_id)</code></pre>
|
|
66
|
+
|
|
67
|
+
Leave the @@list_id@ out and it will return all the campaigns for your Mailchimp account.
|
|
68
|
+
|
|
69
|
+
h2. Other Stuff
|
|
70
|
+
|
|
71
|
+
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.
|
|
72
|
+
|
|
73
|
+
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.
|
|
74
|
+
|
|
75
|
+
So please, help us to improve this gem!
|
|
76
|
+
|
|
77
|
+
Copyright (c) 2009 Brian Getting, released under the MIT license.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rake/testtask'
|
|
3
|
+
require 'rake/rdoctask'
|
|
4
|
+
|
|
5
|
+
begin
|
|
6
|
+
require 'jeweler'
|
|
7
|
+
Jeweler::Tasks.new do |s|
|
|
8
|
+
s.name = "hominid"
|
|
9
|
+
s.summary = "Hominid is a Rails GemPlugin for interacting with the Mailchimp API"
|
|
10
|
+
s.email = "brian@terra-firma-design.com"
|
|
11
|
+
s.homepage = "http://github.com/bgetting/hominid"
|
|
12
|
+
s.description = "Hominid is a Rails GemPlugin for interacting with the Mailchimp API"
|
|
13
|
+
s.authors = ["Brian Getting"]
|
|
14
|
+
end
|
|
15
|
+
rescue LoadError
|
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
|
17
|
+
end
|
|
18
|
+
|
|
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
|
+
desc 'Generate documentation for the hominid plugin.'
|
|
31
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
32
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
33
|
+
rdoc.title = 'Hominid'
|
|
34
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
|
35
|
+
rdoc.rdoc_files.include('README')
|
|
36
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
37
|
+
end
|
data/VERSION.yml
ADDED
data/hominid.gemspec
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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.1.12"
|
|
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-09-18}
|
|
13
|
+
s.description = %q{Hominid is a Rails GemPlugin for interacting with the Mailchimp 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
|
+
"rails/init.rb",
|
|
29
|
+
"spec/hominid_spec.rb",
|
|
30
|
+
"spec/spec_helper.rb",
|
|
31
|
+
"uninstall.rb"
|
|
32
|
+
]
|
|
33
|
+
s.homepage = %q{http://github.com/bgetting/hominid}
|
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
35
|
+
s.require_paths = ["lib"]
|
|
36
|
+
s.rubygems_version = %q{1.3.5}
|
|
37
|
+
s.summary = %q{Hominid is a Rails GemPlugin for interacting with the Mailchimp API}
|
|
38
|
+
s.test_files = [
|
|
39
|
+
"spec/hominid_spec.rb",
|
|
40
|
+
"spec/spec_helper.rb"
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
if s.respond_to? :specification_version then
|
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
45
|
+
s.specification_version = 3
|
|
46
|
+
|
|
47
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
48
|
+
else
|
|
49
|
+
end
|
|
50
|
+
else
|
|
51
|
+
end
|
|
52
|
+
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,263 @@
|
|
|
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 = nil)
|
|
21
|
+
load_monkey_brains(config)
|
|
22
|
+
@chimpApi ||= XMLRPC::Client.new2(MAILCHIMP_API)
|
|
23
|
+
end
|
|
24
|
+
|
|
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] || false
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
## Security related methods
|
|
36
|
+
|
|
37
|
+
def add_api_key
|
|
38
|
+
begin
|
|
39
|
+
@chimpApi ||= XMLRPC::Client.new2(MAILCHIMP_API)
|
|
40
|
+
@chimpApi.call("apikeyAdd", @chimpUsername, @chimpPassword, @api_key)
|
|
41
|
+
rescue
|
|
42
|
+
false
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def expire_api_key
|
|
47
|
+
begin
|
|
48
|
+
@chimpApi ||= XMLRPC::Client.new2(MAILCHIMP_API)
|
|
49
|
+
@chimpApi.call("apikeyExpire", @chimpUsername, @chimpPassword, @api_key)
|
|
50
|
+
rescue
|
|
51
|
+
false
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def api_keys(include_expired = false)
|
|
56
|
+
begin
|
|
57
|
+
@chimpApi ||= XMLRPC::Client.new2(MAILCHIMP_API)
|
|
58
|
+
@api_keys = @chimpApi.call("apikeys", @chimpUsername, @chimpPassword, include_expired)
|
|
59
|
+
rescue
|
|
60
|
+
return nil
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
## Campaign related methods
|
|
65
|
+
|
|
66
|
+
def campaign_content(campaign_id)
|
|
67
|
+
# Get the content of a campaign
|
|
68
|
+
@content = call("campaignContent", campaign_id)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def campaigns(filters = {}, start = 0, limit = 50)
|
|
72
|
+
# Get the campaigns for this account
|
|
73
|
+
# API Version 1.2 requires that filters be sent as a hash
|
|
74
|
+
# Available options for the filters hash are:
|
|
75
|
+
#
|
|
76
|
+
# :campaign_id = (string) The ID of the campaign you wish to return.
|
|
77
|
+
# :list_id = (string) Show only campaigns with this list_id.
|
|
78
|
+
# :folder_id = (integer) Show only campaigns from this folder.
|
|
79
|
+
# :from_name = (string) Show only campaigns with this from_name.
|
|
80
|
+
# :from_email = (string) Show only campaigns with this from_email.
|
|
81
|
+
# :title = (string) Show only campaigns with this title.
|
|
82
|
+
# :subject = (string) Show only campaigns with this subject.
|
|
83
|
+
# :sedtime_start = (string) Show campaigns sent after YYYY-MM-DD HH:mm:ss.
|
|
84
|
+
# :sendtime_end = (string) Show campaigns sent before YYYY-MM-DD HH:mm:ss.
|
|
85
|
+
# :subject = (boolean) Filter by exact values, or search within content for filter values.
|
|
86
|
+
@campaigns = call("campaigns", filters, start, limit)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Attach Ecommerce Order Information to a Campaign.
|
|
90
|
+
# The order hash should be structured as follows:
|
|
91
|
+
#
|
|
92
|
+
# :id = (string) the order id
|
|
93
|
+
# :campaign_id = (string) the campaign id to track the order (mc_cid query string).
|
|
94
|
+
# :email_id = (string) email id of the subscriber (mc_eid query string)
|
|
95
|
+
# :total = (double) Show only campaigns with this from_name.
|
|
96
|
+
# :shipping = (string) *optional - the total paid for shipping fees.
|
|
97
|
+
# :tax = (string) *optional - the total tax paid.
|
|
98
|
+
# :store_id = (string) a unique id for the store sending the order in
|
|
99
|
+
# :store_name = (string) *optional - A readable name for the store, typicaly the hostname.
|
|
100
|
+
# :plugin_id = (string) the MailChimp-assigned Plugin Id. Using 1214 for the moment.
|
|
101
|
+
# :items = (array) the individual line items for an order, using the following keys:
|
|
102
|
+
#
|
|
103
|
+
# :line_num = (integer) *optional - line number of the item on the order
|
|
104
|
+
# :product_id = (integer) internal product id
|
|
105
|
+
# :product_name = (string) the name for the product_id associated with the item
|
|
106
|
+
# :category_id = (integer) internal id for the (main) category associated with product
|
|
107
|
+
# :category_name = (string) the category name for the category id
|
|
108
|
+
# :qty = (double) the quantity of items ordered
|
|
109
|
+
# :cost = (double) the cost of a single item (i.e., not the extended cost of the line)
|
|
110
|
+
def campaign_ecomm_add_order(order)
|
|
111
|
+
@campaign = call("campaignEcommAddOrder", order)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def create_campaign(type = 'regular', options = {}, content = {}, segment_options = {}, type_opts = {})
|
|
115
|
+
# Create a new campaign
|
|
116
|
+
@campaign = call("campaignCreate", type, options, content, segment_options, type_opts)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def delete_campaign(campaign_id)
|
|
120
|
+
# Delete a campaign
|
|
121
|
+
@campaign = call("campaignDelete", campaign_id)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def replicate_campaign(campaign_id)
|
|
125
|
+
# Replicate a campaign (returns ID of new campaign)
|
|
126
|
+
@campaign = call("campaignReplicate", campaign_id)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def schedule_campaign(campaign_id, time = "#{1.day.from_now}")
|
|
130
|
+
# Schedule a campaign
|
|
131
|
+
## TODO: Add support for A/B Split scheduling
|
|
132
|
+
call("campaignSchedule", campaign_id, time)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def send_now(campaign_id)
|
|
136
|
+
# Send a campaign
|
|
137
|
+
call("campaignSendNow", campaign_id)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def send_test(campaign_id, emails = {})
|
|
141
|
+
# Send a test of a campaign
|
|
142
|
+
call("campaignSendTest", campaign_id, emails)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def templates
|
|
146
|
+
# Get the templates
|
|
147
|
+
@templates = call("campaignTemplates", @api_key)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def update_campaign(campaign_id, name, value)
|
|
151
|
+
# Update a campaign
|
|
152
|
+
call("campaignUpdate", campaign_id, name, value)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def unschedule_campaign(campaign_id)
|
|
156
|
+
# Unschedule a campaign
|
|
157
|
+
call("campaignUnschedule", campaign_id)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
## Helper methods
|
|
161
|
+
|
|
162
|
+
def html_to_text(content)
|
|
163
|
+
# Convert HTML content to text
|
|
164
|
+
@html_to_text = call("generateText", 'html', content)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def convert_css_to_inline(html, strip_css = false)
|
|
168
|
+
# Convert CSS styles to inline styles and (optionally) remove original styles
|
|
169
|
+
@html_to_text = call("inlineCss", html, strip_css)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
## List related methods
|
|
173
|
+
|
|
174
|
+
def lists
|
|
175
|
+
# Get all of the lists for this mailchimp account
|
|
176
|
+
@lists = call("lists", @api_key)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def create_group(list_id, group)
|
|
180
|
+
# Add an interest group to a list
|
|
181
|
+
call("listInterestGroupAdd", list_id, group)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def create_tag(list_id, tag, name, required = false)
|
|
185
|
+
# Add a merge tag to a list
|
|
186
|
+
call("listMergeVarAdd", list_id, tag, name, required)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def delete_group(list_id, group)
|
|
190
|
+
# Delete an interest group for a list
|
|
191
|
+
call("listInterestGroupDel", list_id, group)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def delete_tag(list_id, tag)
|
|
195
|
+
# Delete a merge tag and all its members
|
|
196
|
+
call("listMergeVarDel", list_id, tag)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def groups(list_id)
|
|
200
|
+
# Get the interest groups for a list
|
|
201
|
+
@groups = call("listInterestGroups", list_id)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def member(list_id, email)
|
|
205
|
+
# Get a member of a list
|
|
206
|
+
@member = call("listMemberInfo", list_id, email)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def members(list_id, status = "subscribed", since = "2000-01-01 00:00:00", start = 0, limit = 100)
|
|
210
|
+
# Get members of a list based on status
|
|
211
|
+
# Select members based on one of the following statuses:
|
|
212
|
+
# 'subscribed'
|
|
213
|
+
# 'unsubscribed'
|
|
214
|
+
# 'cleaned'
|
|
215
|
+
# 'updated'
|
|
216
|
+
#
|
|
217
|
+
# Select members that have updated their status or profile by providing
|
|
218
|
+
# a "since" date in the format of YYYY-MM-DD HH:MM:SS
|
|
219
|
+
#
|
|
220
|
+
@members = call("listMembers", list_id, status, since, start, limit)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def merge_tags(list_id)
|
|
224
|
+
# Get the merge tags for a list
|
|
225
|
+
@merge_tags = call("listMergeVars", list_id)
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def subscribe(list_id, email, user_info = {}, email_type = "html", update_existing = true, replace_interests = true, double_opt_in = false)
|
|
229
|
+
# Subscribe a member
|
|
230
|
+
call("listSubscribe", list_id, email, user_info, email_type, double_opt_in || @double_opt, update_existing, replace_interests)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def subscribe_many(list_id, subscribers)
|
|
234
|
+
# Subscribe a batch of members
|
|
235
|
+
# subscribers = {:EMAIL => 'example@email.com', :EMAIL_TYPE => 'html'}
|
|
236
|
+
call("listBatchSubscribe", list_id, subscribers, @double_opt, true)
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def unsubscribe(list_id, current_email)
|
|
240
|
+
# Unsubscribe a list member
|
|
241
|
+
call("listUnsubscribe", list_id, current_email, true, @send_goodbye, @send_notify)
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def unsubscribe_many(list_id, emails)
|
|
245
|
+
# Unsubscribe an array of email addresses
|
|
246
|
+
# emails = ['first@email.com', 'second@email.com']
|
|
247
|
+
call("listBatchUnsubscribe", list_id, emails, true, @send_goodbye, @send_notify)
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def update_member(list_id, current_email, user_info = {}, email_type = "")
|
|
251
|
+
# Update a member of this list
|
|
252
|
+
call("listUpdateMember", list_id, current_email, user_info, email_type, true)
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
protected
|
|
256
|
+
def call(method, *args)
|
|
257
|
+
@chimpApi.call(method, @api_key, *args)
|
|
258
|
+
rescue XMLRPC::FaultException => error
|
|
259
|
+
raise HominidError.new(error.message)
|
|
260
|
+
rescue Exception => error
|
|
261
|
+
raise HominidCommunicationError.new(error.message)
|
|
262
|
+
end
|
|
263
|
+
end
|
data/rails/init.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'hominid'
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/uninstall.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: Empact-hominid
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.1.12
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Brian Getting
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-09-18 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Hominid is a Rails GemPlugin for interacting with the Mailchimp 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
|
+
- rails/init.rb
|
|
35
|
+
- spec/hominid_spec.rb
|
|
36
|
+
- spec/spec_helper.rb
|
|
37
|
+
- uninstall.rb
|
|
38
|
+
has_rdoc: false
|
|
39
|
+
homepage: http://github.com/bgetting/hominid
|
|
40
|
+
licenses:
|
|
41
|
+
post_install_message:
|
|
42
|
+
rdoc_options:
|
|
43
|
+
- --charset=UTF-8
|
|
44
|
+
require_paths:
|
|
45
|
+
- lib
|
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: "0"
|
|
51
|
+
version:
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: "0"
|
|
57
|
+
version:
|
|
58
|
+
requirements: []
|
|
59
|
+
|
|
60
|
+
rubyforge_project:
|
|
61
|
+
rubygems_version: 1.3.5
|
|
62
|
+
signing_key:
|
|
63
|
+
specification_version: 3
|
|
64
|
+
summary: Hominid is a Rails GemPlugin for interacting with the Mailchimp API
|
|
65
|
+
test_files:
|
|
66
|
+
- spec/hominid_spec.rb
|
|
67
|
+
- spec/spec_helper.rb
|