postmark 1.21.4 → 1.21.8

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
  SHA256:
3
- metadata.gz: 27b284da8c78da623e294bfea463e876cf18e370d395b681548af71a0071afe8
4
- data.tar.gz: f12aba5cb688c265455578d011d6f917d405dac949003d2286fec6949c79367d
3
+ metadata.gz: bd56ea1117c73ce9a8f60d4dc81dd29f3b409efe1f362a534cb6a9b16a67dc60
4
+ data.tar.gz: 245374f9fb1752254c9c32aeff3ee0139b4b5bce4d252ce40c4f9d2627db42f7
5
5
  SHA512:
6
- metadata.gz: d8881a25fa5bec51bdb8b2db632f3a5a3d1aa1457dd13df1d6e274758b8c4da992cc74ad2b512e4dc771a23c3fafba197bc5c9a979302032114fc5486f49a98d
7
- data.tar.gz: e9be7104643c2b9e9ec7fff821af17675afccb51dfe717e72cd1975e6cdf713f322302a18e3df16943e53976e11bb0d80adb5e685faaeff98ff9ec4d1dafaa2c
6
+ metadata.gz: 17ad62b39034c58dfa35b9aeb296d609b35d786ae1c752abe07df6be4bf7743ecac1a9d83675e1ed860f7e01354bdc9761ccf742fbfe60c5bdd4016fbb831d9b
7
+ data.tar.gz: a3a0792f2525acc786627d7f16b0faa453b9608397a88d270a2bdcf61da3a00549a6bfb0eb92096f1015825fe4813fa5d62c1ba5b591bc675761c65fa2f38fac
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ postmark-gem
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.6
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,21 @@
1
1
  = Changelog
2
2
 
