Empact-hominid 1.1.12 → 1.2.0

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