Class: Mailtrap::Mail::Base
- Inherits:
-
Object
- Object
- Mailtrap::Mail::Base
- Defined in:
- lib/mailtrap/mail/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attachments ⇒ Object
Returns the value of attribute attachments.
-
#bcc ⇒ Object
Returns the value of attribute bcc.
-
#category ⇒ Object
Returns the value of attribute category.
-
#cc ⇒ Object
Returns the value of attribute cc.
-
#custom_variables ⇒ Object
Returns the value of attribute custom_variables.
-
#from ⇒ Object
Returns the value of attribute from.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#html ⇒ Object
Returns the value of attribute html.
-
#reply_to ⇒ Object
Returns the value of attribute reply_to.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#template_uuid ⇒ Object
Returns the value of attribute template_uuid.
-
#template_variables ⇒ Object
Returns the value of attribute template_variables.
-
#text ⇒ Object
Returns the value of attribute text.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #add_attachment(content:, filename:, type: nil, disposition: nil, content_id: nil) ⇒ Object
- #as_json ⇒ Object
-
#initialize(from: nil, to: [], reply_to: nil, cc: [], bcc: [], subject: nil, text: nil, html: nil, attachments: [], headers: {}, custom_variables: {}, category: nil, template_uuid: nil, template_variables: {}) ⇒ Base
constructor
rubocop:disable Metrics/ParameterLists.
- #presence(value) ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(from: nil, to: [], reply_to: nil, cc: [], bcc: [], subject: nil, text: nil, html: nil, attachments: [], headers: {}, custom_variables: {}, category: nil, template_uuid: nil, template_variables: {}) ⇒ Base
rubocop:disable Metrics/ParameterLists
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 |
# File 'lib/mailtrap/mail/base.rb', line 12 def initialize( # rubocop:disable Metrics/ParameterLists from: nil, to: [], reply_to: nil, cc: [], bcc: [], subject: nil, text: nil, html: nil, attachments: [], headers: {}, custom_variables: {}, category: nil, template_uuid: nil, template_variables: {} ) @from = from @to = to @reply_to = reply_to @cc = cc @bcc = bcc @subject = subject @text = text @html = html self. = @headers = headers @custom_variables = custom_variables @category = category @template_uuid = template_uuid @template_variables = template_variables end |
Instance Attribute Details
#attachments ⇒ Object
Returns the value of attribute attachments.
10 11 12 |
# File 'lib/mailtrap/mail/base.rb', line 10 def end |
#bcc ⇒ Object
Returns the value of attribute bcc.
8 9 10 |
# File 'lib/mailtrap/mail/base.rb', line 8 def bcc @bcc end |
#category ⇒ Object
Returns the value of attribute category.
8 9 10 |
# File 'lib/mailtrap/mail/base.rb', line 8 def category @category end |
#cc ⇒ Object
Returns the value of attribute cc.
8 9 10 |
# File 'lib/mailtrap/mail/base.rb', line 8 def cc @cc end |
#custom_variables ⇒ Object
Returns the value of attribute custom_variables.
8 9 10 |
# File 'lib/mailtrap/mail/base.rb', line 8 def custom_variables @custom_variables end |
#from ⇒ Object
Returns the value of attribute from.
8 9 10 |
# File 'lib/mailtrap/mail/base.rb', line 8 def from @from end |
#headers ⇒ Object
Returns the value of attribute headers.
8 9 10 |
# File 'lib/mailtrap/mail/base.rb', line 8 def headers @headers end |
#html ⇒ Object
Returns the value of attribute html.
8 9 10 |
# File 'lib/mailtrap/mail/base.rb', line 8 def html @html end |
#reply_to ⇒ Object
Returns the value of attribute reply_to.
8 9 10 |
# File 'lib/mailtrap/mail/base.rb', line 8 def reply_to @reply_to end |
#subject ⇒ Object
Returns the value of attribute subject.
8 9 10 |
# File 'lib/mailtrap/mail/base.rb', line 8 def subject @subject end |
#template_uuid ⇒ Object
Returns the value of attribute template_uuid.
8 9 10 |
# File 'lib/mailtrap/mail/base.rb', line 8 def template_uuid @template_uuid end |
#template_variables ⇒ Object
Returns the value of attribute template_variables.
8 9 10 |
# File 'lib/mailtrap/mail/base.rb', line 8 def template_variables @template_variables end |
#text ⇒ Object
Returns the value of attribute text.
8 9 10 |
# File 'lib/mailtrap/mail/base.rb', line 8 def text @text end |
#to ⇒ Object
Returns the value of attribute to.
8 9 10 |
# File 'lib/mailtrap/mail/base.rb', line 8 def to @to end |
Instance Method Details
#add_attachment(content:, filename:, type: nil, disposition: nil, content_id: nil) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/mailtrap/mail/base.rb', line 75 def (content:, filename:, type: nil, disposition: nil, content_id: nil) = Mailtrap::Attachment.new( content:, filename:, type:, disposition:, content_id: ) << end |
#as_json ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mailtrap/mail/base.rb', line 44 def as_json { 'from' => from, 'to' => to, 'reply_to' => reply_to, 'cc' => cc, 'bcc' => bcc, 'subject' => subject, 'text' => text, 'html' => html, 'attachments' => .map(&:as_json), # TODO: update headers and custom_variables with as_json method 'headers' => headers, 'custom_variables' => custom_variables, 'category' => category, 'template_uuid' => template_uuid, 'template_variables' => template_variables }.transform_values { |value| presence value }.compact end |
#presence(value) ⇒ Object
88 89 90 |
# File 'lib/mailtrap/mail/base.rb', line 88 def presence(value) value.respond_to?(:empty?) && value.empty? ? nil : value end |
#to_json(*args) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/mailtrap/mail/base.rb', line 64 def to_json(*args) JSON.generate( as_json, *args ) end |