Class: Howitzer::MailAdapters::Mailtrap

Inherits:
Abstract
  • Object
show all
Defined in:
lib/howitzer/mail_adapters/mailtrap.rb

Overview

This class represents mailtrap mail adapter

Instance Attribute Summary

Attributes inherited from Abstract

#message

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#initialize

Constructor Details

This class inherits a constructor from Howitzer::MailAdapters::Abstract

Class Method Details

.find(recipient, subject, wait:) ⇒ Object

Finds an email in storage

Parameters:

  • recipient (String)

    an email

  • subject (String)
  • wait (Integer)

    how much time is required to wait an email

Raises:



15
16
17
18
19
20
21
22
# File 'lib/howitzer/mail_adapters/mailtrap.rb', line 15

def self.find(recipient, subject, wait:)
  message = {}
  retryable(find_retry_params(wait)) { message = retrieve_message(recipient, subject) }
  return new(message) if message.present?

  raise Howitzer::EmailNotFoundError,
        "Message with subject '#{subject}' for recipient '#{recipient}' was not found."
end

Instance Method Details

#html_bodyString

Returns html body of the email message.

Returns:

  • (String)

    html body of the email message



32
33
34
# File 'lib/howitzer/mail_adapters/mailtrap.rb', line 32

def html_body
  Howitzer::MailtrapApi::Client.new.get_html_body(message)
end

#mail_fromString

Returns an email address specified in ‘From` field.

Returns:

  • (String)

    an email address specified in ‘From` field



44
45
46
# File 'lib/howitzer/mail_adapters/mailtrap.rb', line 44

def mail_from
  message['from_email']
end

#mime_partArray

Returns attachments.

Returns:

  • (Array)

    attachments



68
69
70
# File 'lib/howitzer/mail_adapters/mailtrap.rb', line 68

def mime_part
  retrieve_attachments(message)
end

#mime_part!Array

Returns attachments.

Returns:

  • (Array)

    attachments

Raises:



75
76
77
78
79
80
# File 'lib/howitzer/mail_adapters/mailtrap.rb', line 75

def mime_part!
  files = mime_part
  return files if files.present?

  raise Howitzer::NoAttachmentsError, 'No attachments were found.'
end

#plain_text_bodyString

Returns plain text body of the email message.

Returns:

  • (String)

    plain text body of the email message



26
27
28
# File 'lib/howitzer/mail_adapters/mailtrap.rb', line 26

def plain_text_body
  Howitzer::MailtrapApi::Client.new.get_txt_body(message)
end

#received_timeString

Returns when email was received.

Returns:

  • (String)

    when email was received



56
57
58
# File 'lib/howitzer/mail_adapters/mailtrap.rb', line 56

def received_time
  Time.parse(message['created_at']).to_s
end

#recipientsString

Returns recipient emails separated with ‘, `.

Returns:

  • (String)

    recipient emails separated with ‘, `



50
51
52
# File 'lib/howitzer/mail_adapters/mailtrap.rb', line 50

def recipients
  message['to_email'].split ', '
end

#sender_emailString

Returns a real sender email address.

Returns:

  • (String)

    a real sender email address



62
63
64
# File 'lib/howitzer/mail_adapters/mailtrap.rb', line 62

def sender_email
  message['from_email']
end

#textString

Returns stripped text.

Returns:

  • (String)

    stripped text



38
39
40
# File 'lib/howitzer/mail_adapters/mailtrap.rb', line 38

def text
  Howitzer::MailtrapApi::Client.new.get_raw_body(message)
end