3
+ == 1.21.8
4
+
5
+ * Fixed passing and receiving SubscriptionManagementConfiguration when creating/updating message streams (#94).
6
+
7
+ == 1.21.7
8
+
9
+ * Improved parsing recipients with Postmark::InactiveRecipientError.parse_recipients method
10
+
11
+ == 1.21.6
12
+
13
+ * Improved error handling for email sending related to invalid email addresses
14
+
15
+ == 1.21.5
16
+
17
+ * Added support for archiving/unarchiving message streams
18
+
3
19
  == 1.21.4
4
20
 
5
21
  * Fixed Postmark::ApiClient#deliver_messages_with_templates (#104)
data/RELEASE.md CHANGED
@@ -1,5 +1,6 @@
1
1
  New versions of the gem are cut by the Postmark team, this is a quick guide to ensuring a smooth release.
2
2
 
3
+ 1. Determine the next version of the gem by following the [SemVer](https://semver.org/) guidelines.
3
4
  1. Verify all builds are passing on CircleCI for your branch.
4
5
  1. Merge in your branch to master.
5
6
  1. Update VERSION and lib/postmark/version.rb with the new version.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.21.4
1
+ 1.21.8
@@ -38,7 +38,7 @@ module Postmark
38
38
  response, error = take_response_of { http_client.post("email", data) }
39
39
  update_message(message, response)
40
40
  raise error if error
41
- format_response(response, true)
41
+ format_response(response, :compatible => true)
42
42
  end
43
43
  end
44
44
 
@@ -51,7 +51,7 @@ module Postmark
51
51
  response, error = take_response_of { http_client.post("email/withTemplate", data) }
52
52
  update_message(message, response)
53
53
  raise error if error
54
- format_response(response, true)
54
+ format_response(response, :compatible => true)
55
55
  end
56
56
  end
57
57
 
@@ -95,7 +95,7 @@ module Postmark
95
95
  end
96
96
 
97
97
  def delivery_stats
98
- response = format_response(http_client.get("deliverystats"), true)
98
+ response = format_response(http_client.get("deliverystats"), :compatible => true)
99
99
 
100
100
  if response[:bounces]
101
101
  response[:bounces] = format_response(response[:bounces])
@@ -343,13 +343,21 @@ module Postmark
343
343
  end
344
344
 
345
345
  def create_message_stream(attributes = {})
346
- data = serialize(HashHelper.to_postmark(attributes))
347
- format_response(http_client.post('message-streams', data))
346
+ data = serialize(HashHelper.to_postmark(attributes, :deep => true))
347
+ format_response(http_client.post('message-streams', data), :deep => true)
348
348
  end
349
349
 
350
350
  def update_message_stream(id, attributes)
351
- data = serialize(HashHelper.to_postmark(attributes))
352
- format_response(http_client.patch("message-streams/#{id}", data))
351
+ data = serialize(HashHelper.to_postmark(attributes, :deep => true))
352
+ format_response(http_client.patch("message-streams/#{id}", data), :deep => true)
353
+ end
354
+
355
+ def archive_message_stream(id)
356
+ format_response http_client.post("message-streams/#{id}/archive")
357
+ end
358
+
359
+ def unarchive_message_stream(id)
360
+ format_response http_client.post("message-streams/#{id}/unarchive")
353
361
  end
354
362
 
355
363
  def dump_suppressions(stream_id, options = {})
@@ -60,13 +60,16 @@ module Postmark
60
60
  [e.full_response || {}, e]
61
61
  end
62
62
 
63
- def format_response(response, compatible = false)
63
+ def format_response(response, options = {})
64
64
  return {} unless response
65
65
 
66
+ compatible = options.fetch(:compatible, false)
67
+ deep = options.fetch(:deep, false)
68
+
66
69
  if response.kind_of? Array
67
- response.map { |entry| Postmark::HashHelper.to_ruby(entry, compatible) }
70
+ response.map { |entry| Postmark::HashHelper.to_ruby(entry, :compatible => compatible, :deep => deep) }
68
71
  else
69
- Postmark::HashHelper.to_ruby(response, compatible)
72
+ Postmark::HashHelper.to_ruby(response, :compatible => compatible, :deep => deep)
70
73
  end
71
74
  end
72
75
 
@@ -30,9 +30,8 @@ module Postmark
30
30
  def initialize(status_code = 500, body = '', parsed_body = {})
31
31
  self.parsed_body = parsed_body
32
32
  self.status_code = status_code.to_i
33
- message = parsed_body.fetch(
34
- 'Message',
35
- "The Postmark API responded with HTTP status #{status_code}.")
33
+ self.body = body
34
+ message = parsed_body.fetch('Message', "The Postmark API responded with HTTP status #{status_code}.")
36
35
 
37
36
  super(message)
38
37
  end
@@ -44,6 +43,7 @@ module Postmark
44
43
 
45
44
  class ApiInputError < HttpServerError
46
45
  INACTIVE_RECIPIENT = 406
46
+ INVALID_EMAIL_ADDRESS = 300
47
47
 
48
48
  attr_accessor :error_code
49
49
 
@@ -52,7 +52,9 @@ module Postmark
52
52
 
53
53
  case error_code
54
54
  when INACTIVE_RECIPIENT
55
- InactiveRecipientError.new(INACTIVE_RECIPIENT, body, parsed_body)
55
+ InactiveRecipientError.new(error_code, body, parsed_body)
56
+ when INVALID_EMAIL_ADDRESS
57
+ InvalidEmailAddressError.new(error_code, body, parsed_body)
56
58
  else
57
59
  new(error_code, body, parsed_body)
58
60
  end
@@ -68,12 +70,14 @@ module Postmark
68
70
  end
69
71
  end
70
72
 
73
+ class InvalidEmailAddressError < ApiInputError; end
74
+
71
75
  class InactiveRecipientError < ApiInputError
72
76
  attr_reader :recipients
73
77
 
74
78
  PATTERNS = [/^Found inactive addresses: (.+?)\.$/.freeze,
75
- /^Found inactive addresses: (.+?)\.$/.freeze,
76
- /these inactive addresses: (.+?)\. Inactive/.freeze].freeze
79
+ /these inactive addresses: (.+?)\. Inactive/.freeze,
80
+ /these inactive addresses: (.+?)\.?$/].freeze
77
81
 
78
82
  def self.parse_recipients(message)
79
83
  PATTERNS.each do |p|
@@ -3,22 +3,47 @@ module Postmark
3
3
 
4
4
  extend self
5
5
 
6
- def to_postmark(hash)
7
- hash.inject({}) { |m, (k,v)| m[Inflector.to_postmark(k)] = v; m }
6
+ def to_postmark(object, options = {})
7
+ deep = options.fetch(:deep, false)
8
+
9
+ case object
10
+ when Hash
11
+ object.reduce({}) do |m, (k, v)|
12
+ m.tap do |h|
13
+ h[Inflector.to_postmark(k)] = deep ? to_postmark(v, options) : v
14
+ end
15
+ end
16
+ when Array
17
+ deep ? object.map { |v| to_postmark(v, options) } : object
18
+ else
19
+ object
20
+ end
8
21
  end
9
22
 
10
- def to_ruby(hash, compatible = false)
11
- formatted = hash.inject({}) { |m, (k,v)| m[Inflector.to_ruby(k)] = v; m }
12
-
13
- if compatible
14
- formatted.merge!(hash)
15
- enhance_with_compatibility_warning(formatted)
23
+ def to_ruby(object, options = {})
24
+ compatible = options.fetch(:compatible, false)
25
+ deep = options.fetch(:deep, false)
26
+
27
+ case object
28
+ when Hash
29
+ object.reduce({}) do |m, (k, v)|
30
+ m.tap do |h|
31
+ h[Inflector.to_ruby(k)] = deep ? to_ruby(v, options) : v
32
+ end
33
+ end.tap do |result|
34
+ if compatible
35
+ result.merge!(object)
36
+ enhance_with_compatibility_warning(result)
37
+ end
38
+ end
39
+ when Array
40
+ deep ? object.map { |v| to_ruby(v, options) } : object
41
+ else
42
+ object
16
43
  end
17
-
18
- formatted
19
44
  end
20
45
 
21
- protected
46
+ private
22
47
 
23
48
  def enhance_with_compatibility_warning(hash)
24
49
  def hash.[](key)
@@ -1,3 +1,3 @@
1
1
  module Postmark
2
- VERSION = '1.21.4'
2
+ VERSION = '1.21.8'
3
3
  end
data/postmark.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.license = 'MIT'
11
11
 
12
- s.authors = ["Petyo Ivanov", "Ilya Sabanin", "Artem Chistyakov"]
13
- s.email = "ilya@wildbit.com"
12
+ s.authors = ["Tomek Maszkowski", "Igor Balos", "Artem Chistyakov", "Nick Hammond", "Petyo Ivanov", "Ilya Sabanin"]
13
+ s.email = "tomek@wildbit.com"
14
14
  s.extra_rdoc_files = ["LICENSE", "README.md"]
15
15
  s.rdoc_options = ["--charset=UTF-8"]
16
16
 
@@ -606,10 +606,14 @@ describe Postmark::ApiClient do
606
606
  end
607
607
 
608
608
  describe "#server_info" do
609
- let(:response) {{"Name" => "Testing",
610
- "Color" => "blue",
611
- "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
612
- "SmtpApiActivated" => true}}
609
+ let(:response) {
610
+ {
611
+ "Name" => "Testing",
612
+ "Color" => "blue",
613
+ "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
614
+ "SmtpApiActivated" => true
615
+ }
616
+ }
613
617
 
614
618
  it 'requests server info from Postmark and converts it to ruby format' do
615
619
  expect(http_client).to receive(:get).with('server') {response}
@@ -618,10 +622,14 @@ describe Postmark::ApiClient do
618
622
  end
619
623
 
620
624
  describe "#update_server_info" do
621
- let(:response) {{"Name" => "Testing",
622
- "Color" => "blue",
623
- "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
624
- "SmtpApiActivated" => false}}
625
+ let(:response) {
626
+ {
627
+ "Name" => "Testing",
628
+ "Color" => "blue",
629
+ "InboundHash" => "c2425d77f74f8643e5f6237438086c81",
630
+ "SmtpApiActivated" => false
631
+ }
632
+ }
625
633
  let(:update) {{:smtp_api_activated => false}}
626
634
 
627
635
  it 'updates server info in Postmark and converts it to ruby format' do
@@ -1065,7 +1073,10 @@ describe Postmark::ApiClient do
1065
1073
  {
1066
1074
  :name => 'My Stream',
1067
1075
  :id => 'my-stream',
1068
- :message_stream_type => 'Broadcasts'
1076
+ :message_stream_type => 'Broadcasts',
1077
+ :subscription_management_configuration => {
1078
+ :unsubscribe_handling_type => 'Custom'
1079
+ }
1069
1080
  }
1070
1081
  end
1071
1082
 
@@ -1075,7 +1086,10 @@ describe Postmark::ApiClient do
1075
1086
  'Id' => 'my-stream',
1076
1087
  'MessageStreamType' => 'Broadcasts',
1077
1088
  'ServerId' => 222,
1078
- 'CreatedAt' => '2020-04-01T03:33:33.333-03:00'
1089
+ 'CreatedAt' => '2020-04-01T03:33:33.333-03:00',
1090
+ 'SubscriptionManagementConfiguration' => {
1091
+ 'UnsubscribeHandlingType' => 'Custom'
1092
+ }
1079
1093
  }
