postmark 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- data.tar.gz: cb99b9ac9a2d5bdf8e7821b7ba920c6ef5c130c9
4
- metadata.gz: 83c5dc42e240a0dd0b400560b5b5f9621ca79e47
3
+ metadata.gz: 923bce8373580308c169aa8e11f9f284366f03c6
4
+ data.tar.gz: da7597f415f0875cdc6f25f9466fd986b4e1893f
5
5
  SHA512:
6
- data.tar.gz: 562a81cdfc164088c052fb8a92293d7e4049381ea248ed8a4b9badc6075c77544d1a54e4113aea20a8a079bd647f0c90930f2c6778bfc4de9c8ccaee404fcdff
7
- metadata.gz: f7074eea782237a6419e729f37492b89e441647a2a6fe68014db990a683bda16f431f119aa90ac51eb0182efdbc0b4ed317e5f03a24bda04239c62077de076f2
6
+ metadata.gz: 2b883d6b1fd1e6afa8d80de6383b9756677fc9757a1ee14547bb193f9d1df27940d2d451ff534ffa83cc91cbd46fc37f1ab5f4abae25bc2256d7829dabd8f5a2
7
+ data.tar.gz: 7dbd50bc42683980f83befda6d7e91cc040676ed6ffe1e3ce4435e513cc192cf1621370c7d77c1ac04f2b5b31b97167b9fc30a76279f0e8142cdfa3292b76a35
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,10 @@
1
1
  = Changelog
2
2
 
3
+ == 1.4.0
4
+
5
+ * Add descriptive User-Agent string.
6
+ * Enable secure HTTP connections by default.
7
+
3
8
  == 1.3.1
4
9
 
5
10
  * Allow track_open header to be String for compatibility with older versions of the mail gem.
data/README.md CHANGED
@@ -42,13 +42,12 @@ client = Postmark::ApiClient.new(your_api_key)
42
42
  `Postmark::ApiClient` accepts various options:
43
43
 
44
44
  ``` ruby
45
- client = Postmark::ApiClient.new(your_api_key, secure: true
46
- http_open_timeout: 15)
45
+ client = Postmark::ApiClient.new(your_api_key, http_open_timeout: 15)
47
46
  ```
48
47
 
49
48
  Some useful options are:
50
49
 
51
- * `secure` (`true` or `false`): set to true to use SSL connection.
50
+ * `secure` (`true` or `false`): set to false to disable SSL connection.
52
51
  * `http_read_timeout` (positive number): limit HTTP read time to `n` seconds.
53
52
  * `http_open_timeout` (positive number): limit HTTP open time to `n` seconds.
54
53
  * `proxy_host` (string): proxy address to use.
@@ -317,7 +316,7 @@ a delivery method for the message:
317
316
  ``` ruby
318
317
  message = Mail.new do
319
318
  # ...
320
- delivery_method Mail::Postmark, api_key: 'your-postmark-api-key', secure: true
319
+ delivery_method Mail::Postmark, api_key: 'your-postmark-api-key'
321
320
  end
322
321
  ```
323
322
 
@@ -366,7 +365,7 @@ message = Mail.new do
366
365
  body '<p>Any group big enough to trample me to death. General ' \
367
366
  'rule of thumb is 36 adults or 70 children.</p>'
368
367
 
369
- track_opens "true" # Fee free to use true on mail >= 2.3.0
368
+ track_opens "true" # Feel free to use boolean values on mail >= 2.3.0
370
369
 
371
370
  delivery_method Mail::Postmark, :api_key => 'your-postmark-api-key'
372
371
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.1
1
+ 1.4.0
data/lib/postmark.rb CHANGED
@@ -2,6 +2,7 @@ require 'net/http'
2
2
  require 'net/https'
3
3
  require 'thread' unless defined? Mutex # For Ruby 1.8.7
4
4
 
5
+ require 'postmark/version'
5
6
  require 'postmark/inflector'
6
7
  require 'postmark/helpers/hash_helper'
7
8
  require 'postmark/helpers/message_helper'
@@ -42,6 +43,7 @@ module Postmark
42
43
  end
43
44
 
44
45
  HEADERS = {
46
+ 'User-Agent' => "Postmark Ruby Gem v#{VERSION}",
45
47
  'Content-type' => 'application/json',
46
48
  'Accept' => 'application/json'
47
49
  }
@@ -178,7 +178,7 @@ module Postmark
178
178
  def update_message(message, response)
179
179
  response ||= {}
180
180
  message['Message-ID'] = response['MessageID']
