postmark 0.9.12 → 0.9.13
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.rdoc +5 -0
- data/README.rdoc +17 -15
- data/VERSION +1 -1
- data/lib/postmark.rb +21 -16
- data/lib/postmark/http_client.rb +12 -3
- data/lib/postmark/version.rb +1 -1
- data/postmark.gemspec +0 -5
- data/spec/bounce_spec.rb +1 -1
- data/spec/postmark_spec.rb +11 -0
- data/spec/spec_helper.rb +0 -1
- metadata +69 -31
data/.gitignore
CHANGED
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -5,7 +5,7 @@ This gem is an official wrapper for Postmark HTTP API (http://postmarkapp.com).
|
|
5
5
|
== Install
|
6
6
|
|
7
7
|
gem install postmark
|
8
|
-
|
8
|
+
|
9
9
|
In addition to the +postmark+ gem you also need to install +tmail+ or +mail+ gem. Pick the one you like most:
|
10
10
|
|
11
11
|
gem install mail
|
@@ -19,23 +19,23 @@ In addition to the +postmark+ gem you also need to install +tmail+ or +mail+ gem
|
|
19
19
|
require 'tmail'
|
20
20
|
|
21
21
|
Postmark.api_key = "your-api-key"
|
22
|
-
|
22
|
+
|
23
23
|
# Make sure you have a sender signature for every From email you specify.
|
24
|
-
# From can also accept array of addresses.
|
25
|
-
|
24
|
+
# From can also accept array of addresses.
|
25
|
+
|
26
26
|
message = TMail::Mail.new
|
27
27
|
message.from = "leonard@bigbangtheory.com"
|
28
28
|
message.to = "Sheldon Cooper <sheldon@bigbangtheory.com>"
|
29
29
|
message.subject = "Hi Sheldon!"
|
30
30
|
message.content_type = "text/html"
|
31
31
|
message.body = "Hello my friend!"
|
32
|
-
|
32
|
+
|
33
33
|
# You can set customer headers if you like:
|
34
34
|
message["CUSTOM-HEADER"] = "my custom header value"
|
35
|
-
|
35
|
+
|
36
36
|
# Added a tag:
|
37
37
|
message.tag = "my-tracking-tag"
|
38
|
-
|
38
|
+
|
39
39
|
# Add attachments:
|
40
40
|
message.postmark_attachments = [File.open("/path"), File.open("/path")]
|
41
41
|
|
@@ -45,18 +45,18 @@ In addition to the +postmark+ gem you also need to install +tmail+ or +mail+ gem
|
|
45
45
|
"Content" => [pdf_content].pack("m"),
|
46
46
|
"ContentType" => "application/pdf"
|
47
47
|
}]
|
48
|
-
|
48
|
+
|
49
49
|
# Or specify a reply-to address (can also be an array of addresses):
|
50
50
|
message.reply_to = "penny@bigbangtheory.com"
|
51
51
|
|
52
52
|
Postmark.send_through_postmark(message)
|
53
|
-
|
53
|
+
|
54
54
|
== Mail Example
|
55
55
|
|
56
56
|
require 'rubygems'
|
57
57
|
require 'postmark'
|
58
58
|
require 'mail'
|
59
|
-
|
59
|
+
|
60
60
|
message = Mail.new
|
61
61
|
message.delivery_method(Mail::Postmark, :api_key => "your-api-key")
|
62
62
|
# ...
|
@@ -70,12 +70,12 @@ You can retrieve various information about your server state using the Public bo
|
|
70
70
|
|
71
71
|
# Get delivery stats: (JSON format)
|
72
72
|
Postmark.delivery_stats
|
73
|
-
|
74
|
-
# Get bounces information: (array of bounce objects)
|
73
|
+
|
74
|
+
# Get bounces information: (array of bounce objects)
|
75
75
|
Postmark::Bounce.all
|
76
|
-
|
77
|
-
# Find specific bounce by id:
|
78
|
-
bounce = Postmark::Bounce.find(bounce_id)
|
76
|
+
|
77
|
+
# Find specific bounce by id:
|
78
|
+
bounce = Postmark::Bounce.find(bounce_id)
|
79
79
|
bounce.dump # string, containing raw SMTP data
|
80
80
|
bounce.activate # reactivate hard bounce
|
81
81
|
|
@@ -118,6 +118,8 @@ You can also explicitly specify which one to be used, using
|
|
118
118
|
* Yury Batenko
|
119
119
|
* Pavel Maksimenko
|
120
120
|
* Anton Astashov
|
121
|
+
* Marcus Brito
|
122
|
+
* Tyler Hunt
|
121
123
|
|
122
124
|
== Copyright
|
123
125
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.13
|
data/lib/postmark.rb
CHANGED
@@ -1,27 +1,32 @@
|
|
1
|
-
def require_local(file)
|
2
|
-
require File.join(File.dirname(__FILE__), 'postmark', file)
|
3
|
-
end
|
4
|
-
|
5
1
|
require 'net/http'
|
6
2
|
require 'net/https'
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
require 'postmark/bounce'
|
5
|
+
require 'postmark/json'
|
6
|
+
require 'postmark/http_client'
|
7
|
+
require 'postmark/message_extensions/shared'
|
8
|
+
require 'postmark/message_extensions/tmail'
|
9
|
+
require 'postmark/message_extensions/mail'
|
10
|
+
require 'postmark/handlers/mail'
|
11
|
+
require 'postmark/attachments_fix_for_mail'
|
16
12
|
|
17
13
|
module Postmark
|
18
14
|
|
19
|
-
class DeliveryError
|
15
|
+
class DeliveryError < StandardError
|
16
|
+
attr_accessor :error_code
|
17
|
+
|
18
|
+
def initialize(message = nil, error_code = nil)
|
19
|
+
super(message)
|
20
|
+
self.error_code = error_code
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
20
24
|
class UnknownError < DeliveryError; end
|
21
25
|
class InvalidApiKeyError < DeliveryError; end
|
22
26
|
class InvalidMessageError < DeliveryError; end
|
23
27
|
class InternalServerError < DeliveryError; end
|
24
28
|
class UnknownMessageType < DeliveryError; end
|
29
|
+
class TimeoutError < DeliveryError; end
|
25
30
|
|
26
31
|
module ResponseParsers
|
27
32
|
autoload :Json, 'postmark/response_parsers/json'
|
@@ -34,8 +39,6 @@ module Postmark
|
|
34
39
|
'Accept' => 'application/json'
|
35
40
|
}
|
36
41
|
|
37
|
-
MAX_RETRIES = 2
|
38
|
-
|
39
42
|
extend self
|
40
43
|
|
41
44
|
attr_accessor :host, :path_prefix, :port, :secure, :api_key, :http_open_timeout, :http_read_timeout,
|
@@ -86,7 +89,7 @@ module Postmark
|
|
86
89
|
@retries = 0
|
87
90
|
begin
|
88
91
|
HttpClient.post("email", Postmark::Json.encode(convert_message_to_options_hash(message)))
|
89
|
-
rescue DeliveryError
|
92
|
+
rescue DeliveryError, Timeout::Error
|
90
93
|
if @retries < max_retries
|
91
94
|
@retries += 1
|
92
95
|
retry
|
@@ -94,6 +97,8 @@ module Postmark
|
|
94
97
|
raise
|
95
98
|
end
|
96
99
|
end
|
100
|
+
rescue Timeout::Error
|
101
|
+
raise TimeoutError.new($!)
|
97
102
|
end
|
98
103
|
|
99
104
|
def convert_message_to_options_hash(message)
|
data/lib/postmark/http_client.rb
CHANGED
@@ -35,11 +35,11 @@ module Postmark
|
|
35
35
|
when 200
|
36
36
|
return Postmark::Json.decode(response.body)
|
37
37
|
when 401
|
38
|
-
raise InvalidApiKeyError,
|
38
|
+
raise error(InvalidApiKeyError, response.body)
|
39
39
|
when 422
|
40
|
-
raise InvalidMessageError,
|
40
|
+
raise error(InvalidMessageError, response.body)
|
41
41
|
when 500
|
42
|
-
raise InternalServerError, response.body
|
42
|
+
raise error(InternalServerError, response.body)
|
43
43
|
else
|
44
44
|
raise UnknownError, response
|
45
45
|
end
|
@@ -72,5 +72,14 @@ module Postmark
|
|
72
72
|
def error_message(response_body)
|
73
73
|
Postmark::Json.decode(response_body)["Message"]
|
74
74
|
end
|
75
|
+
|
76
|
+
def error_message_and_code(response_body)
|
77
|
+
reply = Postmark::Json.decode(response_body)
|
78
|
+
[reply["Message"], reply["ErrorCode"]]
|
79
|
+
end
|
80
|
+
|
81
|
+
def error(clazz, response_body)
|
82
|
+
clazz.send(:new, *error_message_and_code(response_body))
|
83
|
+
end
|
75
84
|
end
|
76
85
|
end
|
data/lib/postmark/version.rb
CHANGED
data/postmark.gemspec
CHANGED
@@ -41,9 +41,4 @@ Gem::Specification.new do |s|
|
|
41
41
|
s.add_development_dependency "fakeweb-matcher"
|
42
42
|
s.add_development_dependency "timecop"
|
43
43
|
s.add_development_dependency "yajl-ruby"
|
44
|
-
if RUBY_VERSION < '1.9.0'
|
45
|
-
s.add_development_dependency(%q<ruby-debug>, [">= 0"])
|
46
|
-
else
|
47
|
-
s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
|
48
|
-
end
|
49
44
|
end
|
data/spec/bounce_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe "Bounce" do
|
|
18
18
|
|
19
19
|
it "should retrieve and parce bounce correctly" do
|
20
20
|
bounce.type.should == "HardBounce"
|
21
|
-
bounce.bounced_at.should == Time.now
|
21
|
+
bounce.bounced_at.to_s.should == Time.now.to_s
|
22
22
|
bounce.details.should == "test bounce"
|
23
23
|
bounce.email.should == "jim@test.com"
|
24
24
|
end
|
data/spec/postmark_spec.rb
CHANGED
@@ -96,6 +96,11 @@ describe Postmark do
|
|
96
96
|
lambda { Postmark.send_through_postmark(mail_message) }.should raise_error(Postmark::UnknownError)
|
97
97
|
end
|
98
98
|
|
99
|
+
it "should warn when the request times out" do
|
100
|
+
Postmark::HttpClient.should_receive(:post).at_least(:once).and_raise(Timeout::Error)
|
101
|
+
lambda { Postmark.send_through_postmark(mail_message) }.should raise_error(Postmark::TimeoutError)
|
102
|
+
end
|
103
|
+
|
99
104
|
it "should retry 3 times" do
|
100
105
|
FakeWeb.register_uri(:post, "http://api.postmarkapp.com/email",
|
101
106
|
[
|
@@ -105,6 +110,12 @@ describe Postmark do
|
|
105
110
|
])
|
106
111
|
lambda { Postmark.send_through_postmark(mail_message) }.should_not raise_error
|
107
112
|
end
|
113
|
+
|
114
|
+
it "should retry on timeout" do
|
115
|
+
Postmark::HttpClient.should_receive(:post).and_raise(Timeout::Error)
|
116
|
+
Postmark::HttpClient.should_receive(:post).and_return('{}')
|
117
|
+
lambda { Postmark.send_through_postmark(mail_message) }.should_not raise_error
|
118
|
+
end
|
108
119
|
end
|
109
120
|
|
110
121
|
context "delivery stats" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postmark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-01-31 00:00:00.
|
14
|
+
date: 2012-01-31 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rake
|
18
|
-
requirement:
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
@@ -23,10 +23,15 @@ dependencies:
|
|
23
23
|
version: '0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements:
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ! '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
27
32
|
- !ruby/object:Gem::Dependency
|
28
33
|
name: json
|
29
|
-
requirement:
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
30
35
|
none: false
|
31
36
|
requirements:
|
32
37
|
- - ! '>='
|
@@ -34,10 +39,15 @@ dependencies:
|
|
34
39
|
version: '0'
|
35
40
|
type: :runtime
|
36
41
|
prerelease: false
|
37
|
-
version_requirements:
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
38
48
|
- !ruby/object:Gem::Dependency
|
39
49
|
name: tmail
|
40
|
-
requirement:
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
41
51
|
none: false
|
42
52
|
requirements:
|
43
53
|
- - ! '>='
|
@@ -45,10 +55,15 @@ dependencies:
|
|
45
55
|
version: '0'
|
46
56
|
type: :development
|
47
57
|
prerelease: false
|
48
|
-
version_requirements:
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
49
64
|
- !ruby/object:Gem::Dependency
|
50
65
|
name: mail
|
51
|
-
requirement:
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
52
67
|
none: false
|
53
68
|
requirements:
|
54
69
|
- - ! '>='
|
@@ -56,10 +71,15 @@ dependencies:
|
|
56
71
|
version: '0'
|
57
72
|
type: :development
|
58
73
|
prerelease: false
|
59
|
-
version_requirements:
|
74
|
+
version_requirements: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
60
80
|
- !ruby/object:Gem::Dependency
|
61
81
|
name: rspec-core
|
62
|
-
requirement:
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
63
83
|
none: false
|
64
84
|
requirements:
|
65
85
|
- - ~>
|
@@ -67,10 +87,15 @@ dependencies:
|
|
67
87
|
version: '2.0'
|
68
88
|
type: :development
|
69
89
|
prerelease: false
|
70
|
-
version_requirements:
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ~>
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '2.0'
|
71
96
|
- !ruby/object:Gem::Dependency
|
72
97
|
name: activesupport
|
73
|
-
requirement:
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
74
99
|
none: false
|
75
100
|
requirements:
|
76
101
|
- - ~>
|
@@ -78,10 +103,15 @@ dependencies:
|
|
78
103
|
version: '3.0'
|
79
104
|
type: :development
|
80
105
|
prerelease: false
|
81
|
-
version_requirements:
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ~>
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '3.0'
|
82
112
|
- !ruby/object:Gem::Dependency
|
83
113
|
name: fakeweb
|
84
|
-
requirement:
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
85
115
|
none: false
|
86
116
|
requirements:
|
87
117
|
- - ! '>='
|
@@ -89,10 +119,15 @@ dependencies:
|
|
89
119
|
version: '0'
|
90
120
|
type: :development
|
91
121
|
prerelease: false
|
92
|
-
version_requirements:
|
122
|
+
version_requirements: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
93
128
|
- !ruby/object:Gem::Dependency
|
94
129
|
name: fakeweb-matcher
|
95
|
-
requirement:
|
130
|
+
requirement: !ruby/object:Gem::Requirement
|
96
131
|
none: false
|
97
132
|
requirements:
|
98
133
|
- - ! '>='
|
@@ -100,10 +135,15 @@ dependencies:
|
|
100
135
|
version: '0'
|
101
136
|
type: :development
|
102
137
|
prerelease: false
|
103
|
-
version_requirements:
|
138
|
+
version_requirements: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
104
144
|
- !ruby/object:Gem::Dependency
|
105
145
|
name: timecop
|
106
|
-
requirement:
|
146
|
+
requirement: !ruby/object:Gem::Requirement
|
107
147
|
none: false
|
108
148
|
requirements:
|
109
149
|
- - ! '>='
|
@@ -111,10 +151,15 @@ dependencies:
|
|
111
151
|
version: '0'
|
112
152
|
type: :development
|
113
153
|
prerelease: false
|
114
|
-
version_requirements:
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
none: false
|
156
|
+
requirements:
|
157
|
+
- - ! '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
115
160
|
- !ruby/object:Gem::Dependency
|
116
161
|
name: yajl-ruby
|
117
|
-
requirement:
|
162
|
+
requirement: !ruby/object:Gem::Requirement
|
118
163
|
none: false
|
119
164
|
requirements:
|
120
165
|
- - ! '>='
|
@@ -122,18 +167,12 @@ dependencies:
|
|
122
167
|
version: '0'
|
123
168
|
type: :development
|
124
169
|
prerelease: false
|
125
|
-
version_requirements:
|
126
|
-
- !ruby/object:Gem::Dependency
|
127
|
-
name: ruby-debug19
|
128
|
-
requirement: &70174637528420 !ruby/object:Gem::Requirement
|
170
|
+
version_requirements: !ruby/object:Gem::Requirement
|
129
171
|
none: false
|
130
172
|
requirements:
|
131
173
|
- - ! '>='
|
132
174
|
- !ruby/object:Gem::Version
|
133
175
|
version: '0'
|
134
|
-
type: :development
|
135
|
-
prerelease: false
|
136
|
-
version_requirements: *70174637528420
|
137
176
|
description: Use this gem to send emails through Postmark HTTP API and retrieve info
|
138
177
|
about bounces.
|
139
178
|
email: ilya@wildbit.com
|
@@ -143,7 +182,6 @@ extra_rdoc_files:
|
|
143
182
|
- LICENSE
|
144
183
|
- README.rdoc
|
145
184
|
files:
|
146
|
-
- .bundle/config
|
147
185
|
- .document
|
148
186
|
- .gitignore
|
149
187
|
- .rake_tasks
|
@@ -190,7 +228,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
228
|
version: '0'
|
191
229
|
segments:
|
192
230
|
- 0
|
193
|
-
hash:
|
231
|
+
hash: -3519863047660442665
|
194
232
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
233
|
none: false
|
196
234
|
requirements:
|
@@ -199,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
237
|
version: 1.3.7
|
200
238
|
requirements: []
|
201
239
|
rubyforge_project:
|
202
|
-
rubygems_version: 1.
|
240
|
+
rubygems_version: 1.8.24
|
203
241
|
signing_key:
|
204
242
|
specification_version: 3
|
205
243
|
summary: Official Postmark API wrapper.
|