1080
1094
  end
1081
1095
 
@@ -1089,7 +1103,10 @@ describe Postmark::ApiClient do
1089
1103
  json_representation_of({
1090
1104
  'Name' => 'My Stream',
1091
1105
  'Id' => 'my-stream',
1092
- 'MessageStreamType' => 'Broadcasts'
1106
+ 'MessageStreamType' => 'Broadcasts',
1107
+ 'SubscriptionManagementConfiguration' => {
1108
+ 'UnsubscribeHandlingType' => 'Custom'
1109
+ }
1093
1110
  }))
1094
1111
  subject
1095
1112
  end
@@ -1100,7 +1117,10 @@ describe Postmark::ApiClient do
1100
1117
  :name => 'My Stream',
1101
1118
  :server_id => 222,
1102
1119
  :message_stream_type => 'Broadcasts',
1103
- :created_at => '2020-04-01T03:33:33.333-03:00'
1120
+ :created_at => '2020-04-01T03:33:33.333-03:00',
1121
+ :subscription_management_configuration => {
1122
+ :unsubscribe_handling_type => 'Custom'
1123
+ }
1104
1124
  )
1105
1125
  }
1106
1126
  end
@@ -1110,7 +1130,10 @@ describe Postmark::ApiClient do
1110
1130
 
