hominid 1.2.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ pkg/*
3
+ pkg/*.*
4
+ .svn
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 [Brian Getting]
1
+ Copyright (c) 2009 Brian Getting
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,76 +1,161 @@
1
1
  h1. Hominid
2
2
 
3
- Hominid is a Ruby gem for interacting with the "Mailchimp API":http://www.mailchimp.com/api/1.2/.
3
+ Hominid is a Ruby gem that provides a wrapper for interacting with the "Mailchimp":http://www.mailchimp.com email marketing service API ("version 1.2":http://www.mailchimp.com/api/1.2/).
4
4
 
5
5
  h2. Installation
6
6
 
7
- Install the gem:
7
+ <pre><code>sudo gem install hominid, :version => '>= 2.0.0', :source => "http://gemcutter.org"</code></pre>
8
8
 
9
- <pre><code>sudo gem install hominid</code></pre>
9
+ Hominid is hosted at "Gemcutter":http://gemcutter.org. Be sure that you have the Gemcutter gem installed if you are having trouble installing Hominid:
10
10
 
11
- In your @environment.rb@ file:
11
+ <pre><code>sudo gem install gemcutter
12
+ gem tumble</code></pre>
12
13
 
13
- <pre><code>config.gem "hominid"</code></pre>
14
+ h2. Configuration
14
15
 
15
- You can also install Hominid as a Rails plugin:
16
+ You will need to create a "Mailchimp":http://www.mailchimp.com/signup account and get your API key (available at http://admin.mailchimp.com/account/api/) in order to get started.
16
17
 
17
- <pre><code>script/plugin install git://github.com/bgetting/hominid.git</code></pre>
18
+ If you are using Hominid inside a Rails application, you can create a config file at @/config/hominid.yml@ with your Mailchimp account information and basic configuration options:
18
19
 
19
- h2. Setup
20
+ <pre><code>development:
21
+ username: USERNAME
22
+ password: PASSWORD
23
+ api_key: API KEY
24
+ send_goodbye: false
25
+ send_notify: false
26
+ double_opt: false
20
27
 
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).
28
+ ...</code></pre>
22
29
 
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.
30
+ Run @rake hominid:config@ from within a Rails app to create an empty config file.
31
+ Note: You will need to <pre><code>require 'hominid'</code></pre> in your @Rakefile@ to make this rake task available to your application.
24
32
 
25
- h2. Example
33
+ h2. Usage
26
34
 
27
- To interact with the Mailchimp API, simply create a new Hominid object:
35
+ Not all API methods are supported (yet). Currently there are classes for working with lists (_Hominid::List_), campaigns (_Hominid::Campaign_) and accessing the helper methods (_Hominid::Helper_).
28
36
 
29
- <pre><code>@hominid = Hominid.new</code></pre>
37
+ h3. Working with Lists
30
38
 
31
- _or_
39
+ The _Hominid::List_ class is available for working finding lists and working with particular lists. See _Hominid::List_ for more information.
32
40
 
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>
41
+ h4. List Finder Methods
34
42
 
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:
43
+ There are finder methods for working with lists. Refer to _Hominid::List_ to see the other finders availables.
36
44
 
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
+ <pre><code>lists = Hominid::List.all</code></pre>
45
46
 
46
- To subscribe:
47
+ <pre><code>list = Hominid::List.find_by_name("List Name")</code></pre>
47
48
 
48
- <pre><code>@hominid.subscribe(@list_id, "email@example.com", :user_info => {:FNAME => 'Bob', :LNAME => 'Smith'}, :email_type => 'html')</code></pre>
49
+ <pre><code>list = Hominid::List.find(id_or_web_id)</code></pre>
49
50
 
50
- To unsubscribe:
51
+ h4. Subscribing
51
52
 
52
- <pre><code>@hominid.unsubscribe(@list_id, "email@example.com")</code></pre>
53
+ To subscribe a person or persons to a Mailchimp list:
53
54
 
54
- To update a member:
55
+ <pre><code>list.subscribe("sample@emailaddress.com")</code></pre>
55
56
 
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
+ <pre><code>list.subscribe_many([{:EMAIL => 'sample@emailaddress.com', :EMAIL_TYPE => 'html'}, {:EMAIL => 'another@emailaddress.com', :EMAIL_TYPE => 'html'}])</code></pre>
57
58
 
58
- _or_
59
+ h4. Unsubscribing
59
60
 
60
- <pre><code>@hominid.update_member(@list_id, "email@example.com", {:FNAME => 'Robert', :EMAIL => 'another@example.com'})</code></pre>
61
+ To unsubscribe a person or persons from a Mailchimp list:
61
62
 
62
- Campaign methods are also supported. You can get all the campaigns for a particular list by:
63
+ <pre><code>list.unsubscribe("sample@emailaddress.com")</code></pre>
63
64
 
64
- <pre><code>@hominid.campaigns(@list_id)</code></pre>
65
+ <pre><code>list.unsubscribe_many(['sample@emailaddress.com', 'another@emailaddress.com'])</code></pre>
65
66
 
66
- Leave the @@list_id@ out and it will return all the campaigns for your Mailchimp account.
67
+ h4. Updating
67
68
 
68
- h2. Other Stuff
69
+ In the following example, we will be changing a person's email address on the Mailchimp list from @sample@ to @another@:
69
70
 
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
+ <pre><code>list.update_member('sample@emailaddress.com', {:EMAIL => 'another@emailaddress.com'}, 'html')</code></pre>
71
72
 
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
+ You can also updated other attributes by including the MERGE_VARS that you want to change, such as @EMAIL@, @FNAME@, @LNAME@ and @INTERESTS@. Get a list of merge tags for a particular list by running @list.merge_tags@.
73
74
 
74
- So please, help us to improve this gem!
75
+ h3. Working with Campaigns
76
+
77
+ The _Hominid::Campaign_ class provides methods for working with a campaigns.
78
+
79
+ h4. Campaign Finder Methods
80
+
81
+ There are finder methods for campaigns as well. Refer to _Hominid::Campaign_ to see the other finders available.
82
+
83
+ <pre><code>campaigns = Hominid::Campaign.all</code></pre>
84
+
85
+ <pre><code>campaigns = Hominid::Campaign.find_by_list_name("List Name")</code></pre>
86
+
87
+ h4. Creating a Campaign
88
+
89
+ You can create new campaigns using Hominid as well. Please refer to the documentation in _Hominid::Base_ for more information about the options available when creating a new campaign.
90
+
91
+ <pre><code>new_campaign = Hominid::Campaign.create('regular', options, content, segment_opts, type_opts)</code></pre>
92
+
93
+ h4. Schedule a Campaign
94
+
95
+ As an example of how to work with a particular campaign, use the _Hominid::Campaign_ class. Extending from the previous example, since the _#create_campaign_ method returns the ID of the created campaign, we can use it to instantiate the _Hominid::Campaign_ class and schedule our new campaign to go be delivered 2 days from now:
96
+
97
+ <pre><code>campaign = Hominid::Campaign.new(:id => new_campaign)</code></pre>
98
+
99
+ <pre><code>campaign.schedule_campaign(2.days.from_now)</code></pre>
100
+
101
+ h3. Helper Methods
102
+
103
+ The _Hominid::Helper_ class provides a way to access the helper methods for the Mailchimp API. For example, to create a new folder for filing campaigns:
104
+
105
+ <pre><code>folder = Hominid::Helper.create_folder("Folder Name")</code></pre>
106
+
107
+ h2. Syncing Your Application
108
+
109
+ If you are integrating an application with Mailchimp, Hominid will provide a way for your app to connect with your Mailchimp account. However, it does not provide a way for Mailchimp to connect to your application, which is why Mailchimp has implemented "web hooks":http://www.mailchimp.com/api/webhooks/.
110
+
111
+ The _Hominid::Webhook class helps with receiving <tt>POST</tt> data from a Mailchimp webhook:
112
+
113
+ <pre><code>hook = Hominid::Webhook.new(params)
114
+ case hook.event
115
+ when "subscribe"
116
+ user = User.find_by_email(hook.email)
117
+ user.opted_in = true
118
+ user.save
119
+ when "unsubscribe"
120
+ user = User.find_by_email(hook.email)
121
+ user.opted_in = false
122
+ user.save
123
+ when "profile"
124
+ user = User.find_by_email(hook.email)
125
+ user.first_name = hook.first_name
126
+ user.last_name = hook.last_name
127
+ user.email_type = hook.email_type
128
+ user.save
129
+ when "upemail"
130
+ user = User.find_by_email(hook.old_email)
131
+ user.email = hook.new_email
132
+ user.save
133
+ end</code></pre>
134
+
135
+ h2. Contributors
136
+
137
+ Hominid is maintained by "Brian Getting":http://terra-firma-design.com. A very special thank-you to "Michael Strüder":http://github.com/mikezter for all of his hard work. Also, Hominid wouldn't be anywhere near as awesome as it is today without fantastic contributions and inspiration from:
138
+
139
+ * "Alan Harper":http://github.com/aussiegeek
140
+ * "Will":http://github.com/willinfront
141
+ * "Ben Woosley":http://github.com/Empact
142
+ * "banker":http://github.com/banker
143
+ * "Kristoffer Renholm":http://github.com/renholm
144
+ * "Wiktor Schmidt":http://github.com/netguru
145
+ * "ron":http://github.com/ron
146
+ * "Matthew Carlson":http://mandarinsoda.com/
147
+ * "Kelly Mahan":http://digimedia.com/
148
+ * "C.G. Brown":http://www.projectlocker.com/
149
+
150
+ h2. Note on Patches/Pull Requests
151
+
152
+ # Fork the project.
153
+ # Make your feature addition or bug fix.
154
+ # Add tests for it. This is important so I don't break it in a future version unintentionally.
155
+ # Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
156
+ # Send me a pull request. Bonus points for topic branches.
157
+
158
+ h2. Copyright
159
+
160
+ Copyright (c) 2009 Brian Getting. See LICENSE for details.
75
161
 
76
- Copyright (c) 2009 Brian Getting, released under the MIT license.
data/Rakefile CHANGED
@@ -1,28 +1,57 @@
1
+ require 'rubygems'
1
2
  require 'rake'
2
- require 'rake/rdoctask'
3
3
 
4
4
  begin
5
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"]
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "hominid"
8
+ gem.summary = %Q{Hominid is a Ruby gem for interacting with the Mailchimp API.}
9
+ gem.description = %Q{Hominid is a Ruby gem that provides a wrapper for interacting with the Mailchimp email marketing service API.}
10
+ gem.email = "brian@terra-firma-design.com"
11
+ gem.homepage = "http://github.com/bgetting/hominid"
12
+ gem.authors = ["Brian Getting", "Michael Strüder"]
13
+ gem.add_development_dependency "shoulda"
13
14
  end
14
-
15
15
  Jeweler::GemcutterTasks.new
16
-
17
16
  rescue LoadError
18
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
19
25
  end
20
26
 
21
- desc 'Generate documentation for the hominid plugin.'
22
- Rake::RDocTask.new(:rdoc) do |rdoc|
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION')
47
+ version = File.read('VERSION')
48
+ else
49
+ version = ""
50
+ end
51
+
23
52
  rdoc.rdoc_dir = 'rdoc'
24
- rdoc.title = 'Hominid'
25
- rdoc.options << '--line-numbers' << '--inline-source'
26
- rdoc.rdoc_files.include('README')
53
+ rdoc.title = "hominid #{version}"
54
+ rdoc.rdoc_files.include('README*')
27
55
  rdoc.rdoc_files.include('lib/**/*.rb')
