simple_postmark 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .rbenv-vars
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.4.2 (April 28, 2012)
2
+
3
+ * SimplePostmark will now raise Postmark API errors if `ActionMailer::Base.raise_delivery_errors` is set.
data/README.md CHANGED
@@ -1,10 +1,8 @@
1
- # simple_postmark
1
+ # simple_postmark [![Build Status](https://secure.travis-ci.org/haihappen/simple_postmark.png)](http://travis-ci.org/haihappen/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
- [![Build Status](https://secure.travis-ci.org/haihappen/simple_postmark.png)](http://travis-ci.org/haihappen/simple_postmark)
7
-
8
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`).
9
7
 
10
8
  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).
@@ -54,15 +52,13 @@ class NotificationMailer < ActionMailer::Base
54
52
  end
55
53
  ```
56
54
 
57
- ## Contributing to simple_postmark
58
-
59
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
60
- * Check out the [issue tracker](https://github.com/haihappen/simple_postmark/issues) to make sure someone already hasn't requested it and/or contributed it
61
- * Fork the project
62
- * Start a feature/bugfix branch
63
- * Commit and push until you are happy with your contribution
64
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
65
- * 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.
55
+ ## Contributing
56
+
57
+ 1. Fork it
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
66
62
 
67
63
  ## Copyright
68
64
 
@@ -1,6 +1,7 @@
1
1
  source :rubygems
2
2
 
3
- gem 'activesupport', git: 'git://github.com/rails/rails.git'
3
+ gem 'activesupport', github: 'rails/rails'
4
+ gem 'active_record_deprecated_finders', github: 'rails/active_record_deprecated_finders'
4
5
  gem 'httparty'
5
6
  gem 'json'
6
7
  gem 'mail'
@@ -8,6 +9,6 @@ gem 'mail'
8
9
  group :development do
9
10
  gem 'minitest'
10
11
  gem 'purdytest'
11
- gem 'rails', git: 'git://github.com/rails/rails.git'
12
+ gem 'rails', github: 'rails/rails'
12
13
  gem 'webmock'
13
- end
14
+ end
@@ -9,6 +9,7 @@ module SimplePostmark
9
9
  require 'simple_postmark/mail_ext/part'
10
10
 
11
11
  require 'simple_postmark/delivery_method'
12
+ require 'simple_postmark/api_error'
12
13
 
13
14
  require 'simple_postmark/railtie' if defined?(Rails)
14
15
  end
@@ -0,0 +1,7 @@
1
+ module SimplePostmark
2
+ class APIError < StandardError
3
+ def initialize(response)
4
+ super(response.parsed_response['Message'])
5
+ end
6
+ end
7
+ end
@@ -13,7 +13,8 @@ module Mail
13
13
  def deliver!(mail)
14
14
  api_key = { 'X-Postmark-Server-Token' => settings[:api_key].to_s }
15
15
 
16
- self.class.post('/email', headers: self.class.headers.merge(api_key), body: mail.to_postmark.to_json)
16
+ response = self.class.post('/email', headers: self.class.headers.merge(api_key), body: mail.to_postmark.to_json)
17
+ raise ::SimplePostmark::APIError.new(response) unless response.success?
17
18
  end
18
19
  end
19
20
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'simple_postmark'
3
- gem.version = '0.4.1'
3
+ gem.version = '0.4.2'
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.'
@@ -5,7 +5,7 @@ describe Mail do
5
5
  let(:instance) { Mail::SimplePostmark.new({}) }
6
6
 
7
7
 
8
- it 'should respond to deliver!' do
8
+ it 'responds to deliver!' do
9
9
  instance.must_respond_to(:deliver!)
10
10
  end
11
11
 
@@ -23,22 +23,23 @@ describe Mail do
23
23
  end
24
24
  let(:url) { 'http://api.postmarkapp.com/email' }
25
25
 
26
+
26
27
  before do
27
28
  mail.delivery_method(Mail::SimplePostmark)
28
29
  stub_request(:post, url)
29
30
  end
30
31
 
31
32
 
32
- it 'should send emails' do
33
+ it 'sends emails' do
33
34
  mail.deliver
34
-
35
+
35
36
  assert_requested(:post, url)
36
37
  end
37
38
 
38
39
 
39
- it 'should post appropriate data' do
40
+ it 'sends appropriate headers' do
40
41
  mail.deliver
41
-
42
+
42
43
  assert_requested(:post, url, headers: { 'Accept' => 'application/json', 'ContentType' => 'application/json', 'X-Postmark-Server-Token' => '********-****-****-****-************' })
43
44
  end
44
45
  end
@@ -0,0 +1,67 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'action_mailer'
3
+ require 'rails'
4
+ require 'simple_postmark/railtie'
5
+
6
+ WebMock.allow_net_connect!
7
+
8
+ class IntegrationMailer < ActionMailer::Base
9
+ default to: ENV['SIMPLE_POSTMARK_TO'], from: ENV['SIMPLE_POSTMARK_FROM']
10
+
11
+ def text
12
+ 'Mail send via Postmark using SimplePostmark'
13
+ end
14
+
15
+ def email
16
+ mail(subject: 'SimplePostmark') do |as|
17
+ as.text { render(text: text) }
18
+ end
19
+ end
20
+
21
+ def email_with_tags
22
+ mail(subject: 'SimplePostmark with Tags', tag: 'simple-postmark') do |as|
23
+ as.text { render(text: text) }
24
+ end
25
+ end
26
+
27
+ def email_with_attachments
28
+ attachments['thebrocode.jpg'] = File.read(File.join(File.dirname(__FILE__), 'thebrocode.jpg'))
29
+
30
+ mail(subject: 'SimplePostmark with Attachments') do |as|
31
+ as.text { render(text: text) }
32
+ end
33
+ end
34
+
35
+ def email_with_reply_to
36
+ mail(subject: 'SimplePostmark with Reply To', reply_to: ENV['SIMPLE_POSTMARK_REPLY_TO']) do |as|
37
+ as.text { render(text: text) }
38
+ end
39
+ end
40
+ end
41
+
42
+ describe 'SimplePostmark integration' do
43
+ before do
44
+ ActionMailer::Base.simple_postmark_settings = { api_key: ENV['SIMPLE_POSTMARK_API_KEY'] }
45
+ ActionMailer::Base.raise_delivery_errors = true
46
+ end
47
+
48
+
49
+ it 'sends emails' do
50
+ IntegrationMailer.email.deliver
51
+ end
52
+
53
+
54
+ it 'sends emails with tags' do
55
+ IntegrationMailer.email_with_tags.deliver
56
+ end
57
+
58
+
59
+ it 'sends emails with attachments' do
60
+ IntegrationMailer.email_with_attachments.deliver
61
+ end
62
+
63
+
64
+ it 'sends emails with reply-to' do
65
+ IntegrationMailer.email_with_reply_to.deliver
66
+ end
67
+ end if ENV['SIMPLE_POSTMARK_INTEGRATION_SPEC']
@@ -1,12 +1,12 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe Mail::Message do
4
- it 'should respond to +to_postmark+' do
4
+ it 'responds to +to_postmark+' do
5
5
  Mail::Message.new.must_respond_to(:to_postmark)
6
6
  end
7
7
 
8
8
 
9
- it 'should respond to +to_postmark+' do
9
+ it 'responds to +to_postmark+' do
10
10
  Mail.new.must_respond_to(:to_postmark)
11
11
  end
12
12
 
@@ -23,7 +23,7 @@ describe Mail::Message do
23
23
  end
24
24
 
25
25
 
26
- it 'should return a hash' do
26
+ it 'returns a hash' do
27
27
  hash = {
28
28
  'From' => 'barney@himym.tld',
29
29
  'To' => 'ted@himym.tld',
@@ -42,14 +42,14 @@ describe Mail::Message do
42
42
  end
43
43
 
44
44
 
45
- it 'should return multiple recipients as comma-separated list' do
45
+ it 'returns multiple recipients as comma-separated list' do
46
46
  mail.to = ['barney@himym.tld', 'marshall@himym.tld']
47
47
 
48
48
  mail.to_postmark['To'].must_equal('barney@himym.tld, marshall@himym.tld')
49
49
  end
50
50
 
51
51
 
52
- it 'should return all email headers as hash' do
52
+ it 'returns all email headers as hash' do
53
53
  mail.bcc = 'lily@himym.tld'
54
54
  mail.cc = 'marshall@himym.tld'
55
55
  mail.reply_to = 'barney@barneystinsonblog.com'
@@ -1,13 +1,13 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe Mail::Part do
4
- it 'should respond to +to_postmark+' do
4
+ it 'responds to +to_postmark+' do
5
5
  Mail::Part.new.must_respond_to(:to_postmark)
6
6
  end
7
7
 
8
8
 
9
9
  describe :to_postmark do
10
- it 'should return body hash if part is not an attachment' do
10
+ it 'returns body hash if part is not an attachment' do
11
11
  part = Mail::Part.new do
12
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
13
  content_type 'text/plain'
@@ -19,7 +19,7 @@ describe Mail::Part do
19
19
  end
20
20
 
21
21
 
22
- it 'should return body hash if part is not an attachment' do
22
+ it 'returns body hash if part is not an attachment' do
23
23
  part = Mail::Part.new do
24
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
25
  content_type 'text/html'
@@ -31,13 +31,13 @@ describe Mail::Part do
31
31
  end
32
32
 
33
33
 
34
- it 'should return base64-encoded file-content hash if part is an attachment' do
34
+ it 'returns base64-encoded file-content hash if part is an attachment' do
35
35
  file = File.join(File.dirname(__FILE__), '..', 'thebrocode.jpg')
36
36
 
37
37
  part = Mail::Part.new.tap do |mail|
38
38
  mail.add_file(file)
39
39
  end.attachments.first
40
-
40
+
41
41
  content = [File.read(file)].pack('m')
42
42
 
43
43
  part.to_postmark.must_equal('Name' => 'thebrocode.jpg', 'Content' => content, 'ContentType' => 'image/jpeg')
data/spec/railtie_spec.rb CHANGED
@@ -53,17 +53,18 @@ describe ActionMailer::Base do
53
53
  }
54
54
  end
55
55
 
56
+
56
57
  before do
57
58
  stub_request(:post, url)
58
59
  end
59
60
 
60
61
 
61
- it 'should respond to +simple_postmark_settings+' do
62
+ it 'responds to +simple_postmark_settings+' do
62
63
  ActionMailer::Base.must_respond_to(:simple_postmark_settings)
63
64
  end
64
65
 
65
66
 
66
- it 'should allow setting an api key' do
67
+ it 'allows setting an api key' do
67
68
  ActionMailer::Base.simple_postmark_settings = { api_key: api_key }
68
69
 
69
70
  ActionMailer::Base.simple_postmark_settings[:api_key].must_equal(api_key)
@@ -76,21 +77,21 @@ describe ActionMailer::Base do
76
77
  end
77
78
 
78
79
 
79
- it 'should work' do
80
+ it 'works' do
80
81
  NotificationMailer.im_your_bro.deliver
81
82
 
82
83
  assert_requested(:post, url, headers: headers, body: merge_body)
83
84
  end
84
85
 
85
86
 
86
- it 'should allow tags' do
87
+ it 'allows tags' do
87
88
  NotificationMailer.im_your_bro_tagged.deliver
88
89
 
89
90
  assert_requested(:post, url, headers: headers, body: merge_body('Tag' => 'simple-postmark'))
90
91
  end
91
92
 
92
93
 
93
- it 'should work with attachments' do
94
+ it 'works with attachments' do
94
95
  attachment = {
95
96
  'Content' => [File.read(File.join(File.dirname(__FILE__), 'thebrocode.jpg'))].pack('m'),
96
97
  'ContentType' => 'image/jpeg',
@@ -103,7 +104,7 @@ describe ActionMailer::Base do
103
104
  end
104
105
 
105
106
 
106
- it 'should work with multipart messages' do
107
+ it 'works with multipart messages' do
107
108
  bodies = {
108
109
  'HtmlBody' => "<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>",
109
110
  '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!"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_postmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-06 00:00:00.000000000 Z
12
+ date: 2012-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70349875971380 !ruby/object:Gem::Requirement
16
+ requirement: &70104640539960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70349875971380
24
+ version_requirements: *70104640539960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &70349875970980 !ruby/object:Gem::Requirement
27
+ requirement: &70104640539460 !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: :runtime
34
34
  prerelease: false
35
- version_requirements: *70349875970980
35
+ version_requirements: *70104640539460
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: json
38
- requirement: &70349875970520 !ruby/object:Gem::Requirement
38
+ requirement: &70104640538860 !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: :runtime
45
45
  prerelease: false
46
- version_requirements: *70349875970520
46
+ version_requirements: *70104640538860
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: mail
49
- requirement: &70349875970100 !ruby/object:Gem::Requirement
49
+ requirement: &70104640538360 !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: :runtime
56
56
  prerelease: false
57
- version_requirements: *70349875970100
57
+ version_requirements: *70104640538360
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: minitest
60
- requirement: &70349876018780 !ruby/object:Gem::Requirement
60
+ requirement: &70104640537860 !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: *70349876018780
68
+ version_requirements: *70104640537860
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: purdytest
71
- requirement: &70349876018360 !ruby/object:Gem::Requirement
71
+ requirement: &70104640537320 !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: *70349876018360
79
+ version_requirements: *70104640537320
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rails
82
- requirement: &70349876017860 !ruby/object:Gem::Requirement
82
+ requirement: &70104640536700 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '3.0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70349876017860
90
+ version_requirements: *70104640536700
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: webmock
93
- requirement: &70349876017440 !ruby/object:Gem::Requirement
93
+ requirement: &70104640552580 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70349876017440
101
+ version_requirements: *70104640552580
102
102
  description: SimplePostmark makes it easy to send mails via Postmark™ using Rails
103
103
  3's ActionMailer.
104
104
  email: uher.mario@gmail.com
@@ -106,7 +106,9 @@ executables: []
106
106
  extensions: []
107
107
  extra_rdoc_files: []
108
108
  files:
109
+ - .gitignore
109
110
  - .travis.yml
111
+ - CHANGELOG.md
110
112
  - Gemfile
111
113
  - README.md
112
114
  - Rakefile
@@ -115,12 +117,14 @@ files:
115
117
  - gemfiles/Rails_3_2.gemfile
116
118
  - gemfiles/Rails_master.gemfile
117
119
  - lib/simple_postmark.rb
120
+ - lib/simple_postmark/api_error.rb
118
121
  - lib/simple_postmark/delivery_method.rb
119
122
  - lib/simple_postmark/mail_ext/message.rb
120
123
  - lib/simple_postmark/mail_ext/part.rb
121
124
  - lib/simple_postmark/railtie.rb
122
125
  - simple_postmark.gemspec
123
126
  - spec/delivery_method_spec.rb
127
+ - spec/integration_spec.rb
124
128
  - spec/mail_ext/message_spec.rb
125
129
  - spec/mail_ext/part_spec.rb
126
130
  - spec/railtie_spec.rb