Class: Howitzer::MailAdapters::Gmail
- Defined in:
- lib/howitzer/mail_adapters/gmail.rb
Overview
This class represents Gmail mail adapter
Instance Attribute Summary
Attributes inherited from Abstract
Class Method Summary collapse
-
.find(recipient, subject, wait:) ⇒ Object
Finds an email in storage.
Instance Method Summary collapse
-
#html_body ⇒ String
Html body of the email message.
-
#mail_from ⇒ String
An email address specified in ‘From` field.
-
#mime_part ⇒ Array
Attachments.
-
#mime_part! ⇒ Array
Attachments.
-
#plain_text_body ⇒ String
Plain text body of the email message.
-
#received_time ⇒ String
When email was received.
-
#recipients ⇒ Array
Recipient emails.
-
#text ⇒ String
Stripped text.
Methods inherited from Abstract
Constructor Details
This class inherits a constructor from Howitzer::MailAdapters::Abstract
Class Method Details
.find(recipient, subject, wait:) ⇒ Object
Finds an email in storage
15 16 17 18 19 20 21 |
# File 'lib/howitzer/mail_adapters/gmail.rb', line 15 def self.find(recipient, subject, wait:) = {} retryable(find_retry_params(wait)) { = (recipient, subject) } return new() if .present? raise Howitzer::EmailNotFoundError, "Message with subject '#{subject}' for recipient '#{recipient}' was not found." end |
Instance Method Details
#html_body ⇒ String
Returns html body of the email message.
31 32 33 |
# File 'lib/howitzer/mail_adapters/gmail.rb', line 31 def html_body .html_part.to_s end |
#mail_from ⇒ String
Returns an email address specified in ‘From` field.
43 44 45 |
# File 'lib/howitzer/mail_adapters/gmail.rb', line 43 def mail_from "#{.from[0]['mailbox']}@#{.from[0]['host']}" end |
#mime_part ⇒ Array
Returns attachments.
61 62 63 |
# File 'lib/howitzer/mail_adapters/gmail.rb', line 61 def mime_part . end |
#mime_part! ⇒ Array
Returns attachments.
68 69 70 71 72 |
# File 'lib/howitzer/mail_adapters/gmail.rb', line 68 def mime_part! files = mime_part return files if files.present? raise Howitzer::NoAttachmentsError, 'No attachments were found.' end |
#plain_text_body ⇒ String
Returns plain text body of the email message.
25 26 27 |
# File 'lib/howitzer/mail_adapters/gmail.rb', line 25 def plain_text_body .body.to_s end |
#received_time ⇒ String
Returns when email was received.
55 56 57 |
# File 'lib/howitzer/mail_adapters/gmail.rb', line 55 def received_time Time.parse(.date).strftime('%F %T') end |
#recipients ⇒ Array
Returns recipient emails.
49 50 51 |
# File 'lib/howitzer/mail_adapters/gmail.rb', line 49 def recipients .to.inject([]) { |ar, to| ar << "#{to['mailbox']}@#{to['host']}" } end |
#text ⇒ String
Returns stripped text.
37 38 39 |
# File 'lib/howitzer/mail_adapters/gmail.rb', line 37 def text .text_part.to_s end |