Skip to content

Commit 44c15ef

Browse files
committed
Deprecate Mailtrap::Mail::FromTemplate
1 parent 9429154 commit 44c15ef

File tree

4 files changed

+14
-37
lines changed

4 files changed

+14
-37
lines changed

lib/mailtrap/client.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,11 @@ def initialize( # rubocop:disable Metrics/ParameterLists
5454
end
5555

5656
# Sends an email
57-
# @param mail [Mail::Base] The email to send
58-
# @return [Hash, nil] The JSON response
57+
# @param mail [#to_json] The email to send
58+
# @return [Hash] The JSON response
5959
# @!macro api_errors
6060
# @raise [Mailtrap::MailSizeError] If the message is too large
61-
# @raise [ArgumentError] If the mail is not a Mail::Base object
6261
def send(mail)
63-
raise ArgumentError, 'should be Mailtrap::Mail::Base object' unless mail.is_a? Mail::Base
64-
6562
perform_request(:post, api_host, send_path, mail)
6663
end
6764

lib/mailtrap/mail/base.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
module Mailtrap
66
module Mail
77
class Base
8-
attr_accessor :from, :to, :reply_to, :cc, :bcc, :headers, :custom_variables, :subject, :text, :html, :category
8+
attr_accessor :from, :to, :reply_to, :cc, :bcc, :headers, :custom_variables, :subject, :text, :html, :category,
9+
:template_uuid, :template_variables
910
attr_reader :attachments
1011

1112
def initialize( # rubocop:disable Metrics/ParameterLists
@@ -20,7 +21,9 @@ def initialize( # rubocop:disable Metrics/ParameterLists
2021
attachments: [],
2122
headers: {},
2223
custom_variables: {},
23-
category: nil
24+
category: nil,
25+
template_uuid: nil,
26+
template_variables: nil
2427
)
2528
@from = from
2629
@to = to
@@ -34,6 +37,8 @@ def initialize( # rubocop:disable Metrics/ParameterLists
3437
@headers = headers
3538
@custom_variables = custom_variables
3639
@category = category
40+
@template_uuid = template_uuid
41+
@template_variables = template_variables
3742
end
3843

3944
def as_json
@@ -50,7 +55,9 @@ def as_json
5055
# TODO: update headers and custom_variables with as_json method
5156
'headers' => headers,
5257
'custom_variables' => custom_variables,
53-
'category' => category
58+
'category' => category,
59+
'template_uuid' => template_uuid,
60+
'template_variables' => template_variables
5461
}.compact
5562
end
5663

lib/mailtrap/mail/from_template.rb

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
module Mailtrap
44
module Mail
5+
# @deprecated Use Mailtrap::Mail::Base
56
class FromTemplate < Base
6-
attr_accessor :template_uuid, :template_variables
7-
87
def initialize( # rubocop:disable Metrics/ParameterLists
98
from: nil,
109
to: [],
@@ -17,27 +16,7 @@ def initialize( # rubocop:disable Metrics/ParameterLists
1716
template_uuid: nil,
1817
template_variables: {}
1918
)
20-
super(
21-
from:,
22-
to:,
23-
reply_to:,
24-
cc:,
25-
bcc:,
26-
attachments:,
27-
headers:,
28-
custom_variables:
29-
)
30-
@template_uuid = template_uuid
31-
@template_variables = template_variables
32-
end
33-
34-
def as_json
35-
super.merge(
36-
{
37-
'template_uuid' => template_uuid,
38-
'template_variables' => template_variables
39-
}
40-
).compact
19+
super
4120
end
4221
end
4322
end

spec/mailtrap/client_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@
5757
end
5858
end
5959

60-
context 'when mail object is not a Mailtrap::Mail::Base' do
61-
let(:mail) { 'it-a-string' }
62-
63-
it { expect { send }.to raise_error(ArgumentError, 'should be Mailtrap::Mail::Base object') }
64-
end
65-
6660
context 'with an alternative host' do
6761
let(:client) do
6862
described_class.new(api_key:, api_host: 'alternative.host.mailtrap.io', api_port: 8080)

0 commit comments

Comments
 (0)