paubox 0.2.3 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/README.md +120 -8
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/lib/mail/paubox.rb +3 -2
- data/lib/paubox/client.rb +9 -5
- data/lib/paubox/email_disposition.rb +5 -0
- data/lib/paubox/format_helper.rb +7 -2
- data/lib/paubox/mail_to_message.rb +27 -3
- data/lib/paubox/message.rb +33 -8
- data/lib/paubox/templated_message.rb +28 -0
- data/lib/paubox/version.rb +3 -1
- data/lib/paubox.rb +4 -1
- data/lib/paubox_ruby.rb +2 -0
- data/paubox_ruby.gemspec +10 -8
- metadata +28 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3733459b49f6166432d85899d4ea38e9d9f983c6f1ef42d17ed430fc7095beb9
|
4
|
+
data.tar.gz: f4c0bf54df9f438dd499d178ca67eadb2b4f7e0aa3516089da2faed70b6f02cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66acb7c648c2ede8380ecdaeb60c8cde92cd97ed66f17dce81bf8ef9e175c9d53f777fab4d1527ee3c8ceb35d65b3975a74fa5047af8add6af90380fc8b17f5b
|
7
|
+
data.tar.gz: 3eeb0122292eb25f34dc24e5e62ed696200c8efd45304cde5a92467dec5c03bc0c27d01ff369ece52b4c6091c36651e886d119049922f752cafb2cc4c1c4ce97
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
<img src="https://
|
1
|
+
<img src="https://avatars.githubusercontent.com/u/22528478?s=200&v=4" alt="Paubox" width="150px">
|
2
2
|
|
3
3
|
# Paubox Gem
|
4
|
-
This
|
5
|
-
|
6
|
-
This is the official Ruby wrapper for the Paubox Transactional Email HTTP API. The Paubox Transactional Email API allows your application to send secure, HIPAA-compliant email via Paubox and track deliveries and opens.
|
4
|
+
This is the official Ruby wrapper for the Paubox Email API. The Paubox Email API allows your application to send secure, HIPAA compliant email via Paubox and track deliveries and opens.
|
7
5
|
|
8
6
|
It extends the [Ruby Mail Library](https://github.com/mikel/mail) for seamless integration in your existing Ruby application. The API wrapper also allows you to construct and send messages directly without the Ruby Mail Library.
|
9
7
|
|
@@ -39,7 +37,8 @@ Once you have an account, follow the instructions on the Rest API dashboard to v
|
|
39
37
|
### Configuring API Credentials
|
40
38
|
Include your API credentials in an initializer (e.g. config/initializers/paubox.rb in Rails).
|
41
39
|
|
42
|
-
Keep your API credentials out of version control. Store these in
|
40
|
+
Keep your API credentials out of version control. Store these in environment variables.
|
41
|
+
|
43
42
|
```ruby
|
44
43
|
Paubox.configure do |config|
|
45
44
|
config.api_key = ENV['PAUBOX_API_KEY']
|
@@ -47,16 +46,41 @@ Paubox.configure do |config|
|
|
47
46
|
end
|
48
47
|
```
|
49
48
|
|
49
|
+
If you need to send from multiple domains, you can pass credentials in the options hash when you set Ruby Mail's `Mail#delivery_method`, or when using `Paubox::Message`, when you instantiate `Paubox::Client`.
|
50
|
+
|
51
|
+
**(optional) Setting credentials when using Ruby Mail:**
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
message = Mail.new do
|
55
|
+
...
|
56
|
+
delivery_method(Mail::Paubox, api_key: ENV['PAUBOX_API_KEY'],
|
57
|
+
api_user: ENV['PAUBOX_API_USER'])
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
**(optional) Setting credentials when using Paubox::Client:**
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
client = Paubox::Client.new(api_key: ENV['PAUBOX_API_KEY'],
|
65
|
+
api_user: ENV['PAUBOX_API_USER'])
|
66
|
+
```
|
67
|
+
|
50
68
|
<a name="#usage"></a>
|
51
69
|
## Usage
|
52
70
|
|
53
71
|
### Sending Messages with the Ruby Mail Library
|
54
72
|
|
55
73
|
Using the Ruby Mail Library? Sending via Paubox is easy. Just build a message as normal and set Mail::Paubox as the delivery method.
|
74
|
+
|
56
75
|
```ruby
|
76
|
+
require 'Paubox'
|
77
|
+
require 'json'
|
78
|
+
require 'mail'
|
79
|
+
|
57
80
|
message = Mail.new do
|
58
81
|
from 'you@yourdomain.com'
|
59
82
|
to 'someone@somewhere.com'
|
83
|
+
cc 'another@somewhere.com'
|
60
84
|
subject 'HIPAA-compliant email made easy'
|
61
85
|
|
62
86
|
text_part do
|
@@ -80,8 +104,13 @@ message.source_tracking_id
|
|
80
104
|
|
81
105
|
### Allowing non-TLS message delivery
|
82
106
|
|
83
|
-
If you want to send non-PHI mail that does not need to be HIPAA
|
107
|
+
If you want to send non-PHI mail that does not need to be HIPAA compliant, you can allow the message delivery to take place even if a TLS connection is unavailable. This means a message will not be converted into a secure portal message when a non-TLS connection is encountered.
|
108
|
+
|
84
109
|
```ruby
|
110
|
+
require 'Paubox'
|
111
|
+
require 'json'
|
112
|
+
require 'mail'
|
113
|
+
|
85
114
|
message = Mail.new do
|
86
115
|
from 'you@yourdomain.com'
|
87
116
|
to 'someone@somewhere.com'
|
@@ -95,9 +124,57 @@ message.allow_non_tls = true
|
|
95
124
|
message.deliver!
|
96
125
|
```
|
97
126
|
|
127
|
+
### Forcing Secure Notifications
|
128
|
+
|
129
|
+
Paubox Secure Notifications allow an extra layer of security, especially when coupled with an organization's requirement for message recipients to use 2-factor authentication to read messages (this setting is available to org administrators in the Paubox Admin Panel).
|
130
|
+
|
131
|
+
Instead of receiving an email with the message contents, the recipient will receive a notification email that they have a new message in Paubox.
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
require 'Paubox'
|
135
|
+
require 'json'
|
136
|
+
require 'mail'
|
137
|
+
|
138
|
+
message = Mail.new do
|
139
|
+
from 'you@yourdomain.com'
|
140
|
+
to 'someone@somewhere.com'
|
141
|
+
subject 'Sending non-PHI'
|
142
|
+
body 'This message delivery will not enforce TLS transmission.'
|
143
|
+
|
144
|
+
delivery_method Mail::Paubox
|
145
|
+
end
|
146
|
+
|
147
|
+
message.force_secure_notification = 'true'
|
148
|
+
message.deliver!
|
149
|
+
```
|
150
|
+
|
151
|
+
### Adding Attachments
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
require 'Paubox'
|
155
|
+
require 'json'
|
156
|
+
require 'mail'
|
157
|
+
|
158
|
+
message = Mail.new do
|
159
|
+
from 'you@yourdomain.com'
|
160
|
+
to 'someone@somewhere.com'
|
161
|
+
cc 'another@somewhere.com'
|
162
|
+
subject 'HIPAA-compliant email made easy'
|
163
|
+
|
164
|
+
delivery_method Mail::Paubox
|
165
|
+
end
|
166
|
+
|
167
|
+
message.add_file("path_to_your_file")
|
168
|
+
message.deliver!
|
169
|
+
```
|
170
|
+
|
98
171
|
### Sending Messages using just the Paubox API
|
99
172
|
You don't need to use Ruby Mail to build and send messages with Paubox.
|
173
|
+
|
100
174
|
```ruby
|
175
|
+
require 'Paubox'
|
176
|
+
require 'json'
|
177
|
+
|
101
178
|
args = { from: 'you@yourdomain.com',
|
102
179
|
to: 'someone@domain.com, someone-else@domain.com',
|
103
180
|
cc: ['another@domain.com', 'yet-another@domain.com'],
|
@@ -105,7 +182,8 @@ args = { from: 'you@yourdomain.com',
|
|
105
182
|
reply_to: 'reply-to@yourdomain.com',
|
106
183
|
subject: 'Testing!',
|
107
184
|
text_content: 'Hello World!',
|
108
|
-
html_content: '<h1>Hello World!</h1>'
|
185
|
+
html_content: '<h1>Hello World!</h1>'
|
186
|
+
}
|
109
187
|
|
110
188
|
message = Paubox::Message.new(args)
|
111
189
|
|
@@ -114,8 +192,42 @@ client.deliver_mail(message)
|
|
114
192
|
=> {"message"=>"Service OK", "sourceTrackingId"=>"2a3c048485aa4cf6"}
|
115
193
|
```
|
116
194
|
|
195
|
+
### Send Messages using Dynamic Templates
|
196
|
+
Using [dynamic templates](https://docs.paubox.com/docs/paubox_email_api/dynamic_templates/) is similar to sending a regular message. Just create a `Paubox::TemplatedMessage` object and pass a `template` object with the name of the template and variables:
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
require 'Paubox'
|
200
|
+
require 'json'
|
201
|
+
|
202
|
+
args = { from: 'you@yourdomain.com',
|
203
|
+
to: 'someone@domain.com, someone-else@domain.com',
|
204
|
+
cc: ['another@domain.com', 'yet-another@domain.com'],
|
205
|
+
bcc: 'bcc-recipient@domain.com',
|
206
|
+
reply_to: 'reply-to@yourdomain.com',
|
207
|
+
subject: 'Testing!',
|
208
|
+
template: {
|
209
|
+
name: 'Test Template',
|
210
|
+
values: {
|
211
|
+
first_name: 'Timothy',
|
212
|
+
last_name: 'Testerson'
|
213
|
+
}
|
214
|
+
}
|
215
|
+
}
|
216
|
+
|
217
|
+
templated_message = Paubox::TemplatedMessage.new(args)
|
218
|
+
|
219
|
+
client = Paubox::Client.new
|
220
|
+
client.deliver_mail(templated_message)
|
221
|
+
=> {"sourceTrackingId"=>"166904b5-dce7-4de1-92e8-3d505c165ff5", "data"=>"Service OK"}
|
222
|
+
```
|
223
|
+
|
224
|
+
_Note that there is no `content` when using templated messages._
|
225
|
+
|
117
226
|
### Checking Email Dispositions
|
118
227
|
```ruby
|
228
|
+
require 'Paubox'
|
229
|
+
require 'json'
|
230
|
+
|
119
231
|
client = Paubox::Client.new
|
120
232
|
email_disposition = client.email_disposition('2a3c048485aa4cf6')
|
121
233
|
|
@@ -167,5 +279,5 @@ See the License for the specific language governing permissions and
|
|
167
279
|
limitations under the License.
|
168
280
|
|
169
281
|
## Copyright
|
170
|
-
Copyright ©
|
282
|
+
Copyright © 2022, Paubox, Inc.
|
171
283
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'paubox_ruby'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "paubox_ruby"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/lib/mail/paubox.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mail
|
2
4
|
class Paubox
|
3
5
|
attr_accessor :settings
|
@@ -9,11 +11,10 @@ module Mail
|
|
9
11
|
def deliver!(mail)
|
10
12
|
client = ::Paubox::Client.new(settings)
|
11
13
|
response = client.send_mail(mail)
|
12
|
-
puts response
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
17
|
class Message
|
17
|
-
attr_accessor :source_tracking_id, :status, :allow_non_tls
|
18
|
+
attr_accessor :source_tracking_id, :status, :allow_non_tls, :force_secure_notification
|
18
19
|
end
|
19
20
|
end
|
data/lib/paubox/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Paubox
|
2
4
|
# Client sends API requests to Paubox API
|
3
5
|
class Client
|
@@ -14,7 +16,6 @@ module Paubox
|
|
14
16
|
@api_version = args[:api_version]
|
15
17
|
@test_mode = args[:test_mode]
|
16
18
|
@api_base_endpoint = api_base_endpoint
|
17
|
-
@allow_non_tls = args.fetch(:allow_non_tls, false)
|
18
19
|
end
|
19
20
|
|
20
21
|
def api_status
|
@@ -25,12 +26,15 @@ module Paubox
|
|
25
26
|
def send_mail(mail)
|
26
27
|
case mail
|
27
28
|
when Mail::Message
|
28
|
-
|
29
|
+
allow_non_tls = mail.allow_non_tls.nil? ? false : mail.allow_non_tls
|
30
|
+
payload = MailToMessage.new(mail, allow_non_tls: allow_non_tls)
|
29
31
|
.send_message_payload
|
30
32
|
when Hash
|
31
33
|
payload = Message.new(mail).send_message_payload
|
34
|
+
when Paubox::Message, Paubox::TemplatedMessage
|
35
|
+
payload = mail.send_message_payload
|
32
36
|
end
|
33
|
-
url = request_endpoint('messages')
|
37
|
+
url = request_endpoint(mail.is_a?(Paubox::TemplatedMessage) ? 'templated_messages' : 'messages')
|
34
38
|
response = RestClient.post(url, payload, auth_header)
|
35
39
|
if mail.class == Mail::Message
|
36
40
|
mail.source_tracking_id = JSON.parse(response.body)['sourceTrackingId']
|
@@ -51,7 +55,7 @@ module Paubox
|
|
51
55
|
def auth_header
|
52
56
|
{ accept: :json,
|
53
57
|
content_type: :json,
|
54
|
-
:
|
58
|
+
Authorization: "Token token=#{@api_key}" }
|
55
59
|
end
|
56
60
|
|
57
61
|
def api_base_endpoint
|
@@ -65,7 +69,7 @@ module Paubox
|
|
65
69
|
def defaults
|
66
70
|
{ api_key: Paubox.configuration.api_key,
|
67
71
|
api_user: Paubox.configuration.api_user,
|
68
|
-
api_host: 'api.paubox.net',
|
72
|
+
api_host: 'api.paubox.net',
|
69
73
|
api_protocol: 'https://',
|
70
74
|
api_version: 'v1',
|
71
75
|
test_mode: false }
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Paubox
|
2
4
|
# Parses email dispositions from /v1/message_reciept response to friendly Ruby
|
3
5
|
class EmailDisposition
|
@@ -26,6 +28,7 @@ module Paubox
|
|
26
28
|
|
27
29
|
def build_errors
|
28
30
|
return [] unless response['errors']
|
31
|
+
|
29
32
|
errors = response['errors']
|
30
33
|
errors.map { |e| ResponseError.new(e['code'], e['status'], e['title'], e['details']) }
|
31
34
|
end
|
@@ -34,6 +37,7 @@ module Paubox
|
|
34
37
|
|
35
38
|
def build_message_deliveries
|
36
39
|
return [] unless @message_data
|
40
|
+
|
37
41
|
deliveries = @message_data.fetch('message_deliveries', [])
|
38
42
|
deliveries.map do |delivery|
|
39
43
|
status = build_message_delivery_status(delivery['status'])
|
@@ -47,6 +51,7 @@ module Paubox
|
|
47
51
|
opened_status = stat['openedStatus'].to_s.empty? ? 'unopened' : stat['openedStatus']
|
48
52
|
opened_time = stat['openedTime'].to_s.empty? ? nil : DateTime.parse(stat['openedTime'])
|
49
53
|
return MessageMultiDeliveryStatus.new(delivery_status, delivery_time) if multi_recipient?
|
54
|
+
|
50
55
|
MessageDeliveryStatus.new(delivery_status, delivery_time, opened_status, opened_time)
|
51
56
|
end
|
52
57
|
|
data/lib/paubox/format_helper.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Paubox
|
2
4
|
# Utility methods for Message and MailToMessage
|
3
5
|
module FormatHelper
|
4
6
|
require 'base64'
|
5
|
-
BASE64_REGEX = %r(/^(?:[A-Za-z0-9+\/]{4}\n?)*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/)
|
7
|
+
BASE64_REGEX = %r(/^(?:[A-Za-z0-9+\/]{4}\n?)*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/).freeze
|
6
8
|
|
7
9
|
def base64_encoded?(value)
|
8
10
|
return false unless value.is_a?(String)
|
11
|
+
|
9
12
|
!value.strip.match(BASE64_REGEX).nil?
|
10
13
|
end
|
11
14
|
|
12
15
|
def base64_encode_if_needed(str)
|
13
16
|
return str if base64_encoded?(str.to_s)
|
17
|
+
|
14
18
|
Base64.encode64(str.to_s)
|
15
19
|
end
|
16
20
|
|
@@ -21,6 +25,7 @@ module Paubox
|
|
21
25
|
hash.each_pair do |key, val|
|
22
26
|
converted[ruby_to_json_key(key)] = val.is_a?(Hash) ? convert_keys_to_json_version(val) : val
|
23
27
|
next unless val.is_a?(Array)
|
28
|
+
|
24
29
|
val.each_with_index { |el, i| val[i] = convert_keys_to_json_version(el) if el.is_a?(Hash) }
|
25
30
|
end
|
26
31
|
converted
|
@@ -29,7 +34,7 @@ module Paubox
|
|
29
34
|
def ruby_to_json_key(key)
|
30
35
|
{ reply_to: 'reply-to', html_content: 'text/html', text_content: 'text/plain',
|
31
36
|
filename: 'fileName', file_name: 'fileName', content_type: 'contentType',
|
32
|
-
allow_non_tls: 'allowNonTLS' }[key] || key.to_s
|
37
|
+
allow_non_tls: 'allowNonTLS', force_secure_notification: 'forceSecureNotification' }[key] || key.to_s
|
33
38
|
end
|
34
39
|
|
35
40
|
# def get_values_whitelist(*vals)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Paubox
|
2
4
|
# The MailToMessage class takes a Ruby Mail object and attempts to parse it
|
3
5
|
# into a Hash formatted for the JSON payload of HTTP api request.
|
@@ -9,6 +11,7 @@ module Paubox
|
|
9
11
|
def initialize(mail, args = {})
|
10
12
|
@mail = mail
|
11
13
|
@allow_non_tls = args.fetch(:allow_non_tls, false)
|
14
|
+
@force_secure_notification = args.fetch(:force_secure_notification, nil)
|
12
15
|
end
|
13
16
|
|
14
17
|
def send_message_payload
|
@@ -20,6 +23,7 @@ module Paubox
|
|
20
23
|
def build_attachments
|
21
24
|
attachments = mail.attachments
|
22
25
|
return [] if attachments.empty?
|
26
|
+
|
23
27
|
packaged_attachments = []
|
24
28
|
attachments.each do |attch|
|
25
29
|
packaged_attachments << { content: convert_binary_to_base64(attch.body.decoded),
|
@@ -34,10 +38,10 @@ module Paubox
|
|
34
38
|
if mail.multipart?
|
35
39
|
html_content = mail.html_part.body.to_s if mail.html_part
|
36
40
|
text_content = mail.text_part.body.to_s if mail.text_part
|
37
|
-
content[:html_content] = html_content unless html_content.nil?
|
41
|
+
content[:html_content] = base64_encode_if_needed(html_content) unless html_content.nil?
|
38
42
|
content[:text_content] = text_content unless text_content.nil?
|
39
43
|
elsif mail.content_type.to_s.include? 'text/html'
|
40
|
-
content[:html_content] = mail.body.to_s
|
44
|
+
content[:html_content] = base64_encode_if_needed(mail.body.to_s)
|
41
45
|
else
|
42
46
|
content[:text_content] = mail.body.to_s
|
43
47
|
end
|
@@ -48,12 +52,32 @@ module Paubox
|
|
48
52
|
%i[from reply_to subject].map { |k| [k, mail[k].to_s] }.to_h
|
49
53
|
end
|
50
54
|
|
55
|
+
def build_force_secure_notification
|
56
|
+
if @force_secure_notification.instance_of?(String)
|
57
|
+
unless @force_secure_notification.to_s.empty? # if force_secure_notification is not nil or empty
|
58
|
+
force_secure_notification_val = @force_secure_notification.strip.downcase
|
59
|
+
if force_secure_notification_val == 'true'
|
60
|
+
return true
|
61
|
+
elsif force_secure_notification_val == 'false'
|
62
|
+
return false
|
63
|
+
else
|
64
|
+
return nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
|
51
71
|
def build_parts
|
52
72
|
msg = {}
|
53
73
|
msg[:recipients] = string_or_array_to_array(mail.to)
|
54
|
-
msg[:
|
74
|
+
msg[:cc] = string_or_array_to_array(mail.cc)
|
55
75
|
msg[:bcc] = string_or_array_to_array(mail.bcc)
|
56
76
|
msg[:allow_non_tls] = @allow_non_tls
|
77
|
+
@force_secure_notification = build_force_secure_notification
|
78
|
+
unless @force_secure_notification.nil?
|
79
|
+
msg[:force_secure_notification] = @force_secure_notification
|
80
|
+
end
|
57
81
|
msg[:headers] = build_headers
|
58
82
|
msg[:content] = build_content
|
59
83
|
msg[:attachments] = build_attachments
|
data/lib/paubox/message.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Paubox
|
2
4
|
# The Message class is for building a Paubox email message using a hash.
|
3
5
|
class Message
|
4
6
|
include Paubox::FormatHelper
|
5
7
|
attr_accessor :from, :to, :cc, :bcc, :subject, :reply_to, :text_content,
|
6
|
-
:html_content, :allow_non_tls
|
8
|
+
:html_content, :allow_non_tls, :force_secure_notification
|
7
9
|
|
8
10
|
def initialize(args)
|
9
11
|
@from = args[:from]
|
@@ -17,6 +19,7 @@ module Paubox
|
|
17
19
|
@packaged_attachments = []
|
18
20
|
@attachments = build_attachments(args[:attachments])
|
19
21
|
@allow_non_tls = args.fetch(:allow_non_tls, false)
|
22
|
+
@force_secure_notification = args.fetch(:force_secure_notification, nil)
|
20
23
|
end
|
21
24
|
|
22
25
|
def send_message_payload
|
@@ -25,8 +28,8 @@ module Paubox
|
|
25
28
|
|
26
29
|
def add_attachment(file_path)
|
27
30
|
@packaged_attachments << { filename: file_path.split('/').last,
|
28
|
-
|
29
|
-
|
31
|
+
content_type: `file --b --mime-type #{file_path}`.chomp,
|
32
|
+
content: Base64.encode64(File.read(file_path)) }
|
30
33
|
end
|
31
34
|
|
32
35
|
def attachments
|
@@ -41,8 +44,9 @@ module Paubox
|
|
41
44
|
|
42
45
|
def build_attachments(args)
|
43
46
|
return (@packaged_attachments = []) if args.to_a.empty?
|
47
|
+
|
44
48
|
args.each do |a|
|
45
|
-
a[:content] =
|
49
|
+
a[:content] = base64_encode_if_needed(a[:content])
|
46
50
|
@packaged_attachments << a
|
47
51
|
end
|
48
52
|
@packaged_attachments
|
@@ -51,18 +55,39 @@ module Paubox
|
|
51
55
|
def build_content
|
52
56
|
content = {}
|
53
57
|
content[:text_content] = text_content if text_content
|
54
|
-
content[:html_content] = html_content if html_content
|
58
|
+
content[:html_content] = base64_encode_if_needed(html_content) if html_content
|
55
59
|
content
|
56
60
|
end
|
57
61
|
|
58
62
|
def build_headers
|
59
|
-
%i[from reply_to subject].map { |k| [k,
|
63
|
+
%i[from reply_to subject].map { |k| [k, send(k)] }.to_h
|
64
|
+
end
|
65
|
+
|
66
|
+
def build_force_secure_notification
|
67
|
+
if @force_secure_notification.instance_of?(String)
|
68
|
+
unless @force_secure_notification.to_s.empty? # if force_secure_notification is not nil or empty
|
69
|
+
force_secure_notification_val = @force_secure_notification.strip.downcase
|
70
|
+
if force_secure_notification_val == 'true'
|
71
|
+
return true
|
72
|
+
elsif force_secure_notification_val == 'false'
|
73
|
+
return false
|
74
|
+
else
|
75
|
+
return nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
nil
|
60
80
|
end
|
61
81
|
|
62
82
|
def build_parts
|
63
83
|
msg = {}
|
64
|
-
msg[:recipients] = string_or_array_to_array(to)
|
84
|
+
msg[:recipients] = string_or_array_to_array(to)
|
85
|
+
msg[:cc] = string_or_array_to_array(cc)
|
65
86
|
msg[:allow_non_tls] = @allow_non_tls
|
87
|
+
@force_secure_notification = build_force_secure_notification
|
88
|
+
unless @force_secure_notification.nil?
|
89
|
+
msg[:force_secure_notification] = @force_secure_notification
|
90
|
+
end
|
66
91
|
msg[:bcc] = string_or_array_to_array(bcc)
|
67
92
|
msg[:headers] = build_headers
|
68
93
|
msg[:content] = build_content
|
@@ -70,4 +95,4 @@ module Paubox
|
|
70
95
|
msg
|
71
96
|
end
|
72
97
|
end
|
73
|
-
end
|
98
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Paubox
|
4
|
+
# The TemplatedMessage class is for building a Paubox email message from a dynamic template, using a hash.
|
5
|
+
class TemplatedMessage < Message
|
6
|
+
attr_accessor :template_name,
|
7
|
+
:template_values
|
8
|
+
|
9
|
+
def initialize(args)
|
10
|
+
@template_name = args[:template][:name]
|
11
|
+
@template_values = args[:template][:values]
|
12
|
+
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def send_message_payload
|
17
|
+
# template name and values must be outside the `message` object
|
18
|
+
msg = convert_keys_to_json_version(build_parts)
|
19
|
+
|
20
|
+
template_params = {
|
21
|
+
template_name: @template_name,
|
22
|
+
template_values: @template_values.to_json
|
23
|
+
}
|
24
|
+
|
25
|
+
{ data: { message: convert_keys_to_json_version(build_parts) }.merge(template_params) }.to_json
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/paubox/version.rb
CHANGED
data/lib/paubox.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'paubox/version'
|
2
4
|
require 'paubox/client'
|
3
5
|
require 'paubox/format_helper'
|
4
6
|
require 'paubox/mail_to_message'
|
5
7
|
require 'paubox/message'
|
8
|
+
require 'paubox/templated_message'
|
6
9
|
require 'paubox/email_disposition'
|
7
10
|
require 'mail/paubox'
|
8
11
|
|
@@ -19,4 +22,4 @@ module Paubox
|
|
19
22
|
class Configuration
|
20
23
|
attr_accessor :api_key, :api_user
|
21
24
|
end
|
22
|
-
end
|
25
|
+
end
|
data/lib/paubox_ruby.rb
CHANGED
data/paubox_ruby.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
2
4
|
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
@@ -6,26 +8,26 @@ require 'paubox/version'
|
|
6
8
|
Gem::Specification.new do |spec|
|
7
9
|
spec.name = 'paubox'
|
8
10
|
spec.version = Paubox::VERSION
|
9
|
-
spec.authors = ['Paubox'
|
10
|
-
spec.email = ['
|
11
|
+
spec.authors = ['Paubox']
|
12
|
+
spec.email = ['engineering@paubox.com']
|
11
13
|
|
12
14
|
spec.summary = "Paubox's Official Ruby SDK"
|
13
|
-
spec.description =
|
15
|
+
spec.description = 'Ruby SDK for interacting with the Paubox Transactional Email HTTP API.'
|
14
16
|
spec.homepage = 'https://www.paubox.com'
|
15
17
|
spec.license = 'Apache-2.0'
|
16
18
|
|
17
19
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
20
|
f.match(%r{^(test|spec|features)/})
|
19
21
|
end
|
20
|
-
spec.bindir =
|
22
|
+
spec.bindir = 'exe'
|
21
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
-
spec.require_paths = [
|
24
|
+
spec.require_paths = ['lib']
|
23
25
|
spec.required_ruby_version = '>= 2.3'
|
24
|
-
spec.add_development_dependency 'bundler', '~>
|
25
|
-
spec.add_development_dependency '
|
26
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
27
|
+
spec.add_development_dependency 'pry'
|
28
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
26
29
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
27
30
|
spec.add_development_dependency 'webmock', '~> 2.1'
|
28
|
-
spec.add_development_dependency 'pry'
|
29
31
|
|
30
32
|
spec.add_dependency 'mail', '>= 2.5'
|
31
33
|
spec.add_dependency 'rest-client', '~> 2.0', '>= 2.0.2'
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paubox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paubox
|
8
|
-
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2022-10-06 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
@@ -17,70 +16,70 @@ dependencies:
|
|
17
16
|
requirements:
|
18
17
|
- - "~>"
|
19
18
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
19
|
+
version: '2.0'
|
21
20
|
type: :development
|
22
21
|
prerelease: false
|
23
22
|
version_requirements: !ruby/object:Gem::Requirement
|
24
23
|
requirements:
|
25
24
|
- - "~>"
|
26
25
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
26
|
+
version: '2.0'
|
28
27
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
28
|
+
name: pry
|
30
29
|
requirement: !ruby/object:Gem::Requirement
|
31
30
|
requirements:
|
32
|
-
- - "
|
31
|
+
- - ">="
|
33
32
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
33
|
+
version: '0'
|
35
34
|
type: :development
|
36
35
|
prerelease: false
|
37
36
|
version_requirements: !ruby/object:Gem::Requirement
|
38
37
|
requirements:
|
39
|
-
- - "
|
38
|
+
- - ">="
|
40
39
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
40
|
+
version: '0'
|
42
41
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
42
|
+
name: rake
|
44
43
|
requirement: !ruby/object:Gem::Requirement
|
45
44
|
requirements:
|
46
|
-
- - "
|
45
|
+
- - ">="
|
47
46
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
47
|
+
version: 12.3.3
|
49
48
|
type: :development
|
50
49
|
prerelease: false
|
51
50
|
version_requirements: !ruby/object:Gem::Requirement
|
52
51
|
requirements:
|
53
|
-
- - "
|
52
|
+
- - ">="
|
54
53
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
54
|
+
version: 12.3.3
|
56
55
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
56
|
+
name: rspec
|
58
57
|
requirement: !ruby/object:Gem::Requirement
|
59
58
|
requirements:
|
60
59
|
- - "~>"
|
61
60
|
- !ruby/object:Gem::Version
|
62
|
-
version: '2
|
61
|
+
version: '3.2'
|
63
62
|
type: :development
|
64
63
|
prerelease: false
|
65
64
|
version_requirements: !ruby/object:Gem::Requirement
|
66
65
|
requirements:
|
67
66
|
- - "~>"
|
68
67
|
- !ruby/object:Gem::Version
|
69
|
-
version: '2
|
68
|
+
version: '3.2'
|
70
69
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
70
|
+
name: webmock
|
72
71
|
requirement: !ruby/object:Gem::Requirement
|
73
72
|
requirements:
|
74
|
-
- - "
|
73
|
+
- - "~>"
|
75
74
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
75
|
+
version: '2.1'
|
77
76
|
type: :development
|
78
77
|
prerelease: false
|
79
78
|
version_requirements: !ruby/object:Gem::Requirement
|
80
79
|
requirements:
|
81
|
-
- - "
|
80
|
+
- - "~>"
|
82
81
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
82
|
+
version: '2.1'
|
84
83
|
- !ruby/object:Gem::Dependency
|
85
84
|
name: mail
|
86
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,7 +116,7 @@ dependencies:
|
|
117
116
|
version: 2.0.2
|
118
117
|
description: Ruby SDK for interacting with the Paubox Transactional Email HTTP API.
|
119
118
|
email:
|
120
|
-
-
|
119
|
+
- engineering@paubox.com
|
121
120
|
executables: []
|
122
121
|
extensions: []
|
123
122
|
extra_rdoc_files: []
|
@@ -138,6 +137,7 @@ files:
|
|
138
137
|
- lib/paubox/format_helper.rb
|
139
138
|
- lib/paubox/mail_to_message.rb
|
140
139
|
- lib/paubox/message.rb
|
140
|
+
- lib/paubox/templated_message.rb
|
141
141
|
- lib/paubox/version.rb
|
142
142
|
- lib/paubox_ruby.rb
|
143
143
|
- paubox_ruby.gemspec
|
@@ -145,7 +145,7 @@ homepage: https://www.paubox.com
|
|
145
145
|
licenses:
|
146
146
|
- Apache-2.0
|
147
147
|
metadata: {}
|
148
|
-
post_install_message:
|
148
|
+
post_install_message:
|
149
149
|
rdoc_options: []
|
150
150
|
require_paths:
|
151
151
|
- lib
|
@@ -160,9 +160,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
160
|
- !ruby/object:Gem::Version
|
161
161
|
version: '0'
|
162
162
|
requirements: []
|
163
|
-
|
164
|
-
|
165
|
-
signing_key:
|
163
|
+
rubygems_version: 3.3.14
|
164
|
+
signing_key:
|
166
165
|
specification_version: 4
|
167
166
|
summary: Paubox's Official Ruby SDK
|
168
167
|
test_files: []
|