mail_plugger 1.0.0.beta1

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.
@@ -0,0 +1,158 @@
1
+ ## Use MailPlugger in a Ruby script or IRB console
2
+
3
+ First you should be able to `require 'mail'` and `require 'mail_plugger'` to get started.
4
+
5
+ We need a class which will send the message in the right format via API.
6
+
7
+ ```ruby
8
+ # NOTE: This is just an example for testing...
9
+ class TestApiClientClass
10
+ def initialize(options = {})
11
+ @settings = { api_key: '12345' }
12
+ @options = options
13
+ end
14
+
15
+ def deliver
16
+ # e.g. API.new(@settings).client.post(generate_mail_hash)
17
+ puts " >>> settings: #{@settings.inspect}"
18
+ puts " >>> options: #{@options.inspect}"
19
+ puts " >>> generate_mail_hash: #{generate_mail_hash.inspect}"
20
+ { response: 'OK' }
21
+ end
22
+
23
+ private
24
+
25
+ def generate_mail_hash
26
+ {
27
+ to: generate_recipients,
28
+ from: {
29
+ email: @options[:from].first
30
+ },
31
+ subject: @options[:subject],
32
+ content: [
33
+ {
34
+ type: 'text/plain',
35
+ value: @options[:body]
36
+ }
37
+ ]
38
+ }
39
+ end
40
+
41
+ def generate_recipients
42
+ @options[:to].map do |to|
43
+ {
44
+ email: to
45
+ }
46
+ end
47
+ end
48
+ end
49
+ ```
50
+
51
+ We can use `MailPlugger.plug_in` to add our configurations.
52
+
53
+ ```ruby
54
+ MailPlugger.plug_in('test_api_client') do |api|
55
+ api.delivery_options = %i[from to subject body]
56
+ api.client = TestApiClientClass
57
+ end
58
+
59
+ message = Mail.new(from: 'from@example.com', to: 'to@example.com', subject: 'Test email', body: 'Test email body')
60
+ # => #<Mail::Message:1960, Multipart: false, Headers: <From: from@example.com>, <To: to@example.com>, <Subject: Tes...
61
+
62
+ MailPlugger::DeliveryMethod.new.deliver!(message)
63
+ # >>> settings: {:api_key=>"12345"}
64
+ # >>> options: {:from=>["from@example.com"], :to=>["to@example.com"], :subject=>"Test email", :body=>"Test email body"}
65
+ # >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body"}]}
66
+ # => {:response=>"OK"}
67
+ ```
68
+
69
+ Or we can use the `MailPlugger::DeliveryMethod` directly as well.
70
+
71
+ ```ruby
72
+ message = Mail.new(from: 'from@example.com', to: 'to@example.com', subject: 'Test email', body: 'Test email body')
73
+ # => #<Mail::Message:1960, Multipart: false, Headers: <From: from@example.com>, <To: to@example.com>, <Subject: Tes...
74
+
75
+ MailPlugger::DeliveryMethod.new(delivery_options: %i[from to subject body], client: TestApiClientClass).deliver!(message)
76
+ # >>> settings: {:api_key=>"12345"}
77
+ # >>> options: {:from=>["from@example.com"], :to=>["to@example.com"], :subject=>"Test email", :body=>"Test email body"}
78
+ # >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body"}]}
79
+ # => {:response=>"OK"}
80
+ ```
81
+
82
+ Or add `MailPlugger::DeliveryMethod` to `mail.delivery_method`.
83
+
84
+ ```ruby
85
+ mail = Mail.new(from: 'from@example.com', to: 'to@example.com', subject: 'Test email', body: 'Test email body')
86
+ # => #<Mail::Message:1960, Multipart: false, Headers: <From: from@example.com>, <To: to@example.com>, <Subject: Tes...
87
+
88
+ mail.delivery_method MailPlugger::DeliveryMethod, { delivery_options: %i[from to subject body], client: TestApiClientClass }
89
+ # => #<MailPlugger::DeliveryMethod:0x00007fecbbb2ca00 @delivery_options=[:from, :to, :subject, :body], @client=TestApiClientClass, @default_delivery_system=nil, @delivery_settings=nil, @message=nil>
90
+
91
+ mail.deliver
92
+ # >>> settings: {:api_key=>"12345"}
93
+ # >>> options: {:from=>["from@example.com"], :to=>["to@example.com"], :subject=>"Test email", :body=>"Test email body"}
94
+ # >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body"}]}
95
+ # => #<Mail::Message:1960, Multipart: false, Headers: <From: from@example.com>, <To: to@example.com>, <Subject: Test email>>
96
+
97
+ # or
98
+
99
+ mail.deliver!
100
+ # >>> settings: {:api_key=>"12345"}
101
+ # >>> options: {:from=>["from@example.com"], :to=>["to@example.com"], :subject=>"Test email", :body=>"Test email body"}
102
+ # >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body"}]}
103
+ # => #<Mail::Message:1960, Multipart: false, Headers: <From: from@example.com>, <To: to@example.com>, <Subject: Test email>>
104
+ ```
105
+
106
+ Let's add delivery settings to the delivery method.
107
+
108
+ ```ruby
109
+ mail = Mail.new(from: 'from@example.com', to: 'to@example.com', subject: 'Test email', body: 'Test email body')
110
+ # => #<Mail::Message:1960, Multipart: false, Headers: <From: from@example.com>, <To: to@example.com>, <Subject: Tes...
111
+
112
+ mail.delivery_method MailPlugger::DeliveryMethod, { delivery_options: %i[from to subject body], client: TestApiClientClass, delivery_settings: { return_response: true } }
113
+ # => #<MailPlugger::DeliveryMethod:0x00007fecbb9e3630 @delivery_options=[:from, :to, :subject, :body], @client=TestApiClientClass, @default_delivery_system=nil, @delivery_settings={:return_response=>true}, @message=nil>
114
+
115
+ mail.deliver
116
+ # >>> settings: {:api_key=>"12345"}
117
+ # >>> options: {:from=>["from@example.com"], :to=>["to@example.com"], :subject=>"Test email", :body=>"Test email body"}
118
+ # >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body"}]}
119
+ # => #<Mail::Message:1960, Multipart: false, Headers: <From: from@example.com>, <To: to@example.com>, <Subject: Test email>>
120
+
121
+ # or
122
+
123
+ mail.deliver!
124
+ # >>> settings: {:api_key=>"12345"}
125
+ # >>> options: {:from=>["from@example.com"], :to=>["to@example.com"], :subject=>"Test email", :body=>"Test email body"}
126
+ # >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body"}]}
127
+ # => {:response=>"OK"}
128
+ ```
129
+
130
+ Let's use `MailPlugger.plug_in` method.
131
+
132
+ ```ruby
133
+ MailPlugger.plug_in('test_api_client') do |api|
134
+ api.delivery_options = %i[from to subject body]
135
+ api.delivery_settings = { return_response: true }
136
+ api.client = TestApiClientClass
137
+ end
138
+
139
+ mail = Mail.new(from: 'from@example.com', to: 'to@example.com', subject: 'Test email', body: 'Test email body')
140
+ # => #<Mail::Message:1960, Multipart: false, Headers: <From: from@example.com>, <To: to@example.com>, <Subject: Tes...
141
+
142
+ mail.delivery_method MailPlugger::DeliveryMethod
143
+ # => #<MailPlugger::DeliveryMethod:0x00007ffed930b8f0 @delivery_options={"test_api_client"=>[:from, :to, :subject, :body]}, @client={"test_api_client"=>TestApiClientClass}, @default_delivery_system="test_api_client", @delivery_settings={"test_api_client"=>{:return_response=>true}}, @message=nil>
144
+
145
+ mail.deliver
146
+ # >>> settings: {:api_key=>"12345"}
147
+ # >>> options: {:from=>["from@example.com"], :to=>["to@example.com"], :subject=>"Test email", :body=>"Test email body"}
148
+ # >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body"}]}
149
+ # => #<Mail::Message:1960, Multipart: false, Headers: <From: from@example.com>, <To: to@example.com>, <Subject: Test email>>
150
+
151
+ # or
152
+
153
+ mail.deliver!
154
+ # >>> settings: {:api_key=>"12345"}
155
+ # >>> options: {:from=>["from@example.com"], :to=>["to@example.com"], :subject=>"Test email", :body=>"Test email body"}
156
+ # >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body"}]}
157
+ # => {:response=>"OK"}
158
+ ```
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,15 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "rake", "~> 13.0"
7
+ gem "rubocop", "~> 1.7", require: false
8
+ gem "rubocop-performance", require: false
9
+ gem "rubocop-rspec", require: false
10
+ gem "rspec", "~> 3.0"
11
+ gem "simplecov", require: false
12
+ gem "webmock", "~> 3.0"
13
+ gem "mail", "~> 2.6.0"
14
+
15
+ gemspec path: "../"
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ mail_plugger (0.1.0)
5
+ mail (~> 2.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ appraisal (2.3.0)
13
+ bundler
14
+ rake
15
+ thor (>= 0.14.0)
16
+ ast (2.4.1)
17
+ crack (0.4.5)
18
+ rexml
19
+ diff-lcs (1.4.4)
20
+ docile (1.3.4)
21
+ hashdiff (1.0.1)
22
+ mail (2.6.6)
23
+ mime-types (>= 1.16, < 4)
24
+ mime-types (3.3.1)
25
+ mime-types-data (~> 3.2015)
26
+ mime-types-data (3.2020.1104)
27
+ parallel (1.20.1)
28
+ parser (3.0.0.0)
29
+ ast (~> 2.4.1)
30
+ public_suffix (4.0.6)
31
+ rainbow (3.0.0)
32
+ rake (13.0.3)
33
+ regexp_parser (2.0.3)
34
+ rexml (3.2.4)
35
+ rspec (3.10.0)
36
+ rspec-core (~> 3.10.0)
37
+ rspec-expectations (~> 3.10.0)
38
+ rspec-mocks (~> 3.10.0)
39
+ rspec-core (3.10.1)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-expectations (3.10.1)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-mocks (3.10.1)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.10.0)
47
+ rspec-support (3.10.1)
48
+ rubocop (1.7.0)
49
+ parallel (~> 1.10)
50
+ parser (>= 2.7.1.5)
51
+ rainbow (>= 2.2.2, < 4.0)
52
+ regexp_parser (>= 1.8, < 3.0)
53
+ rexml
54
+ rubocop-ast (>= 1.2.0, < 2.0)
55
+ ruby-progressbar (~> 1.7)
56
+ unicode-display_width (>= 1.4.0, < 2.0)
57
+ rubocop-ast (1.3.0)
58
+ parser (>= 2.7.1.5)
59
+ rubocop-performance (1.9.2)
60
+ rubocop (>= 0.90.0, < 2.0)
61
+ rubocop-ast (>= 0.4.0)
62
+ rubocop-rspec (2.1.0)
63
+ rubocop (~> 1.0)
64
+ rubocop-ast (>= 1.1.0)
65
+ ruby-progressbar (1.11.0)
66
+ simplecov (0.20.0)
67
+ docile (~> 1.1)
68
+ simplecov-html (~> 0.11)
69
+ simplecov_json_formatter (~> 0.1)
70
+ simplecov-html (0.12.3)
71
+ simplecov_json_formatter (0.1.2)
72
+ thor (1.0.1)
73
+ unicode-display_width (1.7.0)
74
+ webmock (3.11.0)
75
+ addressable (>= 2.3.6)
76
+ crack (>= 0.3.2)
77
+ hashdiff (>= 0.4.0, < 2.0.0)
78
+
79
+ PLATFORMS
80
+ ruby
81
+
82
+ DEPENDENCIES
83
+ appraisal
84
+ mail (~> 2.6.0)
85
+ mail_plugger!
86
+ rake (~> 13.0)
87
+ rspec (~> 3.0)
88
+ rubocop (~> 1.7)
89
+ rubocop-performance
90
+ rubocop-rspec
91
+ simplecov
92
+ webmock (~> 3.0)
93
+
94
+ BUNDLED WITH
95
+ 2.2.3
@@ -0,0 +1,15 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "rake", "~> 13.0"
7
+ gem "rubocop", "~> 1.7", require: false
8
+ gem "rubocop-performance", require: false
9
+ gem "rubocop-rspec", require: false
10
+ gem "rspec", "~> 3.0"
11
+ gem "simplecov", require: false
12
+ gem "webmock", "~> 3.0"
13
+ gem "mail", "2.7.0"
14
+
15
+ gemspec path: "../"
@@ -0,0 +1,93 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ mail_plugger (0.1.0)
5
+ mail (~> 2.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ appraisal (2.3.0)
13
+ bundler
14
+ rake
15
+ thor (>= 0.14.0)
16
+ ast (2.4.1)
17
+ crack (0.4.5)
18
+ rexml
19
+ diff-lcs (1.4.4)
20
+ docile (1.3.4)
21
+ hashdiff (1.0.1)
22
+ mail (2.7.0)
23
+ mini_mime (>= 0.1.1)
24
+ mini_mime (1.0.2)
25
+ parallel (1.20.1)
26
+ parser (3.0.0.0)
27
+ ast (~> 2.4.1)
28
+ public_suffix (4.0.6)
29
+ rainbow (3.0.0)
30
+ rake (13.0.3)
31
+ regexp_parser (2.0.3)
32
+ rexml (3.2.4)
33
+ rspec (3.10.0)
34
+ rspec-core (~> 3.10.0)
35
+ rspec-expectations (~> 3.10.0)
36
+ rspec-mocks (~> 3.10.0)
37
+ rspec-core (3.10.1)
38
+ rspec-support (~> 3.10.0)
39
+ rspec-expectations (3.10.1)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.10.0)
42
+ rspec-mocks (3.10.1)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.10.0)
45
+ rspec-support (3.10.1)
46
+ rubocop (1.7.0)
47
+ parallel (~> 1.10)
48
+ parser (>= 2.7.1.5)
49
+ rainbow (>= 2.2.2, < 4.0)
50
+ regexp_parser (>= 1.8, < 3.0)
51
+ rexml
52
+ rubocop-ast (>= 1.2.0, < 2.0)
53
+ ruby-progressbar (~> 1.7)
54
+ unicode-display_width (>= 1.4.0, < 2.0)
55
+ rubocop-ast (1.3.0)
56
+ parser (>= 2.7.1.5)
57
+ rubocop-performance (1.9.2)
58
+ rubocop (>= 0.90.0, < 2.0)
59
+ rubocop-ast (>= 0.4.0)
60
+ rubocop-rspec (2.1.0)
61
+ rubocop (~> 1.0)
62
+ rubocop-ast (>= 1.1.0)
63
+ ruby-progressbar (1.11.0)
64
+ simplecov (0.20.0)
65
+ docile (~> 1.1)
66
+ simplecov-html (~> 0.11)
67
+ simplecov_json_formatter (~> 0.1)
68
+ simplecov-html (0.12.3)
69
+ simplecov_json_formatter (0.1.2)
70
+ thor (1.0.1)
71
+ unicode-display_width (1.7.0)
72
+ webmock (3.11.0)
73
+ addressable (>= 2.3.6)
74
+ crack (>= 0.3.2)
75
+ hashdiff (>= 0.4.0, < 2.0.0)
76
+
77
+ PLATFORMS
78
+ ruby
79
+
80
+ DEPENDENCIES
81
+ appraisal
82
+ mail (= 2.7.0)
83
+ mail_plugger!
84
+ rake (~> 13.0)
85
+ rspec (~> 3.0)
86
+ rubocop (~> 1.7)
87
+ rubocop-performance
88
+ rubocop-rspec
89
+ simplecov
90
+ webmock (~> 3.0)
91
+
92
+ BUNDLED WITH
93
+ 2.2.3
@@ -0,0 +1,15 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "rake", "~> 13.0"
7
+ gem "rubocop", "~> 1.7", require: false
8
+ gem "rubocop-performance", require: false
9
+ gem "rubocop-rspec", require: false
10
+ gem "rspec", "~> 3.0"
11
+ gem "simplecov", require: false
12
+ gem "webmock", "~> 3.0"
13
+ gem "mail", "~> 2.7.0"
14
+
15
+ gemspec path: "../"
@@ -0,0 +1,93 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ mail_plugger (0.1.0)
5
+ mail (~> 2.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ appraisal (2.3.0)
13
+ bundler
14
+ rake
15
+ thor (>= 0.14.0)
16
+ ast (2.4.1)
17
+ crack (0.4.5)
18
+ rexml
19
+ diff-lcs (1.4.4)
20
+ docile (1.3.4)
21
+ hashdiff (1.0.1)
22
+ mail (2.7.1)
23
+ mini_mime (>= 0.1.1)
24
+ mini_mime (1.0.2)
25
+ parallel (1.20.1)
26
+ parser (3.0.0.0)
27
+ ast (~> 2.4.1)
28
+ public_suffix (4.0.6)
29
+ rainbow (3.0.0)
30
+ rake (13.0.3)
31
+ regexp_parser (2.0.3)
32
+ rexml (3.2.4)
33
+ rspec (3.10.0)
34
+ rspec-core (~> 3.10.0)
35
+ rspec-expectations (~> 3.10.0)
36
+ rspec-mocks (~> 3.10.0)
37
+ rspec-core (3.10.1)
38
+ rspec-support (~> 3.10.0)
39
+ rspec-expectations (3.10.1)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.10.0)
42
+ rspec-mocks (3.10.1)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.10.0)
45
+ rspec-support (3.10.1)
46
+ rubocop (1.7.0)
47
+ parallel (~> 1.10)
48
+ parser (>= 2.7.1.5)
49
+ rainbow (>= 2.2.2, < 4.0)
50
+ regexp_parser (>= 1.8, < 3.0)
51
+ rexml
52
+ rubocop-ast (>= 1.2.0, < 2.0)
53
+ ruby-progressbar (~> 1.7)
54
+ unicode-display_width (>= 1.4.0, < 2.0)
55
+ rubocop-ast (1.3.0)
56
+ parser (>= 2.7.1.5)
57
+ rubocop-performance (1.9.2)
58
+ rubocop (>= 0.90.0, < 2.0)
59
+ rubocop-ast (>= 0.4.0)
60
+ rubocop-rspec (2.1.0)
61
+ rubocop (~> 1.0)
62
+ rubocop-ast (>= 1.1.0)
63
+ ruby-progressbar (1.11.0)
64
+ simplecov (0.20.0)
65
+ docile (~> 1.1)
66
+ simplecov-html (~> 0.11)
67
+ simplecov_json_formatter (~> 0.1)
68
+ simplecov-html (0.12.3)
69
+ simplecov_json_formatter (0.1.2)
70
+ thor (1.0.1)
71
+ unicode-display_width (1.7.0)
72
+ webmock (3.11.0)
73
+ addressable (>= 2.3.6)
74
+ crack (>= 0.3.2)
75
+ hashdiff (>= 0.4.0, < 2.0.0)
76
+
77
+ PLATFORMS
78
+ ruby
79
+
80
+ DEPENDENCIES
81
+ appraisal
82
+ mail (~> 2.7.0)
83
+ mail_plugger!
84
+ rake (~> 13.0)
85
+ rspec (~> 3.0)
86
+ rubocop (~> 1.7)
87
+ rubocop-performance
88
+ rubocop-rspec
89
+ simplecov
90
+ webmock (~> 3.0)
91
+
92
+ BUNDLED WITH
93
+ 2.2.3