1111
1131
  let(:attrs) do
1112
1132
  {
1113
- :name => 'My Stream XXX'
1133
+ :name => 'My Stream XXX',
1134
+ :subscription_management_configuration => {
1135
+ :unsubscribe_handling_type => 'Custom'
1136
+ }
1114
1137
  }
1115
1138
  end
1116
1139
 
@@ -1120,7 +1143,10 @@ describe Postmark::ApiClient do
1120
1143
  'Id' => 'xxx',
1121
1144
  'MessageStreamType' => 'Broadcasts',
1122
1145
  'ServerId' => 222,
1123
- 'CreatedAt' => '2020-04-01T03:33:33.333-03:00'
1146
+ 'CreatedAt' => '2020-04-01T03:33:33.333-03:00',
1147
+ 'SubscriptionManagementConfiguration' => {
1148
+ 'UnsubscribeHandlingType' => 'Custom'
1149
+ }
1124
1150
  }
1125
1151
  end
1126
1152
 
@@ -1132,7 +1158,10 @@ describe Postmark::ApiClient do
1132
1158
  expect(http_client).to receive(:patch).
1133
1159
  with('message-streams/xxx',
1134
1160
  match_json({
1135
- :Name => 'My Stream XXX',
1161
+ 'Name' => 'My Stream XXX',
1162
+ 'SubscriptionManagementConfiguration' => {
1163
+ 'UnsubscribeHandlingType' => 'Custom'
1164
+ }
1136
1165
  }))
1137
1166
  subject
1138
1167
  end
@@ -1143,11 +1172,70 @@ describe Postmark::ApiClient do
1143
1172
  :name => 'My Stream XXX',
1144
1173
  :server_id => 222,
1145
1174
  :message_stream_type => 'Broadcasts',
1146
- :created_at => '2020-04-01T03:33:33.333-03:00'
1175
+ :created_at => '2020-04-01T03:33:33.333-03:00',
1176
+ :subscription_management_configuration => {
1177
+ :unsubscribe_handling_type => 'Custom'
1178
+ }
1147
1179
  )
1148
1180
  }