28
56
  end
57
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
@@ -1,44 +1,47 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hominid}
8
- s.version = "1.2.1"
8
+ s.version = "2.0.0"
9
9
 
10
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.}
11
+ s.authors = ["Brian Getting", "Michael Str\303\274der"]
12
+ s.date = %q{2009-10-30}
13
+ s.description = %q{Hominid is a Ruby gem that provides a wrapper for interacting with the Mailchimp email marketing service API.}
14
14
  s.email = %q{brian@terra-firma-design.com}
15
15
  s.extra_rdoc_files = [
16
- "README.textile"
16
+ "LICENSE",
17
+ "README.textile"
17
18
  ]
18
19
  s.files = [
19
- "MIT-LICENSE",
20
+ ".gitignore",
21
+ "LICENSE",
20
22
  "README.textile",
21
23
  "Rakefile",
22
- "VERSION.yml",
24
+ "VERSION",
23
25
  "hominid.gemspec",
24
26
  "hominid.yml.tpl",
25
- "init.rb",
26
- "install.rb",
27
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"
28
+ "lib/hominid/base.rb",
29
+ "lib/hominid/campaign.rb",
30
+ "lib/hominid/helper.rb",
31
+ "lib/hominid/list.rb",
32
+ "lib/hominid/webhook.rb",
33
+ "tasks/rails/hominid.rake",
34
+ "test/hominid_test.rb",
35
+ "test/test_helper.rb"
33
36
  ]
