hominid-wout 3.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/.travis.yml +1 -0
- data/Gemfile +9 -0
- data/Guardfile +21 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +107 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/hominid.gemspec +69 -0
- data/lib/hominid.rb +11 -0
- data/lib/hominid/api.rb +60 -0
- data/lib/hominid/campaign.rb +35 -0
- data/lib/hominid/export.rb +63 -0
- data/lib/hominid/list.rb +32 -0
- data/lib/hominid/security.rb +20 -0
- data/lib/hominid/sts.rb +19 -0
- data/spec/hominid/hominid_spec.rb +24 -0
- data/spec/spec_helper.rb +13 -0
- metadata +150 -0
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm: 1.9.2
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^spec/.+_spec\.rb$})
|
11
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
12
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
13
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
14
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
15
|
+
watch('spec/spec_helper.rb') { "spec" }
|
16
|
+
watch('config/routes.rb') { "spec/routing" }
|
17
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
18
|
+
# Capybara request specs
|
19
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
20
|
+
end
|
21
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 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.rdoc
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
Note: The official {Mailchimp gem}[http://rubygems.org/gems/mailchimp] is a better alternative to Hominid if you are starting a new project. There is a lot less data-bludgeoning because it uses JSON rather than XML, and it also includes support for the Mandrill API as well.
|
2
|
+
|
3
|
+
= Hominid {<img src="http://travis-ci.org/terra-firma/hominid.png" />}[http://travis-ci.org/terra-firma/hominid] {<img src="https://gemnasium.com/terra-firma/hominid.png" alt="Dependency Status" />}[https://gemnasium.com/terra-firma/hominid]
|
4
|
+
|
5
|
+
Hominid is a Ruby gem that provides a wrapper for interacting with {Mailchimp's}[http://eepurl.com/ew8J] MC, STS and Export API's. Check out the {Mandrill gem}[http://github.com/terra-firma/mandrill] if you are interested in working with the {Mandrill API}[http://mandrillapp.com/api/docs/index.html].
|
6
|
+
|
7
|
+
== Requirements
|
8
|
+
|
9
|
+
You will need a {Mailchimp}[http://eepurl.com/ew8J] account. Once you have your Mailchimp account set up, you will need to {generate an API key}[http://admin.mailchimp.com/account/api/] in order to get started using Hominid (or you can use OAuth2 as well).
|
10
|
+
|
11
|
+
== Installation
|
12
|
+
|
13
|
+
(sudo) gem install hominid
|
14
|
+
|
15
|
+
== Usage
|
16
|
+
|
17
|
+
=== MCAPI
|
18
|
+
|
19
|
+
Please refer to the {Mailchimp API Documentation}[http://apidocs.mailchimp.com/api/1.3/] for information about what methods are available, the arguments that can be passed to each method, and the output that the API will return. Start by creating a Hominid object:
|
20
|
+
|
21
|
+
h = Hominid::API.new('your_api_key')
|
22
|
+
|
23
|
+
You can also override the default configuration by passing in your own when initializing:
|
24
|
+
|
25
|
+
h = Hominid::API.new('your_api_key', {:secure => true, :timeout => 60})
|
26
|
+
|
27
|
+
Finally, and we're not sure why you would want to, but you can use the older versions of the API if you would like:
|
28
|
+
|
29
|
+
h = Hominid::API.new('your_api_key', {:api_version => '1.2'})
|
30
|
+
|
31
|
+
You can then run any of the methods that you find in the {Mailchimp API Documentation}[http://apidocs.mailchimp.com/api/1.3/] against it. Simply convert the names to the more Ruby-like underscored versions (e.g. listUpdateMember becomes list_update_member).
|
32
|
+
|
33
|
+
MailChimp's API documentation states that several API methods (e.g. listUpdateMember, list_subscribe) require 'array' parameters. Hominid requires many (all?) of these parameters to be passed as **hashes**, not arrays -- the examples below should all work as-is.
|
34
|
+
|
35
|
+
You do not need to pass your api_key to each method, as that is done automatically for you:
|
36
|
+
|
37
|
+
# list_id is a short hex string used internally by MailChimp to identify your lists (e.g. 'eceeae8b22')
|
38
|
+
# it's returned as the "id" member of the structure returned by the 'lists' call.
|
39
|
+
h.get_account_details
|
40
|
+
# Get all lists associated with this API key
|
41
|
+
h.lists
|
42
|
+
# Subscribe 'joe@public.com', with merge variables 'FNAME' and 'LNAME', to the list identified by list_id
|
43
|
+
h.list_subscribe(list_id, 'joe@public.com', {'FNAME' => 'Joe', 'LNAME' => 'Public'}, 'html', false, true, true, false)
|
44
|
+
h.list_batch_subscribe(list_id, [{:EMAIL => 'joe@public.com', :EMAIL_TYPE => 'html'}, {:EMAIL => 'jane@doe.com', :EMAIL_TYPE => 'html'}])
|
45
|
+
h.campaign_create('regular', {:list_id => list_id, ...}, {:html => 'Campaign HTML content', ...})
|
46
|
+
h.template_add('template_name', 'Template HTML Code')
|
47
|
+
h.list_interest_grouping_add(list_id, 'Grouping Title', 'hidden', ['First Group', 'Second Group', 'Third Group'])
|
48
|
+
h.list_static_segment_add('Sample Static Segment')
|
49
|
+
|
50
|
+
The {Mailchimp API}[http://apidocs.mailchimp.com/api/1.3/] supports pagination for some methods, so certain methods will have the following response:
|
51
|
+
|
52
|
+
h.lists['total'] => 4
|
53
|
+
h.lists['data'] => outputs an array of your mailing lists
|
54
|
+
h.lists['data'].first => {"id" => "XXXXXXX", "web_id" => 1234567, "name" => "My Mailing List", ...}
|
55
|
+
|
56
|
+
==== Finder Methods
|
57
|
+
|
58
|
+
Hominid includes some finder methods for campaigns (see Hominid::Campaign) and lists (see Hominid::List) to help with finding each of these resources:
|
59
|
+
|
60
|
+
h.find_list_by_name('my_mailing_list')
|
61
|
+
h.find_list_id_by_name('my_mailing_list')
|
62
|
+
h.find_campaigns_by_list_name('my_mailing_list')
|
63
|
+
|
64
|
+
=== STS API
|
65
|
+
|
66
|
+
Please refer to the {Mailchimp STS API Documentation}[http://apidocs.mailchimp.com/sts/1.0/] for information about what methods are available, the arguments that can be passed to each method, and the output that the API will return. Start by creating a Hominid object:
|
67
|
+
|
68
|
+
s = Hominid::STS.new('your_api_key', {:secure => true})
|
69
|
+
|
70
|
+
You can then run any of the methods that you find in the {Mailchimp STS API Documentation}[http://apidocs.mailchimp.com/sts/1.0/] against it. Simply convert the names to the more Ruby-like underscored versions (e.g. listVerifiedEmailAddresses becomes list_verified_email_addresses).
|
71
|
+
|
72
|
+
s.list_verified_email_addresses
|
73
|
+
s.verify_email_address('joe@public.com')
|
74
|
+
s.send_email({:to_email => ['joe@public.com'], :text => 'Hello World!'}, false, true)
|
75
|
+
s.get_send_quota
|
76
|
+
|
77
|
+
Note that MailChimp will return an error if you attempt to make STS API calls on an account without Amazon SES integration.
|
78
|
+
|
79
|
+
=== Export API
|
80
|
+
|
81
|
+
Please refer to the {Mailchimp Export API Documentation}[http://apidocs.mailchimp.com/export/1.0/] for information about what methods are available, the arguments that can be passed to each method, and the output that the API will return. Start by creating a Hominid object:
|
82
|
+
|
83
|
+
e = Hominid::Export.new('your_api_key', {:secure => true})
|
84
|
+
|
85
|
+
You can then run the following methods:
|
86
|
+
|
87
|
+
e.list('list_id')
|
88
|
+
e.campaign_subscriber_activit('campaign_id')
|
89
|
+
|
90
|
+
== Submitting an Issue
|
91
|
+
|
92
|
+
We use the {GitHub issue tracker}[https://github.com/terra-firma/hominid/issues] to track bugs and features. Before submitting a bug report or feature request, check to make sure it hasn't already been submitted. You can indicate support for an existing issue by voting it up. When submitting a bug report, please include a Gist that includes a stack trace and any details that may be necessary to reproduce the bug, including your gem version, Ruby version, and operating system. Ideally, a bug report should include a pull request with failing specs.
|
93
|
+
|
94
|
+
== Contributing to Hominid
|
95
|
+
|
96
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
97
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
98
|
+
* Fork the project
|
99
|
+
* Start a feature/bugfix branch
|
100
|
+
* Commit and push until you are happy with your contribution
|
101
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
102
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
103
|
+
|
104
|
+
== Copyright
|
105
|
+
|
106
|
+
Copyright (c) 2010 Brian Getting. See LICENSE.txt for further details.
|
107
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "hominid-wout"
|
18
|
+
gem.homepage = "https://github.com/wout/hominid"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Ruby gem for interacting with the Mailchimp API's.}
|
21
|
+
gem.description = %Q{Hominid is a Ruby gem that provides a wrapper for interacting with the Mailchimp email marketing service MC, STS and Export API's.}
|
22
|
+
gem.email = "bwout@impinc.co.uk"
|
23
|
+
gem.authors = ["Brian Getting", "Wout Fierens"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
task :default => :test
|
37
|
+
|
38
|
+
require 'rdoc/task'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "hominid #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.6
|
data/hominid.gemspec
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
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 = "hominid"
|
8
|
+
s.version = "3.0.6"
|
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 = "2013-05-30"
|
13
|
+
s.description = "Hominid is a Ruby gem that provides a wrapper for interacting with the Mailchimp email marketing service MC, STS and Export API's."
|
14
|
+
s.email = "brian@tatem.ae"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".rspec",
|
21
|
+
".travis.yml",
|
22
|
+
"Gemfile",
|
23
|
+
"Guardfile",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"hominid.gemspec",
|
29
|
+
"lib/hominid.rb",
|
30
|
+
"lib/hominid/api.rb",
|
31
|
+
"lib/hominid/campaign.rb",
|
32
|
+
"lib/hominid/export.rb",
|
33
|
+
"lib/hominid/list.rb",
|
34
|
+
"lib/hominid/security.rb",
|
35
|
+
"lib/hominid/sts.rb",
|
36
|
+
"spec/hominid/hominid_spec.rb",
|
37
|
+
"spec/spec_helper.rb"
|
38
|
+
]
|
39
|
+
s.homepage = "http://github.com/tatemae-consultancy/hominid"
|
40
|
+
s.licenses = ["MIT"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = "1.8.25"
|
43
|
+
s.summary = "Ruby gem for interacting with the Mailchimp API's."
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_development_dependency(%q<bundler>, ["> 1.0.0"])
|
50
|
+
s.add_development_dependency(%q<fakeweb>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<jeweler>, ["> 1.6.4"])
|
52
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<bundler>, ["> 1.0.0"])
|
56
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["> 1.6.4"])
|
58
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
59
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<bundler>, ["> 1.0.0"])
|
63
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
64
|
+
s.add_dependency(%q<jeweler>, ["> 1.6.4"])
|
65
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
66
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
data/lib/hominid.rb
ADDED
data/lib/hominid/api.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
module Hominid
|
2
|
+
class API
|
3
|
+
# Blank Slate
|
4
|
+
instance_methods.each do |m|
|
5
|
+
undef_method m unless m.to_s =~ /^__|object_id|method_missing|respond_to?|to_s|inspect|kind_of?|nil?|should|should_not/
|
6
|
+
end
|
7
|
+
|
8
|
+
include Hominid::Campaign
|
9
|
+
include Hominid::List
|
10
|
+
include Hominid::Security
|
11
|
+
|
12
|
+
# MailChimp API Documentation: http://apidocs.mailchimp.com/api/1.3/
|
13
|
+
MAILCHIMP_API_VERSION = "1.3"
|
14
|
+
|
15
|
+
# Initialize with an API key and config options
|
16
|
+
def initialize(api_key, config = {})
|
17
|
+
raise ArgumentError.new('Your Mailchimp API key appears to be malformed.') unless api_key.include?('-')
|
18
|
+
dc = api_key.split('-').last
|
19
|
+
defaults = {
|
20
|
+
:api_version => MAILCHIMP_API_VERSION,
|
21
|
+
:domain => 'api.mailchimp.com',
|
22
|
+
:secure => false,
|
23
|
+
:timeout => nil
|
24
|
+
}
|
25
|
+
@config = defaults.merge(config).freeze
|
26
|
+
protocol = @config[:secure] ? 'https' : 'http'
|
27
|
+
@api_key = api_key
|
28
|
+
@chimpApi = XMLRPC::Client.new2("#{protocol}://#{dc}.#{@config[:domain]}/#{@config[:api_version]}/", nil, @config[:timeout])
|
29
|
+
@chimpApi.http_header_extra = { 'accept-encoding' => 'identity' }
|
30
|
+
end
|
31
|
+
|
32
|
+
def method_missing(api_method, *args) # :nodoc:
|
33
|
+
@chimpApi.call(camelize_api_method_name(api_method.to_s), @api_key, *args)
|
34
|
+
rescue XMLRPC::FaultException => error
|
35
|
+
super if error.faultCode == -32601
|
36
|
+
raise APIError.new(error)
|
37
|
+
end
|
38
|
+
|
39
|
+
def respond_to?(api_method) # :nodoc:
|
40
|
+
@chimpApi.call(api_method, @api_key)
|
41
|
+
rescue XMLRPC::FaultException => error
|
42
|
+
error.faultCode == -32601 ? false : true
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def camelize_api_method_name(str)
|
48
|
+
str.to_s[0].chr.downcase + str.gsub(/(?:^|_)(.)/) { $1.upcase }[1..str.size]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class APIError < StandardError
|
53
|
+
attr_accessor :fault_code
|
54
|
+
def initialize(error)
|
55
|
+
self.fault_code = error.faultCode
|
56
|
+
super("<#{error.faultCode}> #{error.message}")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Hominid
|
2
|
+
module Campaign
|
3
|
+
|
4
|
+
# Find a campaign by id
|
5
|
+
def find_campaign_by_id(campaign_id)
|
6
|
+
campaigns({:campaign_id => campaign_id})['data']
|
7
|
+
end
|
8
|
+
|
9
|
+
# Find a campaign by web_id
|
10
|
+
def find_campaign_by_web_id(campaign_web_id)
|
11
|
+
campaigns['data'].find {|c| c["web_id"] == campaign_web_id}
|
12
|
+
end
|
13
|
+
|
14
|
+
# Find a campaign by name
|
15
|
+
def find_campaigns_by_title(campaign_title, *args)
|
16
|
+
campaigns({:title => campaign_title}, *args)['data']
|
17
|
+
end
|
18
|
+
|
19
|
+
# Find campaigns by list name
|
20
|
+
def find_campaigns_by_list_name(list_name, *args)
|
21
|
+
campaigns({:list_id => find_list_id_by_name(list_name)}, *args)['data']
|
22
|
+
end
|
23
|
+
|
24
|
+
# Find campaigns by list id
|
25
|
+
def find_campaigns_by_list_id(list_id, *args)
|
26
|
+
campaigns({:list_id => list_id}, *args)['data']
|
27
|
+
end
|
28
|
+
|
29
|
+
# Find campaigns by type
|
30
|
+
def find_campaigns_by_type(campaign_type, *args)
|
31
|
+
campaigns({:type => campaign_type}, *args)['data']
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Hominid
|
2
|
+
class Export
|
3
|
+
|
4
|
+
# MailChimp Export API Documentation: http://apidocs.mailchimp.com/export/1.0/
|
5
|
+
MAILCHIMP_EXPORT_VERSION = "1.0"
|
6
|
+
|
7
|
+
# Initialize with an API key and config options
|
8
|
+
def initialize(api_key, config = {})
|
9
|
+
raise ArgumentError.new('Your Mailchimp API key appears to be malformed.') unless api_key.include?('-')
|
10
|
+
dc = api_key.split('-').last
|
11
|
+
defaults = {
|
12
|
+
:api_version => MAILCHIMP_EXPORT_VERSION,
|
13
|
+
:secure => false
|
14
|
+
}
|
15
|
+
@config = defaults.merge(config).freeze
|
16
|
+
protocol = @config[:secure] ? 'https' : 'http'
|
17
|
+
@api_key = api_key
|
18
|
+
@api_base = "#{protocol}://#{dc}.api.mailchimp.com/export/#{@config[:api_version]}"
|
19
|
+
end
|
20
|
+
|
21
|
+
# TODO: We'll have to see how this progresses with regard to Mailchimp
|
22
|
+
# adding methods to the Export API. It would be nice to have this
|
23
|
+
# model follow the "method_missing" style of the others, but it
|
24
|
+
# would require passing arguments in as a hash:
|
25
|
+
#
|
26
|
+
# hominid_export.list({:id => 123, :status => 'unsubscribed'})
|
27
|
+
#
|
28
|
+
# It's the only way to get the *args to map over to the params hash
|
29
|
+
# if we use the "method_missing" approach. For now, this way seems
|
30
|
+
# more intuitive to the end user.
|
31
|
+
|
32
|
+
def list(id, status = 'subscribed', segment = [], since = '1900-01-01 00:00:00')
|
33
|
+
post_data = {
|
34
|
+
:apikey => @api_key,
|
35
|
+
:id => id,
|
36
|
+
:status => status,
|
37
|
+
:since => since
|
38
|
+
}
|
39
|
+
call('list', post_data)
|
40
|
+
end
|
41
|
+
|
42
|
+
def campaign_subscriber_activity(id, include_empty = false)
|
43
|
+
post_data = {
|
44
|
+
:apikey => @api_key,
|
45
|
+
:id => id,
|
46
|
+
:include_empty => include_empty,
|
47
|
+
}
|
48
|
+
call('campaignSubscriberActivity', post_data)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def call(list_method, post_data)
|
54
|
+
uri = URI.parse("#{@api_base}/#{list_method}/")
|
55
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
56
|
+
http.use_ssl = true if @config[:secure]
|
57
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
58
|
+
request.set_form_data(post_data)
|
59
|
+
response = http.request(request)
|
60
|
+
response.body
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/hominid/list.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Hominid
|
2
|
+
module List
|
3
|
+
|
4
|
+
# Find a list by name
|
5
|
+
def find_list_by_name(list_name)
|
6
|
+
lists['data'].find {|l| l["name"] == list_name}
|
7
|
+
end
|
8
|
+
|
9
|
+
# Find a list ID by name, returns nil if no list found
|
10
|
+
def find_list_id_by_name(list_name)
|
11
|
+
list = find_list_by_name(list_name)
|
12
|
+
list && list["id"]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Find a list by ID
|
16
|
+
def find_list_by_id(list_id)
|
17
|
+
lists['data'].find {|l| l["id"] == list_id}
|
18
|
+
end
|
19
|
+
|
20
|
+
# Find a list by web_id
|
21
|
+
def find_list_by_web_id(list_web_id)
|
22
|
+
lists['data'].find {|l| l["web_id"] == list_web_id}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Find a list ID by web_id, returns nil if no list found
|
26
|
+
def find_list_id_by_web_id(list_web_id)
|
27
|
+
list = find_list_by_web_id(list_web_id)
|
28
|
+
list && list["id"]
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Hominid
|
2
|
+
module Security
|
3
|
+
|
4
|
+
# Get a list of all API keys
|
5
|
+
def apikeys(username, password, expired = false)
|
6
|
+
@chimpApi.call("apikeys", username, password, @api_key, expired)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Add an API key to your account
|
10
|
+
def apikey_add(username, password)
|
11
|
+
@chimpApi.call("apikeyAdd", username, password, @api_key)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Expire a specific API key
|
15
|
+
def apikey_expire(username, password, api_key)
|
16
|
+
@chimpApi.call("apikeyExpire", username, password, api_key)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/hominid/sts.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Hominid
|
2
|
+
class STS < API
|
3
|
+
|
4
|
+
# MailChimp STS API Documentation: http://apidocs.mailchimp.com/sts/1.0/
|
5
|
+
MAILCHIMP_STS_VERSION = "1.0"
|
6
|
+
|
7
|
+
# Initialize with an API key and config options
|
8
|
+
def initialize(api_key, config = {})
|
9
|
+
defaults = {
|
10
|
+
:api_version => MAILCHIMP_STS_VERSION,
|
11
|
+
:domain => 'sts.mailchimp.com',
|
12
|
+
:secure => false,
|
13
|
+
:timeout => nil
|
14
|
+
}
|
15
|
+
super(api_key, defaults.merge(config))
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hominid
|
4
|
+
describe API do
|
5
|
+
it "requires an API key" do
|
6
|
+
expect {Hominid::API.new}.should raise_error(ArgumentError)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "requires a valid API key" do
|
10
|
+
expect {Hominid::API.new(@invalid_api_key)}.should raise_error(ArgumentError)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "also accepts config options" do
|
14
|
+
expect {Hominid::API.new(@valid_api_key, {:secure => true})}.should_not raise_error(ArgumentError)
|
15
|
+
end
|
16
|
+
# TODO: Need a way to mock XMLRPC requests.
|
17
|
+
end
|
18
|
+
|
19
|
+
describe STS do
|
20
|
+
it "returns an instance of API" do
|
21
|
+
Hominid::STS.new(@valid_api_key).should be_kind_of(Hominid::API)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'fakeweb'
|
3
|
+
require 'hominid'
|
4
|
+
|
5
|
+
FakeWeb.allow_net_connect = false
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.before(:each) do
|
9
|
+
FakeWeb.clean_registry
|
10
|
+
@valid_api_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us1'
|
11
|
+
@invalid_api_key = 'not_a_valid_api_key'
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hominid-wout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.6
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Getting
|
9
|
+
- Wout Fierens
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-06-01 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>'
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>'
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 1.0.0
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: fakeweb
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>'
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.6.4
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>'
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.6.4
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: simplecov
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: rspec
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
description: Hominid is a Ruby gem that provides a wrapper for interacting with the
|
96
|
+
Mailchimp email marketing service MC, STS and Export API's.
|
97
|
+
email: bwout@impinc.co.uk
|
98
|
+
executables: []
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files:
|
101
|
+
- LICENSE.txt
|
102
|
+
- README.rdoc
|
103
|
+
files:
|
104
|
+
- .rspec
|
105
|
+
- .travis.yml
|
106
|
+
- Gemfile
|
107
|
+
- Guardfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.rdoc
|
110
|
+
- Rakefile
|
111
|
+
- VERSION
|
112
|
+
- hominid.gemspec
|
113
|
+
- lib/hominid.rb
|
114
|
+
- lib/hominid/api.rb
|
115
|
+
- lib/hominid/campaign.rb
|
116
|
+
- lib/hominid/export.rb
|
117
|
+
- lib/hominid/list.rb
|
118
|
+
- lib/hominid/security.rb
|
119
|
+
- lib/hominid/sts.rb
|
120
|
+
- spec/hominid/hominid_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
homepage: https://github.com/wout/hominid
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
hash: -1405847718566908098
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 1.8.25
|
147
|
+
signing_key:
|
148
|
+
specification_version: 3
|
149
|
+
summary: Ruby gem for interacting with the Mailchimp API's.
|
150
|
+
test_files: []
|