1149
1181
  end
1150
1182
 
1183
+ describe '#archive_message_stream' do
1184
+ subject { api_client.archive_message_stream(stream_id) }
1185
+
1186
+ let(:stream_id) { 'my-stream'}
1187
+ let(:server_id) { 123 }
1188
+ let(:purge_date) { '2030-08-30T12:30:00.00-04:00' }
1189
+ let(:api_endpoint) { "message-streams/#{stream_id}/archive" }
1190
+ let(:api_response) {{ 'ID' => stream_id, 'ServerID' => server_id, 'ExpectedPurgeDate' => purge_date }}
1191
+
1192
+ before do
1193
+ allow(http_client).to receive(:post).with(api_endpoint) { api_response }
1194
+ end
1195
+
1196
+ it 'calls the API endpoint' do
1197
+ expect(http_client).to receive(:post).with(api_endpoint)
1198
+ subject
1199
+ end
1200
+
1201
+ it 'transforms the API response' do
1202
+ expect(subject).to eq({ :id => stream_id, :server_id => server_id, :expected_purge_date => purge_date })
1203
+ end
1204
+ end
1205
+
1206
+ describe '#unarchive_message_stream' do
1207
+ subject { api_client.unarchive_message_stream(stream_id) }
1208
+
1209
+ let(:stream_id) { 'my-stream'}
1210
+ let(:server_id) { 123 }
1211
+ let(:api_endpoint) { "message-streams/#{stream_id}/unarchive" }
1212
+ let(:api_response) {
1213
+ { 'ID' => stream_id, 'ServerID' => server_id, 'Name' => 'My Stream',
1214
+ 'Description' => 'My test stream.', 'MessageStreamType' => 'Transactional',
1215
+ 'CreatedAt' => '2030-08-30T12:30:00.00-04:00', 'UpdatedAt' => '2030-09-30T12:30:00.00-04:00',
1216
+ 'ArchivedAt'=> nil, 'ExpectedPurgeDate' => nil,
1217
+ 'SubscriptionManagementConfiguration' => { 'UnsubscribeHandlingType' => 'None' } }
1218
+ }
1219
+
1220
+ before do
1221
+ allow(http_client).to receive(:post).with(api_endpoint) { api_response }
1222
+ end
1223
+
1224
+ it 'calls the API endpoint' do
1225
+ expect(http_client).to receive(:post).with(api_endpoint)
1226
+ subject
1227
+ end
1228
+
1229
+ it 'transforms the API response' do
1230
+ expect(subject).to eq({ :id => stream_id, :server_id => server_id, :name => 'My Stream',
1231
+ :description => 'My test stream.', :message_stream_type => 'Transactional',
1232
+ :created_at => '2030-08-30T12:30:00.00-04:00',
1233
+ :updated_at => '2030-09-30T12:30:00.00-04:00',
1234
+ :archived_at => nil , :expected_purge_date => nil ,
1235
+ :subscription_management_configuration => { 'UnsubscribeHandlingType' => 'None' }})
1236
+ end
1237
+ end
1238
+
1151
1239
  describe '#create_suppressions' do
1152
1240
  let(:email_addresses) { nil }
1153
1241
  let(:message_stream_id) { 'outbound' }
@@ -97,6 +97,13 @@ describe(Postmark::ApiInputError) do
97
97
  it_behaves_like 'api input error'
98
98
  end
99
99
 
100
+ context '300' do
101
+ let(:code) {Postmark::ApiInputError::INVALID_EMAIL_ADDRESS}
102
+
103
+ it {is_expected.to be_a(Postmark::InvalidEmailAddressError)}
104
+ it_behaves_like 'api input error'
105
+ end
106
+
100
107
  context 'others' do
101
108
  let(:code) {'9999'}
102
109
 
@@ -142,6 +149,33 @@ describe(Postmark::MailAdapterError) do
142
149
  it {is_expected.to be_a(Postmark::Error)}
143
150
  end
144
151
 
