paubox 0.2.3 → 0.3.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 +5 -5
- data/.gitignore +13 -12
- data/.rspec +2 -2
- data/.travis.yml +5 -5
- data/Gemfile +6 -4
- data/LICENSE.txt +12 -12
- data/README.md +230 -171
- data/Rakefile +8 -6
- data/bin/console +15 -14
- data/bin/setup +8 -8
- data/lib/mail/paubox.rb +21 -19
- data/lib/paubox.rb +24 -22
- data/lib/paubox/client.rb +85 -81
- data/lib/paubox/email_disposition.rb +62 -57
- data/lib/paubox/format_helper.rb +60 -55
- data/lib/paubox/mail_to_message.rb +94 -70
- data/lib/paubox/message.rb +98 -73
- data/lib/paubox/version.rb +5 -3
- data/lib/paubox_ruby.rb +3 -1
- data/paubox_ruby.gemspec +34 -32
- metadata +19 -20
@@ -1,70 +1,94 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
attachments
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
content[:text_content] =
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Paubox
|
4
|
+
# The MailToMessage class takes a Ruby Mail object and attempts to parse it
|
5
|
+
# into a Hash formatted for the JSON payload of HTTP api request.
|
6
|
+
class MailToMessage
|
7
|
+
include Paubox::FormatHelper
|
8
|
+
attr_reader :mail
|
9
|
+
require 'tempfile'
|
10
|
+
|
11
|
+
def initialize(mail, args = {})
|
12
|
+
@mail = mail
|
13
|
+
@allow_non_tls = args.fetch(:allow_non_tls, false)
|
14
|
+
@force_secure_notification = args.fetch(:force_secure_notification, nil)
|
15
|
+
end
|
16
|
+
|
17
|
+
def send_message_payload
|
18
|
+
{ data: { message: convert_keys_to_json_version(build_parts) } }.to_json
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def build_attachments
|
24
|
+
attachments = mail.attachments
|
25
|
+
return [] if attachments.empty?
|
26
|
+
|
27
|
+
packaged_attachments = []
|
28
|
+
attachments.each do |attch|
|
29
|
+
packaged_attachments << { content: convert_binary_to_base64(attch.body.decoded),
|
30
|
+
file_name: attch.filename,
|
31
|
+
content_type: attch.mime_type }
|
32
|
+
end
|
33
|
+
packaged_attachments
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_content
|
37
|
+
content = {}
|
38
|
+
if mail.multipart?
|
39
|
+
html_content = mail.html_part.body.to_s if mail.html_part
|
40
|
+
text_content = mail.text_part.body.to_s if mail.text_part
|
41
|
+
content[:html_content] = base64_encode_if_needed(html_content) unless html_content.nil?
|
42
|
+
content[:text_content] = text_content unless text_content.nil?
|
43
|
+
elsif mail.content_type.to_s.include? 'text/html'
|
44
|
+
content[:html_content] = base64_encode_if_needed(mail.body.to_s)
|
45
|
+
else
|
46
|
+
content[:text_content] = mail.body.to_s
|
47
|
+
end
|
48
|
+
content
|
49
|
+
end
|
50
|
+
|
51
|
+
def build_headers
|
52
|
+
%i[from reply_to subject].map { |k| [k, mail[k].to_s] }.to_h
|
53
|
+
end
|
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
|
+
|
71
|
+
def build_parts
|
72
|
+
msg = {}
|
73
|
+
msg[:recipients] = string_or_array_to_array(mail.to)
|
74
|
+
msg[:cc] = string_or_array_to_array(mail.cc)
|
75
|
+
msg[:bcc] = string_or_array_to_array(mail.bcc)
|
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
|
81
|
+
msg[:headers] = build_headers
|
82
|
+
msg[:content] = build_content
|
83
|
+
msg[:attachments] = build_attachments
|
84
|
+
msg
|
85
|
+
end
|
86
|
+
|
87
|
+
def convert_binary_to_base64(f)
|
88
|
+
file = Tempfile.new(encoding: 'ascii-8bit')
|
89
|
+
file.write(f)
|
90
|
+
file.rewind
|
91
|
+
Base64.encode64(file.read)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/paubox/message.rb
CHANGED
@@ -1,73 +1,98 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
def
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Paubox
|
4
|
+
# The Message class is for building a Paubox email message using a hash.
|
5
|
+
class Message
|
6
|
+
include Paubox::FormatHelper
|
7
|
+
attr_accessor :from, :to, :cc, :bcc, :subject, :reply_to, :text_content,
|
8
|
+
:html_content, :allow_non_tls, :force_secure_notification
|
9
|
+
|
10
|
+
def initialize(args)
|
11
|
+
@from = args[:from]
|
12
|
+
@to = args[:to]
|
13
|
+
@cc = args[:cc]
|
14
|
+
@bcc = args[:bcc]
|
15
|
+
@subject = args[:subject]
|
16
|
+
@reply_to = args[:reply_to]
|
17
|
+
@text_content = args[:text_content]
|
18
|
+
@html_content = args[:html_content]
|
19
|
+
@packaged_attachments = []
|
20
|
+
@attachments = build_attachments(args[:attachments])
|
21
|
+
@allow_non_tls = args.fetch(:allow_non_tls, false)
|
22
|
+
@force_secure_notification = args.fetch(:force_secure_notification, nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
def send_message_payload
|
26
|
+
{ data: { message: convert_keys_to_json_version(build_parts) } }.to_json
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_attachment(file_path)
|
30
|
+
@packaged_attachments << { filename: file_path.split('/').last,
|
31
|
+
content_type: `file --b --mime-type #{file_path}`.chomp,
|
32
|
+
content: Base64.encode64(File.read(file_path)) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def attachments
|
36
|
+
@packaged_attachments
|
37
|
+
end
|
38
|
+
|
39
|
+
def attachments=(args)
|
40
|
+
@attachments = build_attachments(args)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def build_attachments(args)
|
46
|
+
return (@packaged_attachments = []) if args.to_a.empty?
|
47
|
+
|
48
|
+
args.each do |a|
|
49
|
+
a[:content] = base64_encode_if_needed(a[:content])
|
50
|
+
@packaged_attachments << a
|
51
|
+
end
|
52
|
+
@packaged_attachments
|
53
|
+
end
|
54
|
+
|
55
|
+
def build_content
|
56
|
+
content = {}
|
57
|
+
content[:text_content] = text_content if text_content
|
58
|
+
content[:html_content] = base64_encode_if_needed(html_content) if html_content
|
59
|
+
content
|
60
|
+
end
|
61
|
+
|
62
|
+
def build_headers
|
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
|
80
|
+
end
|
81
|
+
|
82
|
+
def build_parts
|
83
|
+
msg = {}
|
84
|
+
msg[:recipients] = string_or_array_to_array(to)
|
85
|
+
msg[:cc] = string_or_array_to_array(cc)
|
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
|
91
|
+
msg[:bcc] = string_or_array_to_array(bcc)
|
92
|
+
msg[:headers] = build_headers
|
93
|
+
msg[:content] = build_content
|
94
|
+
msg[:attachments] = attachments
|
95
|
+
msg
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/paubox/version.rb
CHANGED
data/lib/paubox_ruby.rb
CHANGED
data/paubox_ruby.gemspec
CHANGED
@@ -1,32 +1,34 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
spec.
|
10
|
-
spec.
|
11
|
-
|
12
|
-
spec.
|
13
|
-
|
14
|
-
spec.
|
15
|
-
spec.
|
16
|
-
|
17
|
-
spec.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
spec.
|
23
|
-
spec.
|
24
|
-
spec.
|
25
|
-
spec.
|
26
|
-
spec.add_development_dependency '
|
27
|
-
spec.add_development_dependency '
|
28
|
-
spec.add_development_dependency '
|
29
|
-
|
30
|
-
spec.
|
31
|
-
|
32
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'paubox/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'paubox'
|
10
|
+
spec.version = Paubox::VERSION
|
11
|
+
spec.authors = ['Paubox', 'Jonathan Greeley']
|
12
|
+
spec.email = ['jon.r.greeley@gmail.com']
|
13
|
+
|
14
|
+
spec.summary = "Paubox's Official Ruby SDK"
|
15
|
+
spec.description = 'Ruby SDK for interacting with the Paubox Transactional Email HTTP API.'
|
16
|
+
spec.homepage = 'https://www.paubox.com'
|
17
|
+
spec.license = 'Apache-2.0'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
spec.required_ruby_version = '>= 2.3'
|
26
|
+
spec.add_development_dependency 'bundler', '~> 2.0.2'
|
27
|
+
spec.add_development_dependency 'pry'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
30
|
+
spec.add_development_dependency 'webmock', '~> 2.1'
|
31
|
+
|
32
|
+
spec.add_dependency 'mail', '>= 2.5'
|
33
|
+
spec.add_dependency 'rest-client', '~> 2.0', '>= 2.0.2'
|
34
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paubox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paubox
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-07-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -17,14 +17,28 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 2.0.2
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 2.0.2
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: pry
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: rake
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,20 +81,6 @@ dependencies:
|
|
67
81
|
- - "~>"
|
68
82
|
- !ruby/object:Gem::Version
|
69
83
|
version: '2.1'
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: pry
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '0'
|
77
|
-
type: :development
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - ">="
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: mail
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -160,8 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
160
|
- !ruby/object:Gem::Version
|
161
161
|
version: '0'
|
162
162
|
requirements: []
|
163
|
-
|
164
|
-
rubygems_version: 2.6.13
|
163
|
+
rubygems_version: 3.0.1
|
165
164
|
signing_key:
|
166
165
|
specification_version: 4
|
167
166
|
summary: Paubox's Official Ruby SDK
|