mail_plugger 1.0.1 → 1.1.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 +4 -4
- data/CHANGELOG.md +23 -1
- data/README.md +10 -2
- data/lib/fake_plugger/delivery_method.rb +162 -0
- data/lib/fake_plugger/railtie.rb +14 -0
- data/lib/mail_plugger.rb +9 -1
- data/lib/mail_plugger/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ae30c8103f7eecb765d0e08984c79c39b116781adebbbc31bb1c56e0aac2273
|
4
|
+
data.tar.gz: 3cd75d6aabb8a301f0def36fdfd77f1d624a8c15d7ad60bcc5c60174392e2185
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed702bc39827fbe0afdaa6db1737367fb8bf329aa096dcd1092109673eea45f6fdb1b84a8eb0da0fd8283724ac57f9eae2ae44607a156a6025c6de661aeb0fbf
|
7
|
+
data.tar.gz: df3d125a0342d83a0e19802dcfcb3a0ac7f2c682b9de733d2c53cb81da11d6a0f04df828113912eee1f991d8b45cf720e4503f57f494ffcfcf0283895ea86257
|
data/CHANGELOG.md
CHANGED
@@ -1,28 +1,50 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
|
4
|
+
## 1.1.0 (2021-01-18)
|
5
|
+
|
6
|
+
### New features
|
7
|
+
|
8
|
+
* Add FakePlugger to mock MailPlugger.
|
9
|
+
|
10
|
+
### Changes
|
11
|
+
|
12
|
+
* Fix typos in the documentations.
|
13
|
+
* Add more metadata to gempspec file.
|
14
|
+
|
15
|
+
|
3
16
|
## 1.0.1 (2021-01-15)
|
4
17
|
|
18
|
+
### Changes
|
19
|
+
|
5
20
|
* Tidy up the gemspec file and change which files contains in the gem. Now the gem is much smaller.
|
6
21
|
* Add a new mail plugger image which has a different canvas and use it in the README.md.
|
7
22
|
|
23
|
+
|
8
24
|
## 1.0.0 (2021-01-14)
|
9
25
|
|
26
|
+
### Changes
|
27
|
+
|
10
28
|
* Update gems.
|
11
29
|
* Remove `webmock` gem to clean up unused things.
|
12
30
|
* Update documentations.
|
13
31
|
|
32
|
+
|
14
33
|
## 1.0.0.rc1 (2021-01-13)
|
15
34
|
|
35
|
+
### Changes
|
36
|
+
|
16
37
|
* Change description and fix changelog_uri in gemspec file.
|
17
38
|
* Add/Change documentations.
|
18
39
|
* Update gems.
|
19
40
|
* Change `MailPlugger.plug_in` and `MailPlugger::MailHelper.delivery_options` methods to accept strings and symbols.
|
20
|
-
* Change `MailPlugger::MailHelper.delivery_data` method that we can retrieve
|
41
|
+
* Change `MailPlugger::MailHelper.delivery_data` method that we can retrieve message object as well.
|
21
42
|
* Check hash keys in `MailPlugger::MailHelper.delivery_system` method, so now if we are add wrong `delivey_system` then we are getting a meaningful error message.
|
22
43
|
* Change `MailPlugger::MailHelper.extract_attachments` method. If an attachment is inline then the hash contains the `filename` and `cid` as well.
|
23
44
|
* Add/Change tests.
|
24
45
|
* Change `MailPlugger::MailHelper.delivery_option` that returns with indifferent hash
|
25
46
|
|
47
|
+
|
26
48
|
## 1.0.0.beta1 (2021-01-02)
|
27
49
|
|
28
50
|
* Implement MailPlugger methods and functionality. See [README.md](https://github.com/norbertszivos/mail_plugger/blob/main/README.md)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# M<img src="https://raw.githubusercontent.com/norbertszivos/mail_plugger/
|
1
|
+
# M<img src="https://raw.githubusercontent.com/norbertszivos/mail_plugger/main/images/mail_plugger800x500.png" height="22" />ilPlugger
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/mail_plugger)
|
4
4
|
[](LICENSE.txt)
|
@@ -31,7 +31,7 @@ Or install it yourself as:
|
|
31
31
|
- [How to use MailPlugger::DeliveryMethod class](https://github.com/norbertszivos/mail_plugger/blob/main/docs/usage_of_delivery_method.md)
|
32
32
|
- [How to use MailPlugger in a Ruby script or IRB console](https://github.com/norbertszivos/mail_plugger/blob/main/docs/usage_in_script_or_console.md)
|
33
33
|
- [How to use MailPlugger in Ruby on Rails](https://github.com/norbertszivos/mail_plugger/blob/main/docs/usage_in_ruby_on_rails.md)
|
34
|
-
- [How to add API specific options to the mailer method in Ruby on Rails](https://github.com/norbertszivos/mail_plugger/blob/main/docs/
|
34
|
+
- [How to add API specific options to the mailer method in Ruby on Rails](https://github.com/norbertszivos/mail_plugger/blob/main/docs/usage_of_special_options_in_ruby_on_rails.md)
|
35
35
|
- [How to add attachments to the mailer method in Ruby on Rails](https://github.com/norbertszivos/mail_plugger/blob/main/docs/usage_of_attachments_in_ruby_on_rails.md)
|
36
36
|
- [How to use more delivey systems in Ruby on Rails](https://github.com/norbertszivos/mail_plugger/blob/main/docs/usage_of_more_delivery_system_in_ruby_on_rails.md)
|
37
37
|
- [How to use one delivey system with more send methods in Ruby on Rails](https://github.com/norbertszivos/mail_plugger/blob/main/docs/usage_of_one_delivery_system_with_more_send_methods_in_ruby_on_rails.md)
|
@@ -42,6 +42,14 @@ Or install it yourself as:
|
|
42
42
|
- [How to use Postmark with MailPlugger in Ruby on Rails](https://github.com/norbertszivos/mail_plugger/blob/main/docs/usage_of_postmark_in_ruby_on_rails.md)
|
43
43
|
- [How to use Mailgun with MailPlugger in Ruby on Rails](https://github.com/norbertszivos/mail_plugger/blob/main/docs/usage_of_mailgun_in_ruby_on_rails.md)
|
44
44
|
|
45
|
+
# F<img src="https://raw.githubusercontent.com/norbertszivos/mail_plugger/main/images/fake_plugger800x500.png" height="22" />kePlugger
|
46
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
- [How to use FakePlugger::DeliveryMethod class](https://github.com/norbertszivos/mail_plugger/blob/main/docs/usage_of_fake_plugger_delivery_method.md)
|
50
|
+
- [How to use FakePlugger in a Ruby script or IRB console](https://github.com/norbertszivos/mail_plugger/blob/main/docs/usage_of_fake_plugger_in_script_or_console.md)
|
51
|
+
- [How to use FakePlugger in Ruby on Rails](https://github.com/norbertszivos/mail_plugger/blob/main/docs/usage_of_fake_plugger_in_ruby_on_rails.md)
|
52
|
+
|
45
53
|
## Development
|
46
54
|
|
47
55
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,162 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FakePlugger
|
4
|
+
class DeliveryMethod < MailPlugger::DeliveryMethod
|
5
|
+
# Initialize FakePlugger delivery method attributes. If we are using
|
6
|
+
# MailPlugger.plug_in method, then these attributes can be nil, if not then
|
7
|
+
# we should set these attributes.
|
8
|
+
#
|
9
|
+
# @param [Hash] options check options below
|
10
|
+
# @option options [Class/Hash] client
|
11
|
+
# e.g. DefinedApiClientClass or { 'key' => DefinedApiClientClass }
|
12
|
+
#
|
13
|
+
# @option options [Array/Hash] delivery_options
|
14
|
+
# e.g. [:to, :from, :subject, :body] or
|
15
|
+
# { 'key' => [:to, :from, :subject, :body] }
|
16
|
+
#
|
17
|
+
# @option options [Hash] delivery_settings
|
18
|
+
# e.g. { return_response: true }
|
19
|
+
#
|
20
|
+
# @option options [String/Symbol] default_delivery_system
|
21
|
+
# e.g. 'defined_api'
|
22
|
+
#
|
23
|
+
# @option options [Boolean] debug
|
24
|
+
# if true it will show debug informations
|
25
|
+
#
|
26
|
+
# @option options [Boolean] raw_message
|
27
|
+
# if true it will show raw message
|
28
|
+
#
|
29
|
+
# @option options [String/Symbol/Array/Hash] response
|
30
|
+
# the deliver! method will return with this value or if this value is nil
|
31
|
+
# then it will return with the client object
|
32
|
+
def initialize(options = {})
|
33
|
+
super
|
34
|
+
|
35
|
+
@debug = options[:debug] || settings[:fake_plugger_debug] || false
|
36
|
+
@raw_message = options[:raw_message] ||
|
37
|
+
settings[:fake_plugger_raw_message] || false
|
38
|
+
@response = options[:response] || settings[:fake_plugger_response]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Mock send message with the given client if the message parameter is a
|
42
|
+
# Mail::Message object. If 'response' parameter is nil then it will extract
|
43
|
+
# those information from the Mail::Message object which was provided in the
|
44
|
+
# 'delivery_options'. After that it generates a hash with these data and
|
45
|
+
# returns with the provided client class which has a 'deliver' method, but
|
46
|
+
# it won't call the 'deliver' method.
|
47
|
+
# If the 'response' parameter is a hash with 'return_message_obj: true' then
|
48
|
+
# it will retrun with the Mail::Message object.
|
49
|
+
# If the 'response' parameter is not nil then retruns with that given data
|
50
|
+
# without call any other methods.
|
51
|
+
# Except if 'debug' is true. In this case it will call those methods which
|
52
|
+
# is calling in normal operation as well.
|
53
|
+
# If 'debug' is true then it prints out some debug informations.
|
54
|
+
# If 'raw_message' is true then it prints out raw message.
|
55
|
+
#
|
56
|
+
# @param [Mail::Message] message what we would like to send
|
57
|
+
#
|
58
|
+
# @return [Mail::Message/Hash] depend on give value
|
59
|
+
#
|
60
|
+
# @example
|
61
|
+
#
|
62
|
+
# MailPlugger.plug_in('test_api_client') do |api|
|
63
|
+
# api.delivery_options = %i[from to subject body]
|
64
|
+
# api.delivery_settings = {
|
65
|
+
# fake_plugger_debug: true,
|
66
|
+
# fake_plugger_raw_message: true,
|
67
|
+
# fake_plugger_response: { response: 'OK' }
|
68
|
+
# }
|
69
|
+
# api.client = DefinedApiClientClass
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# message = Mail.new(from: 'from@example.com', to: 'to@example.com',
|
73
|
+
# subject: 'Test email', body: 'Test email body')
|
74
|
+
#
|
75
|
+
# FakePlugger::DeliveryMethod.new.deliver!(message)
|
76
|
+
#
|
77
|
+
# # or
|
78
|
+
#
|
79
|
+
# message = Mail.new(from: 'from@example.com', to: 'to@example.com',
|
80
|
+
# subject: 'Test email', body: 'Test email body')
|
81
|
+
#
|
82
|
+
# FakePlugger::DeliveryMethod.new(
|
83
|
+
# delivery_options: %i[from to subject body],
|
84
|
+
# client: DefinedApiClientClass,
|
85
|
+
# debug: true,
|
86
|
+
# raw_message: true,
|
87
|
+
# response: { response: 'OK' }
|
88
|
+
# ).deliver!(message)
|
89
|
+
#
|
90
|
+
def deliver!(message)
|
91
|
+
unless message.is_a?(Mail::Message)
|
92
|
+
raise MailPlugger::Error::WrongParameter,
|
93
|
+
'The given parameter is not a Mail::Message'
|
94
|
+
end
|
95
|
+
|
96
|
+
@message = message
|
97
|
+
|
98
|
+
show_debug_info if @debug
|
99
|
+
show_raw_message if @raw_message
|
100
|
+
|
101
|
+
return_with_response
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
# Return with a response which depends on the conditions.
|
107
|
+
def return_with_response
|
108
|
+
return client.new(delivery_data) if @response.nil?
|
109
|
+
return @message if @response.is_a?(Hash) && @response[:return_message_obj]
|
110
|
+
|
111
|
+
@response
|
112
|
+
end
|
113
|
+
|
114
|
+
# Show debug informations from variables and methods.
|
115
|
+
def show_debug_info
|
116
|
+
puts <<~DEBUG_INFO
|
117
|
+
|
118
|
+
===================== FakePlugger::DeliveryMethod =====================
|
119
|
+
|
120
|
+
------------------------------ Variables ------------------------------
|
121
|
+
|
122
|
+
==> @client: #{@client.inspect}
|
123
|
+
|
124
|
+
==> @delivery_options: #{@delivery_options.inspect}"
|
125
|
+
|
126
|
+
==> @delivery_settings: #{@delivery_settings.inspect}"
|
127
|
+
|
128
|
+
==> @default_delivery_system: #{@default_delivery_system.inspect}
|
129
|
+
|
130
|
+
==> @message: #{@message.inspect}
|
131
|
+
|
132
|
+
------------------------------- Methods -------------------------------
|
133
|
+
|
134
|
+
==> client: #{client.inspect}
|
135
|
+
|
136
|
+
==> delivery_system: #{delivery_system.inspect}
|
137
|
+
|
138
|
+
==> delivery_options: #{delivery_options.inspect}
|
139
|
+
|
140
|
+
==> delivery_data: #{delivery_data.inspect}
|
141
|
+
|
142
|
+
==> settings: #{settings.inspect}
|
143
|
+
|
144
|
+
=======================================================================
|
145
|
+
|
146
|
+
DEBUG_INFO
|
147
|
+
end
|
148
|
+
|
149
|
+
# Show raw message for debug purpose.
|
150
|
+
def show_raw_message
|
151
|
+
puts <<~RAW_MESSAGE
|
152
|
+
|
153
|
+
============================ Mail::Message ============================
|
154
|
+
|
155
|
+
#{@message}
|
156
|
+
|
157
|
+
=======================================================================
|
158
|
+
|
159
|
+
RAW_MESSAGE
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FakePlugger
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
initializer 'fake_plugger.add_delivery_method' do
|
6
|
+
ActiveSupport.on_load :action_mailer do
|
7
|
+
ActionMailer::Base.add_delivery_method(
|
8
|
+
:fake_plugger,
|
9
|
+
FakePlugger::DeliveryMethod
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/mail_plugger.rb
CHANGED
@@ -7,6 +7,10 @@ require 'mail_plugger/delivery_method'
|
|
7
7
|
require 'mail_plugger/railtie' if defined?(Rails)
|
8
8
|
require 'mail_plugger/version'
|
9
9
|
|
10
|
+
require 'fake_plugger/delivery_method'
|
11
|
+
# If we are using this gem outside of Rails then do not load this code.
|
12
|
+
require 'fake_plugger/railtie' if defined?(Rails)
|
13
|
+
|
10
14
|
module MailPlugger
|
11
15
|
class << self
|
12
16
|
attr_reader :client, :delivery_options, :delivery_settings
|
@@ -17,7 +21,7 @@ module MailPlugger
|
|
17
21
|
#
|
18
22
|
# @example using Rails `config/initializers/mail_plugger.rb`
|
19
23
|
#
|
20
|
-
# # The defined API class should have an '
|
24
|
+
# # The defined API class should have an 'initialize' and a 'deliver'
|
21
25
|
# # method.
|
22
26
|
# class DefinedApiClientClass
|
23
27
|
# def initialize(options = {})
|
@@ -90,6 +94,10 @@ module MailPlugger
|
|
90
94
|
|
91
95
|
private
|
92
96
|
|
97
|
+
# Check 'delivery_system' is valid or not. If it's not valid then
|
98
|
+
# it will raise an error.
|
99
|
+
#
|
100
|
+
# @param [String/Symbol] delivery_system the name of the API
|
93
101
|
def check_value(delivery_system)
|
94
102
|
if delivery_system.nil?
|
95
103
|
raise Error::WrongDeliverySystem, '"delivery_system" is nil'
|
data/lib/mail_plugger/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail_plugger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Norbert Szivós
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
@@ -37,6 +37,8 @@ files:
|
|
37
37
|
- CHANGELOG.md
|
38
38
|
- LICENSE.txt
|
39
39
|
- README.md
|
40
|
+
- lib/fake_plugger/delivery_method.rb
|
41
|
+
- lib/fake_plugger/railtie.rb
|
40
42
|
- lib/mail_plugger.rb
|
41
43
|
- lib/mail_plugger/delivery_method.rb
|
42
44
|
- lib/mail_plugger/error.rb
|
@@ -50,6 +52,8 @@ metadata:
|
|
50
52
|
homepage_uri: https://github.com/norbertszivos/mail_plugger
|
51
53
|
source_code_uri: https://github.com/norbertszivos/mail_plugger
|
52
54
|
changelog_uri: https://github.com/norbertszivos/mail_plugger/blob/main/CHANGELOG.md
|
55
|
+
bug_tracker_uri: https://github.com/norbertszivos/mail_plugger/issues
|
56
|
+
documentation_uri: https://rubydoc.info/gems/mail_plugger
|
53
57
|
post_install_message:
|
54
58
|
rdoc_options: []
|
55
59
|
require_paths:
|