181
- message.delivered = !!response['MessageID']
181
+ message.delivered = response['ErrorCode'] && response['ErrorCode'].zero?
182
182
  message.postmark_response = response
183
183
  end
184
184
 
@@ -11,7 +11,7 @@ module Postmark
11
11
  DEFAULTS = {
12
12
  :auth_header_name => 'X-Postmark-Server-Token',
13
13
  :host => 'api.postmarkapp.com',
14
- :secure => false,
14
+ :secure => true,
15
15
  :path_prefix => '/',
16
16
  :http_read_timeout => 15,
17
17
  :http_open_timeout => 5
@@ -1,3 +1,3 @@
1
1
  module Postmark
2
- VERSION = "1.3.1"
2
+ VERSION = '1.4.0'
3
3
  end
@@ -42,6 +42,14 @@ describe "Sending Mail::Messages with Postmark::ApiClient" do
42
42
  let(:partially_valid_messages) { [message, message.dup, message_with_no_body] }
43
43
  let(:invalid_messages) { [message_with_no_body, message_with_no_body.dup] }
44
44
 
45
+ context 'invalid API code' do
46
+ it "doesn't deliver messages" do
47
+ expect {
48
+ Postmark::ApiClient.new('INVALID').deliver_message(message) rescue Postmark::InvalidApiKeyError
49
+ }.to change{message.delivered?}.to(false)
50
+ end
51
+ end
52
+
45
53
  context "message by message" do
46
54
  it 'delivers a plain text message' do
47
55
  api_client.deliver_message(message).should have_key(:message_id)
@@ -7,17 +7,6 @@ describe Postmark::HttpClient do
7
7
  end
8
8
 
9
9
  let(:api_key) { "provided-postmark-api-key" }
10
- let(:secure) { true }
11
- let(:proxy_host) { "providedproxyhostname.com" }
12
- let(:proxy_port) { 42 }
13
- let(:proxy_user) { "provided proxy user" }
14
- let(:proxy_pass) { "provided proxy pass" }
15
- let(:host) { "providedhostname.org" }
16
- let(:port) { 443 }
17
- let(:path_prefix) { "/provided/path/prefix" }
18
- let(:http_open_timeout) { 42 }
19
- let(:http_read_timeout) { 42 }
20
-
21
10
  let(:http_client) { Postmark::HttpClient.new(api_key) }
22
11
  subject { http_client }
23
12
 
@@ -43,14 +32,25 @@ describe Postmark::HttpClient do
43
32
  context "when it is created without options" do
44
33
  its(:api_key) { should eq api_key }
45
34
  its(:host) { should eq 'api.postmarkapp.com' }
46
- its(:port) { should eq 80 }
47
- its(:secure) { should be_false }
35
+ its(:port) { should eq 443 }
36
+ its(:secure) { should be_true }
48
37
  its(:path_prefix) { should eq '/' }
49
38
  its(:http_read_timeout) { should eq 15 }
50
39
  its(:http_open_timeout) { should eq 5 }
51
40
  end
52
41
 
53
42
  context "when it is created with options" do
43
+ let(:secure) { true }
44
+ let(:proxy_host) { "providedproxyhostname.com" }
45
+ let(:proxy_port) { 42 }
46
+ let(:proxy_user) { "provided proxy user" }
47
+ let(:proxy_pass) { "provided proxy pass" }
48
+ let(:host) { "providedhostname.org" }
49
+ let(:port) { 443 }
50
+ let(:path_prefix) { "/provided/path/prefix" }
51
+ let(:http_open_timeout) { 42 }
52
+ let(:http_read_timeout) { 42 }
53
+
54
54
  subject { Postmark::HttpClient.new(api_key,
55
55
  :secure => secure,
56
56
  :proxy_host => proxy_host,
@@ -78,7 +78,7 @@ describe Postmark::HttpClient do
78
78
 
79
79
  describe "#post" do
80
80
  let(:target_path) { "path/on/server" }
81
- let(:target_url) { "http://api.postmarkapp.com/#{target_path}" }
81
+ let(:target_url) { "https://api.postmarkapp.com/#{target_path}" }
82
82
 
83
83
  it "sends a POST request to provided URI" do
84
84
  FakeWeb.register_uri(:post, target_url, :body => response_body(200))
@@ -120,7 +120,7 @@ describe Postmark::HttpClient do
120
120
 
121
121
  describe "#get" do
122
122
  let(:target_path) { "path/on/server" }
123
- let(:target_url) { "http://api.postmarkapp.com/#{target_path}" }
123
+ let(:target_url) { "https://api.postmarkapp.com/#{target_path}" }
124
124
 
125
125
  it "sends a GET request to provided URI" do
126
126
  FakeWeb.register_uri(:get, target_url, :body => response_body(200))
@@ -136,25 +136,24 @@ describe Postmark::HttpClient do
136
136
 
137
137
  it "raises a custom error when sent JSON was not valid" do
138
138
  FakeWeb.register_uri(:get, target_url, :body => response_body(422),
139
- :status => [ "422", "Invalid" ])
139
+ :status => [ "422", "Invalid" ])
140
140
  expect { subject.get(target_path) }.to raise_error Postmark::InvalidMessageError
141
141
  end
142
142
 
143
143
  it "raises a custom error when server fails to process the request" do
144
144
  FakeWeb.register_uri(:get, target_url, :body => response_body(500),
145
- :status => [ "500", "Internal Server Error" ])
145
+ :status => [ "500", "Internal Server Error" ])
146
146
  expect { subject.get(target_path) }.to raise_error Postmark::InternalServerError
147
147
  end
148
148
 
149
149
  it "raises a custom error when the request times out" do
150
- subject.http.should_receive(:get).at_least(:once).
151
- and_raise(Timeout::Error)
150
+ subject.http.should_receive(:get).at_least(:once).and_raise(Timeout::Error)
152
151
  expect { subject.get(target_path) }.to raise_error Postmark::TimeoutError
153
152
  end
154
153
 
155
154
  it "raises a default error when unknown issue occurs" do
156
155
  FakeWeb.register_uri(:get, target_url, :body => response_body(485),
157
- :status => [ "485", "Custom HTTP response status" ])
156
+ :status => [ "485", "Custom HTTP response status" ])
158
157
  expect { subject.get(target_path) }.to raise_error Postmark::UnknownError