34
- s.homepage = %q{http://terra-firma-design.com}
37
+ s.homepage = %q{http://github.com/bgetting/hominid}
35
38
  s.rdoc_options = ["--charset=UTF-8"]
36
39
  s.require_paths = ["lib"]
37
40
  s.rubygems_version = %q{1.3.5}
38
41
  s.summary = %q{Hominid is a Ruby gem for interacting with the Mailchimp API.}
39
42
  s.test_files = [
40
- "spec/hominid_spec.rb",
41
- "spec/spec_helper.rb"
43
+ "test/hominid_test.rb",
44
+ "test/test_helper.rb"
42
45
  ]
43
46
 
44
47
  if s.respond_to? :specification_version then
@@ -46,8 +49,12 @@ Gem::Specification.new do |s|
46
49
  s.specification_version = 3
47
50
 
48
51
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
49
53
  else
54
+ s.add_dependency(%q<shoulda>, [">= 0"])
50
55
  end
51
56
  else
57
+ s.add_dependency(%q<shoulda>, [">= 0"])
52
58
  end
53
59
  end
60
+
@@ -1,4 +1,5 @@
1
1
  # Get your API key at http://admin.mailchimp.com/account/api/
2
+
2
3
  development:
3
4
  username:
4
5
  password:
@@ -1,265 +1,54 @@
1
1
  require 'xmlrpc/client'
2
+ require 'ostruct'
2
3
 
3
- class HominidError < RuntimeError
4
- def initialize(message)
5
- super(message)
6
- end
7
- end
4
+ module Hominid
8
5
 
9
- class HominidCommunicationError < HominidError
10
- def initialize(message)
11
- super(message)
6
+ class StandardError < ::StandardError
12
7
  end
13
- end
14
8
 
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
9
+ class APIError < StandardError
10
+ def initialize(error)
11
+ super("<#{error.faultCode}> #{error.message}")
23
12
  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
13
  end
29
14
 
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)
15
+ class ListError < APIError
75
16
  end
76
17
 
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)
18
+ class ListEmailError < ListError
100
19
  end
101
20
 
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)
21
+ class ListMergeError < ListError
158
22
  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))
23
+
24
+ class AlreadySubscribed < ListEmailError
227
25
  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))
26
+
27
+ class AlreadyUnsubscribed < ListEmailError
239
28
  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))
29
+
30
+ class NotExists < ListEmailError
246
31
  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)
32
+
33
+ class NotSubscribed < ListEmailError
251
34
  end
252
-
253
- protected
254
- def apply_defaults_to(options)
255
- @config.merge(options)
35
+
36
+ class CommunicationError < StandardError
37
+ def initialize(message)
38
+ super(message)
39
+ end
256
40
  end
41
+ end
257
42
 
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)
43
+ begin
44
+ # include the provided rake task
45
+ require 'rake'
46
+ unless Rake::Task.task_defined? "hominid:config"
47
+ load File.join(File.dirname(__FILE__), '..', 'tasks', 'rails', 'hominid.rake')
264
48
  end
49
+ rescue LoadError
50
+ # silently skip rake task inclusion unless the rake gem is installed
265
51
  end
52
+
53
+ require 'hominid/base'
54
+