152
+ describe(Postmark::InvalidEmailAddressError) do
153
+ describe '.new' do
154
+ let(:response) {{'Message' => message}}
155
+
156
+ subject do
157
+ Postmark::InvalidEmailAddressError.new(
158
+ Postmark::ApiInputError::INVALID_EMAIL_ADDRESS, Postmark::Json.encode(response), response)
159
+ end
160
+
161
+ let(:message) do
162
+ "Error parsing 'To': Illegal email address 'johne.xample.com'. It must contain the '@' symbol."
163
+ end
164
+
165
+ it 'body is set' do
166
+ expect(subject.body).to eq(Postmark::Json.encode(response))
167
+ end
168
+
169
+ it 'parsed body is set' do
170
+ expect(subject.parsed_body).to eq(response)
171
+ end
172
+
173
+ it 'error code is set' do
174
+ expect(subject.error_code).to eq(Postmark::ApiInputError::INVALID_EMAIL_ADDRESS)
175
+ end
176
+ end
177
+ end
178
+
145
179
  describe(Postmark::InactiveRecipientError) do
146
180
  describe '.parse_recipients' do
147
181
  let(:recipients) do
@@ -161,6 +195,12 @@ describe(Postmark::InactiveRecipientError) do
161
195
  it {is_expected.to eq(recipients.take(1))}
162
196
  end
163
197
 
198
+ context 'i/n inactive, n > 1, i < n - new message format' do
199
+ let(:message) { "Message OK, but will not deliver to these inactive addresses: #{recipients[0...2].join(', ')}" }
200
+
201
+ it {is_expected.to eq(recipients.take(2))}
202
+ end
203
+
164
204
  context 'i/n inactive, n > 1, i < n' do
165
205
  let(:message) do
166
206
  'Message OK, but will not deliver to these inactive addresses: ' \
@@ -209,6 +249,18 @@ describe(Postmark::InactiveRecipientError) do
209
249
  it 'parses recipients from json payload' do
210
250
  expect(subject.recipients).to eq([address])
211
251
  end
252
+
253
+ it 'body is set' do
254
+ expect(subject.body).to eq(Postmark::Json.encode(response))
255
+ end
256
+
257
+ it 'parsed body is set' do
258
+ expect(subject.parsed_body).to eq(response)
259
+ end
260
+
261
+ it 'error code is set' do
262
+ expect(subject.error_code).to eq(Postmark::ApiInputError::INACTIVE_RECIPIENT)
263
+ end
212
264
  end
213
265
  end
214
266
 
@@ -2,32 +2,119 @@ require 'spec_helper'
2
2
 
3
3
  describe Postmark::HashHelper do
4
4
  describe ".to_postmark" do
5
- let(:source) { {:from => "support@postmarkapp.com", :reply_to => "contact@wildbit.com"} }
6
- let(:target) { {"From" => "support@postmarkapp.com", "ReplyTo" => "contact@wildbit.com"} }
5
+ let(:source) do
6
+ {
7
+ :level_one => {
8
+ :level_two => {
9
+ :level_three => [{ :array_item => 1 }]
10
+ }
11
+ }
12
+ }
13
+ end
14
+
15
+ describe 'default behaviour' do
16
+ let(:target) do
17
+ {
18
+ 'LevelOne' => {
19
+ :level_two => {
20
+ :level_three => [{ :array_item => 1 }]
21
+ }
22
+ }
23
+ }
24
+ end
25
+
26
+ it 'does not convert nested elements' do
27
+ expect(subject.to_postmark(source)).to eq(target)
28
+ end
29
+ end
30
+
31
+ describe 'deep conversion' do
32
+ let(:target) do
33
+ {
34
+ 'LevelOne' => {
35
+ 'LevelTwo' => {
36
+ 'LevelThree' => [{ 'ArrayItem' => 1 }]
37
+ }
38
+ }
39
+ }
40
+ end
7
41
 
8
- it 'converts Hash keys to Postmark format' do
9
- expect(subject.to_postmark(source)).to eq target
42
+ it 'converts nested elements when requested' do
43
+ expect(subject.to_postmark(source, :deep => true)).to eq(target)
44
+ end
10
45
  end
11
46
 
12
- it 'acts idempotentely' do
13
- expect(subject.to_postmark(target)).to eq target
47
+ it 'leaves CamelCase keys untouched' do
48
+ expect(subject.to_postmark('ReplyTo' => 'alice@example.com')).to eq('ReplyTo' => 'alice@example.com')
14
49
  end