159
158
  end
160
159
 
@@ -162,7 +161,7 @@ describe Postmark::HttpClient do
162
161
 
163
162
  describe "#put" do
164
163
  let(:target_path) { "path/on/server" }
165
- let(:target_url) { "http://api.postmarkapp.com/#{target_path}" }
164
+ let(:target_url) { "https://api.postmarkapp.com/#{target_path}" }
166
165
 
167
166
  it "sends a PUT request to provided URI" do
168
167
  FakeWeb.register_uri(:put, target_url, :body => response_body(200))
@@ -172,31 +171,30 @@ describe Postmark::HttpClient do
172
171
 
173
172
  it "raises a custom error when API key authorization fails" do
174
173
  FakeWeb.register_uri(:put, target_url, :body => response_body(401),
175
- :status => [ "401", "Unauthorized" ])
174
+ :status => [ "401", "Unauthorized" ])
176
175
  expect { subject.put(target_path) }.to raise_error Postmark::InvalidApiKeyError
177
176
  end
178
177
 
179
178
  it "raises a custom error when sent JSON was not valid" do
180
179
  FakeWeb.register_uri(:put, target_url, :body => response_body(422),
181
- :status => [ "422", "Invalid" ])
180
+ :status => [ "422", "Invalid" ])
182
181
  expect { subject.put(target_path) }.to raise_error Postmark::InvalidMessageError
183
182
  end
184
183
 
185
184
  it "raises a custom error when server fails to process the request" do
186
185
  FakeWeb.register_uri(:put, target_url, :body => response_body(500),
187
- :status => [ "500", "Internal Server Error" ])
186
+ :status => [ "500", "Internal Server Error" ])
188
187
  expect { subject.put(target_path) }.to raise_error Postmark::InternalServerError
189
188
  end
190
189
 
191
190
  it "raises a custom error when the request times out" do
192
- subject.http.should_receive(:put).at_least(:once).
193
- and_raise(Timeout::Error)
191
+ subject.http.should_receive(:put).at_least(:once).and_raise(Timeout::Error)
194
192
  expect { subject.put(target_path) }.to raise_error Postmark::TimeoutError
195
193
  end
196
194
 
197
195
  it "raises a default error when unknown issue occurs" do
198
196
  FakeWeb.register_uri(:put, target_url, :body => response_body(485),
199
- :status => [ "485", "Custom HTTP response status" ])
197
+ :status => [ "485", "Custom HTTP response status" ])
200
198
  expect { subject.put(target_path) }.to raise_error Postmark::UnknownError
201
199
  end
202
200
 
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: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petyo Ivanov
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2014-06-05 00:00:00 Z
14
+ date: 2014-12-02 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake