postmark 1.21.7 → 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: b2bd2c9a288c0f4baa7f2f076d91151a0835b8b168c76e6b1938d5aee972d118
4
- data.tar.gz: 5f8ef5865ba91468d5d413f111af5f195adaf0c44983749605e7e015d9b79eb3
3
+ metadata.gz: bd56ea1117c73ce9a8f60d4dc81dd29f3b409efe1f362a534cb6a9b16a67dc60
4
+ data.tar.gz: 245374f9fb1752254c9c32aeff3ee0139b4b5bce4d252ce40c4f9d2627db42f7
5
5
  SHA512:
6
- metadata.gz: ba8d2597f8502259ef996c647d08f5264e6c677aa4d3e0e697156442b35fe6a1503b914f156b83a627dadaf4cdb64e3e159049d2031e52c675ff721b960abc16
7
- data.tar.gz: 538224ea9fa9c537f9671a5f9de5bfb1a7dc9078f531b6ef8fc8f1c02aa64fda4e82e8031ad5da37abcaeb793b65fd4b5b541e6329181e8e0e21af8d05d0fc93
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,9 @@
1
1
  = Changelog
2
2
 
3
+ == 1.21.8
4
+
5
+ * Fixed passing and receiving SubscriptionManagementConfiguration when creating/updating message streams (#94).
6
+
3
7
  == 1.21.7
4
8
 
5
9
  * Improved parsing recipients with Postmark::InactiveRecipientError.parse_recipients method
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,13 @@ 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
353
  end
354
354
 
355
355
  def archive_message_stream(id)
@@ -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
 
@@ -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.7'
2
+ VERSION = '1.21.8'
3
3
  end
@@ -1073,7 +1073,10 @@ describe Postmark::ApiClient do
1073
1073
  {
1074
1074
  :name => 'My Stream',
1075
1075
  :id => 'my-stream',
1076
- :message_stream_type => 'Broadcasts'
1076
+ :message_stream_type => 'Broadcasts',
1077
+ :subscription_management_configuration => {
1078
+ :unsubscribe_handling_type => 'Custom'
1079
+ }
1077
1080
  }
1078
1081
  end
1079
1082
 
@@ -1083,7 +1086,10 @@ describe Postmark::ApiClient do
1083
1086
  'Id' => 'my-stream',
1084
1087
  'MessageStreamType' => 'Broadcasts',
1085
1088
  'ServerId' => 222,
1086
- '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
+ }
1087
1093
  }
1088
1094
  end
1089
1095
 
@@ -1097,7 +1103,10 @@ describe Postmark::ApiClient do
1097
1103
  json_representation_of({
1098
1104
  'Name' => 'My Stream',
1099
1105
  'Id' => 'my-stream',
1100
- 'MessageStreamType' => 'Broadcasts'
1106
+ 'MessageStreamType' => 'Broadcasts',
1107
+ 'SubscriptionManagementConfiguration' => {
1108
+ 'UnsubscribeHandlingType' => 'Custom'
1109
+ }
1101
1110
  }))
1102
1111
  subject
1103
1112
  end
@@ -1108,7 +1117,10 @@ describe Postmark::ApiClient do
1108
1117
  :name => 'My Stream',
1109
1118
  :server_id => 222,
1110
1119
  :message_stream_type => 'Broadcasts',
1111
- :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
+ }
1112
1124
  )
1113
1125
  }
1114
1126
  end
@@ -1118,7 +1130,10 @@ describe Postmark::ApiClient do
1118
1130
 
1119
1131
  let(:attrs) do
1120
1132
  {
1121
- :name => 'My Stream XXX'
1133
+ :name => 'My Stream XXX',
1134
+ :subscription_management_configuration => {
1135
+ :unsubscribe_handling_type => 'Custom'
1136
+ }
1122
1137
  }
1123
1138
  end
1124
1139
 
@@ -1128,7 +1143,10 @@ describe Postmark::ApiClient do
1128
1143
  'Id' => 'xxx',
1129
1144
  'MessageStreamType' => 'Broadcasts',
1130
1145
  'ServerId' => 222,
1131
- '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
+ }
1132
1150
  }
1133
1151
  end
1134
1152
 
@@ -1140,7 +1158,10 @@ describe Postmark::ApiClient do
1140
1158
  expect(http_client).to receive(:patch).
1141
1159
  with('message-streams/xxx',
1142
1160
  match_json({
1143
- :Name => 'My Stream XXX',
1161
+ 'Name' => 'My Stream XXX',
1162
+ 'SubscriptionManagementConfiguration' => {
1163
+ 'UnsubscribeHandlingType' => 'Custom'
1164
+ }
1144
1165
  }))
1145
1166
  subject
1146
1167
  end
@@ -1151,7 +1172,10 @@ describe Postmark::ApiClient do
1151
1172
  :name => 'My Stream XXX',
1152
1173
  :server_id => 222,
1153
1174
  :message_stream_type => 'Broadcasts',
1154
- :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
+ }
1155
1179
  )
1156
1180
  }
1157
1181
  end
@@ -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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.21.7
4
+ version: 1.21.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomek Maszkowski
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2021-07-22 00:00:00.000000000 Z
16
+ date: 2021-07-29 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: json
@@ -71,6 +71,8 @@ files:
71
71
  - ".gitignore"
72
72
  - ".rake_tasks"
73
73
  - ".rspec"
74
+ - ".ruby-gemset"
75
+ - ".ruby-version"
74
76
  - CHANGELOG.rdoc
75
77
  - CONTRIBUTING.md
76
78
  - Gemfile
@@ -150,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
152
  - !ruby/object:Gem::Version
151
153
  version: 1.3.7
152
154
  requirements: []
153
- rubygems_version: 3.2.3
155
+ rubygems_version: 3.0.8
154
156
  signing_key:
155
157
  specification_version: 4
156
158
  summary: Official Postmark API wrapper.