15
50
  end
16
51
 
17
52
  describe ".to_ruby" do
18
- let(:source) { {"From" => "support@postmarkapp.com", "ReplyTo" => "contact@wildbit.com"} }
19
- let(:target) { {:from => "support@postmarkapp.com", :reply_to => "contact@wildbit.com"} }
53
+ let(:source) do
54
+ {
55
+ 'LevelOne' => {
56
+ 'LevelTwo' => {
57
+ 'LevelThree' => [{ 'ArrayItem' => 1 }]
58
+ }
59
+ }
60
+ }
61
+ end
20
62
 
21
- it 'converts Hash keys to Ruby format' do
22
- expect(subject.to_ruby(source)).to eq target
63
+ describe 'default behaviour' do
64
+ let(:target) do
65
+ {
66
+ :level_one => {
67
+ 'LevelTwo' => {
68
+ 'LevelThree' => [{ 'ArrayItem' => 1 }]
69
+ }
70
+ }
71
+ }
72
+ end
73
+
74
+ it 'does not convert nested elements' do
75
+ expect(subject.to_ruby(source)).to eq(target)
76
+ end
23
77
  end
24
78
 
25
- it 'has compatible mode' do
26
- expect(subject.to_ruby(source, true)).to eq target.merge(source)
79
+ describe 'deep conversion' do
80
+ let(:target) do
81
+ {
82
+ :level_one => {
83
+ :level_two => {
84
+ :level_three => [{ :array_item => 1 }]
85
+ }
86
+ }
87
+ }
88
+ end
89
+
90
+ it 'converts nested elements when requested' do
91
+ expect(subject.to_ruby(source, :deep => true)).to eq(target)
92
+ end
93
+ end
94
+
95
+ describe 'compatibility mode' do
96
+ let(:target) do
97
+ {
98
+ :level_one => {
99
+ 'LevelTwo' => {
100
+ 'LevelThree' => [{ 'ArrayItem' => 1 }]
101
+ }
102
+ },
103
+ 'LevelOne' => {
104
+ 'LevelTwo' => {
105
+ 'LevelThree' => [{ 'ArrayItem' => 1 }]
106
+ }
107
+ }
108
+ }
109
+ end
110
+
111
+ it 'preserves the original structure' do
112
+ expect(subject.to_ruby(source, :compatible => true)).to eq target
113
+ end
27
114
  end
28
115
 
29
- it 'acts idempotentely' do
30
- expect(subject.to_ruby(target)).to eq target
116
+ it 'leaves symbol keys untouched' do
117
+ expect(subject.to_ruby(:reply_to => 'alice@example.com')).to eq(:reply_to => 'alice@example.com')
31
118
  end
32
119
  end
33
120
  end
metadata CHANGED
@@ -1,16 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.21.4
4
+ version: 1.21.8
5
5
  platform: ruby
6
6
  authors:
7
+ - Tomek Maszkowski
8
+ - Igor Balos
9
+ - Artem Chistyakov
10
+ - Nick Hammond
7
11
  - Petyo Ivanov
8
12
  - Ilya Sabanin
9
- - Artem Chistyakov
10
13
  autorequire:
11
14
  bindir: bin
12
15
  cert_chain: []
13
- date: 2021-06-14 00:00:00.000000000 Z
16
+ date: 2021-07-29 00:00:00.000000000 Z
14
17
  dependencies:
15
18
  - !ruby/object:Gem::Dependency
16
19
  name: json
@@ -56,7 +59,7 @@ dependencies:
56
59
  version: '0'
57
60
  description: Use this gem to send emails through Postmark HTTP API and retrieve info
58
61
  about bounces.
59
- email: ilya@wildbit.com
62
+ email: tomek@wildbit.com
60
63
  executables: []
61
64
  extensions: []
62
65
  extra_rdoc_files:
@@ -68,6 +71,8 @@ files:
68
71
  - ".gitignore"
69
72
  - ".rake_tasks"
70
73
  - ".rspec"
74
+ - ".ruby-gemset"
75
+ - ".ruby-version"
71
76
  - CHANGELOG.rdoc
72
77
  - CONTRIBUTING.md
73
78
  - Gemfile