mailchimp 0.0.7.alpha → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,4 +14,5 @@
14
14
  * [Dave Worth](https://github.com/daveworth)
15
15
  * [Mike Skalnik](https://github.com/skalnik)
16
16
  * [Kristopher Murata](https://github.com/krsmurata)
17
- * [Michael Klishin](https://github.com/michaelklishin)
17
+ * [Michael Klishin](https://github.com/michaelklishin)
18
+ * [Ben Simpson](https://github.com/bsimpson)
@@ -63,15 +63,9 @@ or
63
63
  ### Export API usage
64
64
 
65
65
  In addition to the standard API you can make calls to the
66
- [MailChimp Export API](http://apidocs.mailchimp.com/export/1.0/) using a APIExport object. Given an existing
67
- Mailchimp::API object you can request a new Mailchimp::APIExporter object:
68
-
69
- api = Mailchimp::API.new(@api_key)
70
- mailchimp_export = api.get_exporter
71
-
72
- or you can construct a new object directly:
73
-
74
- mailchimp_export = Mailchimp::APIExport.new(@api_key)
66
+ [MailChimp Export API](http://apidocs.mailchimp.com/export/1.0/) using a Mailchimp::Export object:
67
+
68
+ mailchimp_export = Mailchimp::Export.new(@api_key)
75
69
 
76
70
  Calling Export API functions is identical to making standard API calls but the
77
71
  return value is an Enumerator which loops over the lines returned from the
@@ -32,7 +32,7 @@ To check if your api_key is valid:
32
32
 
33
33
  ### Sending a message
34
34
 
35
- Send a message so a single email:
35
+ Send a message to a single email:
36
36
 
37
37
  response = mandrill.messages_send({
38
38
  :message => {
@@ -41,7 +41,7 @@ Send a message so a single email:
41
41
  :text => 'hello world',
42
42
  :from_name => 'John Smith',
43
43
  :from_email => 'support@somedomain.com',
44
- :to => ['user@someotherdomain.com']
44
+ :to => [{'email' => 'user@someotherdomain.com', 'name' => 'User Name'}]
45
45
  }
46
46
  })
47
47
 
@@ -14,7 +14,7 @@ confident that it should work out of the box for most usage scenarios.
14
14
  ##Installation
15
15
 
16
16
  # This supercedes uakari and gibbon
17
- $ gem install mailchimp
17
+ $ gem install mailchimp --pre
18
18
 
19
19
  ##Requirements
20
20
 
@@ -1,5 +1,8 @@
1
1
  module Mailchimp
2
2
  class Export < Base
3
+
4
+ format :plain
5
+
3
6
  def initialize(api_key = nil, default_parameters = {})
4
7
  super(api_key, {:apikey => api_key}.merge(default_parameters))
5
8
  end
@@ -7,28 +7,10 @@ module Mailchimp
7
7
  end
8
8
 
9
9
  def deliver!(message)
10
-
11
- message_payload = {
12
- :track_opens => settings[:track_opens],
13
- :track_clicks => settings[:track_clicks],
14
- :message => {
15
- :subject => message.subject,
16
- :from_name => settings[:from_name],
17
- :from_email => message.from.first,
18
- :to => message.to
19
- }
20
- }
21
-
22
- [:html, :text].each do |format|
23
- content = get_content_for(message, format)
24
- message_payload[:message][format] = content if content
25
- end
26
-
27
- message_payload[:tags] = settings[:tags] if settings[:tags]
28
-
29
10
  api_key = message.header['api-key'].blank? ? settings[:api_key] : message.header['api-key']
30
11
 
31
- Mailchimp::Mandrill.new(api_key).messages_send(message_payload)
12
+ message_payload = get_message_payload(message)
13
+ self.settings[:return_response] = Mailchimp::Mandrill.new(api_key).messages_send(message_payload)
32
14
  end
33
15
 
34
16
  private
@@ -43,7 +25,28 @@ module Mailchimp
43
25
  content ||= message.body if message.mime_type == mime_types[format]
44
26
  content
45
27
  end
46
-
28
+
29
+ def get_message_payload(message)
30
+ message_payload = {
31
+ :track_opens => settings[:track_opens],
32
+ :track_clicks => settings[:track_clicks],
33
+ :message => {
34
+ :subject => message.subject,
35
+ :from_name => message.header['from-name'].blank? ? settings[:from_name] : message.header['from-name'],
36
+ :from_email => message.from.first,
37
+ :to => message.to.map {|email| { :email => email, :name => email } },
38
+ :headers => {'Reply-To' => message.reply_to.nil? ? nil : message.reply_to }
39
+ }
40
+ }
41
+ message_payload[:message][:bcc_address] = message.bcc.first if message.bcc && !message.bcc.empty?
42
+ [:html, :text].each do |format|
43
+ content = get_content_for(message, format)
44
+ message_payload[:message][format] = content if content
45
+ end
46
+
47
+ message_payload[:tags] = settings[:tags] if settings[:tags]
48
+ message_payload
49
+ end
47
50
  end
48
51
  end
49
52
 
@@ -1,3 +1,3 @@
1
1
  module Mailchimp
2
- VERSION = "0.0.7.alpha"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Mailchimp::VERSION
8
8
  s.authors = ["Chris Kelly"]
9
9
  s.email = ["chris@highgroove.com"]
10
- s.homepage = ""
10
+ s.homepage = "https://github.com/mailchimp/mailchimp-gem"
11
11
  s.summary = %q{Mailchimp APIs in Ruby}
12
12
  s.description = %q{This provides Ruby access to (eventually) all of Mailchimp's APIs}
13
13
 
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ class ExportIntegrationTest < Test::Unit::TestCase
4
+
5
+ should "send request List Data from the Mailchimp Export API" do
6
+
7
+ FakeWeb.register_uri(
8
+ :post,
9
+ 'http://us2.api.mailchimp.com/export/1.0/list/',
10
+ body: '["Email Address","First Name","Last Name","Salesforce ID","EMAIL_TYPE","MEMBER_RATING","OPTIN_TIME","OPTIN_IP","CONFIRM_TIME","CONFIRM_IP","LATITUDE","LONGITUDE","GMTOFF","DSTOFF","TIMEZONE","CC","REGION","LAST_CHANGED"]
11
+ ["highgroove@example.com","Daniel","Rice","00Qd0000005MKaEEAW","html",2,"2011-10-06 20:06:46","173.160.74.121","2011-10-06 20:07:28","173.160.74.121","33.7490000","-84.3880000","-5","-4","America\/Kentucky\/Monticello","US","GA","2012-03-12 17:45:18"]
12
+ ["chimpy@example.com","Daniel","Rice","00Qd0000006AjjtEAC","html",2,"",null,"2012-03-08 20:52:31","173.160.74.121",null,null,null,null,null,null,null,"2012-03-12 17:45:20"]
13
+ ["wolfbrain@example.com","George P","Burdell","00Qd0000006AjjuEAC","html",2,"",null,"2012-03-08 20:53:10","173.160.74.121",null,null,null,null,null,null,null,"2012-03-12 17:45:22"]'
14
+ )
15
+
16
+ m = Mailchimp::Export.new('abc123-us2')
17
+ response = m.list(:id => 'xxxxxxxx')
18
+
19
+ assert_kind_of Enumerator, response
20
+
21
+ end
22
+
23
+ should "get campaign subscriber activity" do
24
+
25
+ FakeWeb.register_uri(
26
+ :post,
27
+ 'http://us2.api.mailchimp.com/export/1.0/campaignSubscriberActivity/',
28
+ body: '{"highgroove@example.com":[{"action":"open","timestamp":"2012-03-12 20:14:17","url":null,"ip":"184.77.22.196"}]} {"wolfbrain@example.com":[{"action":"open","timestamp":"2012-03-12 20:14:20","url":null,"ip":"184.77.22.196"}]}'.to_json
29
+ )
30
+ response = Mailchimp::Export.new('abc123-us2').campaign_subscriber_activity(:id => 'xxxxxxxx')
31
+
32
+ assert_kind_of Enumerator, response
33
+ end
34
+ end
@@ -38,6 +38,8 @@ def mock_mail_message(options = {})
38
38
  message.stubs(:mime_type).returns('text/html')
39
39
  message.stubs(:html_part).returns(nil)
40
40
  message.stubs(:text_part).returns(nil)
41
-
41
+ message.stubs(:reply_to).returns('replyto@example.com')
42
+ message.stubs(:bcc).returns(nil)
43
+
42
44
  message
43
45
  end
@@ -4,7 +4,7 @@ require File.join('./lib/mailchimp','handlers', 'mandrill_delivery_handler')
4
4
  class MandrillDeliveryHandlerTest < Test::Unit::TestCase
5
5
  context "when delivering a Mail::Message to the Mandrill API" do
6
6
  setup do
7
- @mandrill_delivery_handler = Mailchimp::MandrillDeliveryHandler.new
7
+ @mandrill_delivery_handler = Mailchimp::MandrillDeliveryHandler.new(:from_name => "Foo Bar")
8
8
  @fake_mandrill_api_response = [{"email"=>"foo@bar.com", "status"=>"sent"}]
9
9
 
10
10
  FakeWeb.register_uri(
@@ -19,5 +19,36 @@ class MandrillDeliveryHandlerTest < Test::Unit::TestCase
19
19
  response = @mandrill_delivery_handler.deliver!(message)
20
20
  assert_equal @fake_mandrill_api_response, response
21
21
  end
22
+
23
+ should "store the api response in the settings[:return_response] hash key" do
24
+ message = mock_mail_message
25
+ response = @mandrill_delivery_handler.deliver!(message)
26
+ assert_equal @fake_mandrill_api_response, @mandrill_delivery_handler.settings[:return_response]
27
+ end
28
+
29
+ context "for the mandrill api payload" do
30
+ should "build a valid Mandrill API payload" do
31
+ message = mock_mail_message
32
+ @mandrill_delivery_handler.deliver!(message)
33
+ message_payload = @mandrill_delivery_handler.send(:get_message_payload, message)
34
+
35
+ assert_equal true, message_payload[:track_opens]
36
+ assert_equal true, message_payload[:track_clicks]
37
+ assert_equal 'Subject', message_payload[:message][:subject]
38
+ assert_equal 'foo@bar.com', message_payload[:message][:from_email]
39
+ assert_equal 'Foo Bar', message_payload[:message][:from_name]
40
+ assert_equal 'foo@bar.com has moved use awesome@awesomesauce.com now', message_payload[:message][:html]
41
+ assert_equal [{email: 'foo@bar.com', name: 'foo@bar.com'}], message_payload[:message][:to]
42
+ assert_equal({'Reply-To' => 'replyto@example.com'}, message_payload[:message][:headers])
43
+ end
44
+
45
+ should "handle bcc correctly" do
46
+ message = mock_mail_message
47
+ message.stubs(:bcc).returns(["bar@bar.com"])
48
+ @mandrill_delivery_handler.deliver!(message)
49
+ message_payload = @mandrill_delivery_handler.send(:get_message_payload, message)
50
+ assert_equal 'bar@bar.com', message_payload[:message][:bcc_address]
51
+ end
52
+ end
22
53
  end
23
- end
54
+ end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailchimp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7.alpha
5
- prerelease: 6
4
+ version: 0.0.8
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Chris Kelly
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-06 00:00:00.000000000Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &70308507199520 !ruby/object:Gem::Requirement
16
+ requirement: &70361207201980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70308507199520
24
+ version_requirements: *70361207201980
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ruby-debug19
27
- requirement: &70308507199020 !ruby/object:Gem::Requirement
27
+ requirement: &70361207201240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70308507199020
35
+ version_requirements: *70361207201240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70308507198560 !ruby/object:Gem::Requirement
38
+ requirement: &70361207200740 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70308507198560
46
+ version_requirements: *70361207200740
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: shoulda
49
- requirement: &70308507198140 !ruby/object:Gem::Requirement
49
+ requirement: &70361207200240 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70308507198140
57
+ version_requirements: *70361207200240
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mocha
60
- requirement: &70308507197640 !ruby/object:Gem::Requirement
60
+ requirement: &70361207199720 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70308507197640
68
+ version_requirements: *70361207199720
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: cover_me
71
- requirement: &70308507197140 !ruby/object:Gem::Requirement
71
+ requirement: &70361207199260 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70308507197140
79
+ version_requirements: *70361207199260
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: fakeweb
82
- requirement: &70308507196700 !ruby/object:Gem::Requirement
82
+ requirement: &70361207198760 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70308507196700
90
+ version_requirements: *70361207198760
91
91
  description: This provides Ruby access to (eventually) all of Mailchimp's APIs
92
92
  email:
93
93
  - chris@highgroove.com
@@ -120,6 +120,7 @@ files:
120
120
  - mailchimp.gemspec
121
121
  - test/integration/api_test.rb
122
122
  - test/integration/base_test.rb
123
+ - test/integration/export_test.rb
123
124
  - test/integration/mandrill_test.rb
124
125
  - test/integration/sts_test.rb
125
126
  - test/lib/api_test.rb
@@ -129,7 +130,7 @@ files:
129
130
  - test/lib/sts_test.rb
130
131
  - test/test_helper.rb
131
132
  - test/unit/handlers/mandrill_deliver_handler_test.rb
132
- homepage: ''
133
+ homepage: https://github.com/mailchimp/mailchimp-gem
133
134
  licenses: []
134
135
  post_install_message:
135
136
  rdoc_options: []
@@ -144,18 +145,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
145
  required_rubygems_version: !ruby/object:Gem::Requirement
145
146
  none: false
146
147
  requirements:
147
- - - ! '>'
148
+ - - ! '>='
148
149
  - !ruby/object:Gem::Version
149
- version: 1.3.1
150
+ version: '0'
150
151
  requirements: []
151
152
  rubyforge_project: mailchimp
152
- rubygems_version: 1.8.6
153
+ rubygems_version: 1.8.17
153
154
  signing_key:
154
155
  specification_version: 3
155
156
  summary: Mailchimp APIs in Ruby
156
157
  test_files:
157
158
  - test/integration/api_test.rb
158
159
  - test/integration/base_test.rb
160
+ - test/integration/export_test.rb
159
161
  - test/integration/mandrill_test.rb
160
162
  - test/integration/sts_test.rb
161
163
  - test/lib/api_test.rb