simple_postmark 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,4 +19,7 @@ branches:
19
19
  matrix:
20
20
  exclude:
21
21
  - rvm: 1.9.2
22
- gemfile: gemfiles/Rails_master.gemfile
22
+ gemfile: gemfiles/Rails_master.gemfile
23
+ allow_failures:
24
+ - rvm: ruby-head
25
+ - gemfile: gemfiles/Rails_master.gemfile
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
- # simple_postmark [![Build Status](https://secure.travis-ci.org/haihappen/simple_postmark.png?branch=master)](http://travis-ci.org/haihappen/simple_postmark)
1
+ # simple_postmark
2
2
 
3
3
  SimplePostmark makes it easy to send mails via [Postmark](http://postmarkapp.com)™ using Rails 3's ActionMailer.
4
4
  SimplePostmark is inspired by [postmark-gem](https://github.com/wildbit/postmark-gem), but unfortunately postmark-gem forced to me to use non-standard Rails calls like `postmark_attachments`. SimplePostmark uses the standard Rails 3's ActionMailer syntax to send your emails via Postmark.
5
5
 
6
- Tested against Ruby versions `1.9.2`, `1.9.3`, `ruby-head` and Rails versions `3.0.x`, `3.1.x`, `3.2.x`, `master` (upcoming Rails `4.0.0`).
6
+ Tested against Ruby versions `1.9.2`, `1.9.3` and Rails versions `3.0.x`, `3.1.x`, `3.2.x`.
7
+ `ruby-head` (a.k.a. Ruby `2.0`) and Rails `master` (upcoming Rails `4.0`) should work too btw.
7
8
 
8
9
  If you are still using Ruby `1.8.7` or `Ruby Enterprise Edition` with Rails 3, you can use the backported version of this gem called [simple_postmark18](https://github.com/haihappen/simple_postmark/tree/ruby18).
9
10
 
@@ -44,7 +45,7 @@ And of course you can use standard attachment calls and [Postmark's tags](http:/
44
45
  class NotificationMailer < ActionMailer::Base
45
46
  def notification
46
47
  attachments['thebrocode.pdf'] = File.read('thebrocode.pdf')
47
-
48
+
48
49
  mail(to: 'ted@himym.tld', from: 'barney@himym.tld', subject: "I'm your bro!", tag: 'with-attachment') do
49
50
  # ...
50
51
  end
@@ -52,6 +53,31 @@ class NotificationMailer < ActionMailer::Base
52
53
  end
53
54
  ```
54
55
 
56
+ ## Advanced Configuration
57
+
58
+ * `api_key`: Your Postmark API key. Go to [your Rack](https://postmarkapp.com/servers),
59
+ selected the one you want to use and then go to the **Credentials** tab to find your API key.
60
+
61
+ * `return_response`: In order to receive the response from the Postmark API
62
+ – for example, if you want to store ErrorCode or MessageID -
63
+ set it to `true`. ([Mail](https://github.com/mikel/mail) which is the base of simple_postmark
64
+ expects this option.)
65
+
66
+ Example how the ErrorCode, MessageID and other values can be received from Postmark:
67
+
68
+ ```ruby
69
+ # config/environments/production.rb
70
+ config.action_mailer.simple_postmark_settings = { api_key: '********-****-****-****-************', return_response: true }
71
+
72
+ # your_mailer.rb
73
+ response = YourMailer.email.deliver!.parsed_response
74
+
75
+ response['MessageID']
76
+ # => "b7bc2f4a-e38e-4336-af7d-e6c392c2f817"
77
+ response['ErrorCode']
78
+ # => 0
79
+ ```
80
+
55
81
  ## Contributing
56
82
 
57
83
  1. Fork it
@@ -83,4 +109,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
83
109
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
84
110
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
85
111
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
86
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
112
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,7 +1,7 @@
1
1
  source :rubygems
2
2
 
3
3
  gem 'activesupport', github: 'rails/rails'
4
- gem 'active_record_deprecated_finders', github: 'rails/active_record_deprecated_finders'
4
+ gem 'activerecord-deprecated_finders', github: 'rails/activerecord-deprecated_finders'
5
5
  gem 'httparty'
6
6
  gem 'json'
7
7
  gem 'mail'
@@ -22,7 +22,10 @@ module Mail
22
22
 
23
23
  def to_postmark
24
24
  %w[attachments bcc cc from html_body reply_to subject tag text_body to].each.with_object({}) do |key, hash|
25
- hash[key.camelcase] = case (value = public_send(key).presence or next)
25
+ # mail returns different responses for mail[:reply_to] than mail.reply_to, and we want to prefer the former
26
+ # as it includes the name, not just the email
27
+ key_value = self[key.to_sym].nil? ? public_send(key) : self[key.to_sym]
28
+ hash[key.camelcase] = case (value = key_value.presence or next)
26
29
  when AttachmentsList then value.map(&:to_postmark)
27
30
  when Array then value.join(', ')
28
31
  else value.to_s
@@ -30,4 +33,4 @@ module Mail
30
33
  end
31
34
  end
32
35
  end
33
- end
36
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'simple_postmark'
3
- gem.version = '0.4.3'
3
+ gem.version = '0.4.4'
4
4
  gem.authors = 'Mario Uher'
5
5
  gem.email = 'uher.mario@gmail.com'
6
6
  gem.description = 'SimplePostmark makes it easy to send mails via Postmark™ using Rails 3\'s ActionMailer.'
@@ -96,6 +96,7 @@ describe 'SimplePostmark integration' do
96
96
 
97
97
  response['To'].must_equal(ENV['SIMPLE_POSTMARK_TO'])
98
98
  response['Message'].must_equal('OK')
99
+ response['MessageID'].wont_be_empty
99
100
  end
100
101
  end
101
102
  end if ENV['SIMPLE_POSTMARK_INTEGRATION_SPEC']
@@ -1,18 +1,28 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe Mail::Message do
4
- it 'responds to +to_postmark+' do
5
- Mail::Message.new.must_respond_to(:to_postmark)
4
+ describe 'integration into Mail::Message' do
5
+ subject { Mail::Message.new }
6
+
7
+
8
+ it 'responds to +to_postmark+' do
9
+ subject.must_respond_to(:to_postmark)
10
+ end
6
11
  end
7
12
 
8
13
 
9
- it 'responds to +to_postmark+' do
10
- Mail.new.must_respond_to(:to_postmark)
14
+ describe 'integration into Mail' do
15
+ subject { Mail.new }
16
+
17
+
18
+ it 'responds to +to_postmark+' do
19
+ subject.must_respond_to(:to_postmark)
20
+ end
11
21
  end
12
22
 
13
23
 
14
24
  describe :to_postmark do
15
- let(:mail) do
25
+ subject do
16
26
  Mail.new do
17
27
  from 'barney@himym.tld'
18
28
  to 'ted@himym.tld'
@@ -36,23 +46,23 @@ describe Mail::Message do
36
46
  'ContentType' => 'image/jpeg'
37
47
  }]
38
48
  }
39
- mail.add_file(File.join(File.dirname(__FILE__), '..', 'thebrocode.jpg'))
49
+ subject.add_file(File.join(File.dirname(__FILE__), '..', 'thebrocode.jpg'))
40
50
 
41
- mail.to_postmark.must_equal(hash)
51
+ subject.to_postmark.must_equal(hash)
42
52
  end
43
53
 
44
54
 
45
55
  it 'returns multiple recipients as comma-separated list' do
46
- mail.to = ['barney@himym.tld', 'marshall@himym.tld']
56
+ subject.to = ['barney@himym.tld', 'marshall@himym.tld']
47
57
 
48
- mail.to_postmark['To'].must_equal('barney@himym.tld, marshall@himym.tld')
58
+ subject.to_postmark['To'].must_equal('barney@himym.tld, marshall@himym.tld')
49
59
  end
50
60
 
51
61
 
52
62
  it 'returns all email headers as hash' do
53
- mail.bcc = 'lily@himym.tld'
54
- mail.cc = 'marshall@himym.tld'
55
- mail.reply_to = 'barney@barneystinsonblog.com'
63
+ subject.bcc = 'lily@himym.tld'
64
+ subject.cc = 'marshall@himym.tld'
65
+ subject.reply_to = 'barney@barneystinsonblog.com'
56
66
 
57
67
  hash = {
58
68
  'Bcc' => 'lily@himym.tld',
@@ -65,7 +75,29 @@ describe Mail::Message do
65
75
  'To' => 'ted@himym.tld'
66
76
  }
67
77
 
68
- mail.to_postmark.must_equal(hash)
78
+ subject.to_postmark.must_equal(hash)
79
+ end
80
+
81
+
82
+ it 'should use the from and reply-to names as well as the email addresses' do
83
+ subject.to = 'Lily <lily@himym.tld>'
84
+ subject.from = 'Marshall <marshall@himym.tld>'
85
+ subject.reply_to = 'Barney <barney@barneystinsonblog.com>'
86
+ subject.bcc = 'lily@himym.tld'
87
+ subject.cc = 'marshall@himym.tld'
88
+
89
+ hash = {
90
+ 'To' => 'Lily <lily@himym.tld>',
91
+ 'From' => 'Marshall <marshall@himym.tld>',
92
+ 'ReplyTo' => 'Barney <barney@barneystinsonblog.com>',
93
+ 'Bcc' => 'lily@himym.tld',
94
+ 'Cc' => 'marshall@himym.tld',
95
+ 'Subject' => "I'm your bro!",
96
+ 'Tag' => 'simple-postmark',
97
+ 'TextBody' => "Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!",
98
+ }
99
+
100
+ subject.to_postmark.must_equal(hash)
69
101
  end
70
102
  end
71
- end
103
+ end
@@ -1,46 +1,62 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe Mail::Part do
4
- it 'responds to +to_postmark+' do
5
- Mail::Part.new.must_respond_to(:to_postmark)
4
+ describe 'integration into Mail::Part' do
5
+ subject { Mail::Part.new }
6
+
7
+
8
+ it 'responds to +to_postmark+' do
9
+ subject.new.must_respond_to(:to_postmark)
10
+ end
6
11
  end
7
12
 
8
13
 
9
14
  describe :to_postmark do
10
- it 'returns body hash if part is not an attachment' do
11
- part = Mail::Part.new do
12
- body "Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!"
13
- content_type 'text/plain'
15
+ describe 'a text/plain part' do
16
+ let(:content) { "Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!" }
17
+ subject do
18
+ Mail::Part.new do
19
+ body content
20
+ content_type 'text/plain'
21
+ end
22
+ end
23
+
24
+
25
+ it 'returns body hash' do
26
+ part.to_postmark.must_equal('Name' => nil, 'Content' => content, 'ContentType' => 'text/plain')
14
27
  end
15
-
16
- content = "Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome. I'm your bro-I'm Broda!"
17
-
18
- part.to_postmark.must_equal('Name' => nil, 'Content' => content, 'ContentType' => 'text/plain')
19
28
  end
20
29
 
21
30
 
22
- it 'returns body hash if part is not an attachment' do
23
- part = Mail::Part.new do
24
- body "<p>Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome.<br /><br />I'm your bro-I'm Broda!</p>"
25
- content_type 'text/html'
31
+ describe 'a text/html part' do
32
+ let(:content) { "<p>Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome.<br /><br />I'm your bro-I'm Broda!</p>" }
33
+ subject do
34
+ Mail::Part.new do
35
+ body content
36
+ content_type 'text/html'
37
+ end
38
+ end
39
+
40
+
41
+ it 'returns body hash' do
42
+ part.to_postmark.must_equal('Name' => nil, 'Content' => content, 'ContentType' => 'text/html')
26
43
  end
27
-
28
- content = "<p>Think of me like Yoda, but instead of being little and green I wear suits and I'm awesome.<br /><br />I'm your bro-I'm Broda!</p>"
29
-
30
- part.to_postmark.must_equal('Name' => nil, 'Content' => content, 'ContentType' => 'text/html')
31
44
  end
32
45
 
33
46
 
34
- it 'returns base64-encoded file-content hash if part is an attachment' do
35
- file = File.join(File.dirname(__FILE__), '..', 'thebrocode.jpg')
36
-
37
- part = Mail::Part.new.tap do |mail|
38
- mail.add_file(file)
39
- end.attachments.first
40
-
41
- content = [File.read(file)].pack('m')
42
-
43
- part.to_postmark.must_equal('Name' => 'thebrocode.jpg', 'Content' => content, 'ContentType' => 'image/jpeg')
47
+ describe 'a file part' do
48
+ let(:file) { File.join(File.dirname(__FILE__), '..', 'thebrocode.jpg') }
49
+ let(:content) { [File.read(file)].pack('m') }
50
+ subject do
51
+ Mail::Part.new.tap do |mail|
52
+ mail.add_file(file)
53
+ end.attachments.first
54
+ end
55
+
56
+
57
+ it 'returns base64-encoded file-content hash if part is an attachment' do
58
+ part.to_postmark.must_equal('Name' => 'thebrocode.jpg', 'Content' => content, 'ContentType' => 'image/jpeg')
59
+ end
44
60
  end
45
61
  end
46
62
  end
metadata CHANGED
@@ -1,132 +1,135 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: simple_postmark
3
- version: !ruby/object:Gem::Version
4
- hash: 9
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.4
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 3
10
- version: 0.4.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Mario Uher
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-06-09 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-11-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: activesupport
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
- version: "3.0"
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: httparty
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: httparty
32
+ requirement: !ruby/object:Gem::Requirement
40
33
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
48
38
  type: :runtime
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: json
52
39
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
54
41
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: json
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
62
54
  type: :runtime
63
- version_requirements: *id003
64
- - !ruby/object:Gem::Dependency
65
- name: mail
66
55
  prerelease: false
67
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
68
57
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
- version: "0"
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: mail
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
76
70
  type: :runtime
77
- version_requirements: *id004
78
- - !ruby/object:Gem::Dependency
79
- name: minitest
80
71
  prerelease: false
81
- requirement: &id005 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
82
73
  none: false
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- hash: 3
87
- segments:
88
- - 0
89
- version: "0"
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: minitest
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
90
86
  type: :development
91
- version_requirements: *id005
92
- - !ruby/object:Gem::Dependency
93
- name: rails
94
87
  prerelease: false
95
- requirement: &id006 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
96
89
  none: false
97
- requirements:
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rails
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
98
99
  - - ~>
99
- - !ruby/object:Gem::Version
100
- hash: 7
101
- segments:
102
- - 3
103
- - 0
104
- version: "3.0"
100
+ - !ruby/object:Gem::Version
101
+ version: '3.0'
105
102
  type: :development
106
- version_requirements: *id006
107
- - !ruby/object:Gem::Dependency
108
- name: webmock
109
103
  prerelease: false
110
- requirement: &id007 !ruby/object:Gem::Requirement
104
+ version_requirements: !ruby/object:Gem::Requirement
111
105
  none: false
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- hash: 3
116
- segments:
117
- - 0
118
- version: "0"
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '3.0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: webmock
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
119
118
  type: :development
120
- version_requirements: *id007
121
- description: "SimplePostmark makes it easy to send mails via Postmark\xE2\x84\xA2 using Rails 3's ActionMailer."
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: SimplePostmark makes it easy to send mails via Postmark™ using Rails
127
+ 3's ActionMailer.
122
128
  email: uher.mario@gmail.com
123
129
  executables: []
124
-
125
130
  extensions: []
126
-
127
131
  extra_rdoc_files: []
128
-
129
- files:
132
+ files:
130
133
  - .gitignore
131
134
  - .travis.yml
132
135
  - CHANGELOG.md
@@ -151,39 +154,28 @@ files:
151
154
  - spec/railtie_spec.rb
152
155
  - spec/spec_helper.rb
153
156
  - spec/thebrocode.jpg
154
- has_rdoc: true
155
157
  homepage: http://haihappen.github.com/simple_postmark
156
158
  licenses: []
157
-
158
159
  post_install_message:
159
160
  rdoc_options: []
160
-
161
- require_paths:
161
+ require_paths:
162
162
  - lib
163
- required_ruby_version: !ruby/object:Gem::Requirement
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
164
  none: false
165
- requirements:
166
- - - ">="
167
- - !ruby/object:Gem::Version
168
- hash: 3
169
- segments:
170
- - 0
171
- version: "0"
172
- required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
170
  none: false
174
- requirements:
175
- - - ">="
176
- - !ruby/object:Gem::Version
177
- hash: 3
178
- segments:
179
- - 0
180
- version: "0"
171
+ requirements:
172
+ - - ! '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
181
175
  requirements: []
182
-
183
176
  rubyforge_project:
184
- rubygems_version: 1.6.2
177
+ rubygems_version: 1.8.23
185
178
  signing_key:
186
179
  specification_version: 3
187
- summary: "A simple way to use Postmark\xE2\x84\xA2 with your Rails app."
180
+ summary: A simple way to use Postmark with your Rails app.
188
181
  test_files: []
189
-