class MailHandler::Sender
Class for sending email, and storing details about the sending.
Constants
- Sending
@param [Time] - sending started at Time @param [Time] - sending finished at Time @param [int] - how long sending lasted, seconds @param [Object] - sending response message @param [Mail] - email/emails sent
Attributes
dispatcher[RW]
sending[RW]
validate_response[RW]
Public Class Methods
new(dispatcher)
click to toggle source
@param [Sending::Oblect] dispatcher - sender type used for sending email
# File lib/mailhandler/sender.rb, line 23 def initialize(dispatcher) @dispatcher = dispatcher @sending = Sending.new @validate_response = false end
Public Instance Methods
dispatcher_client()
click to toggle source
# File lib/mailhandler/sender.rb, line 37 def dispatcher_client dispatcher.client if dispatcher.respond_to?(:client) end
send_email(email)
click to toggle source
# File lib/mailhandler/sender.rb, line 29 def send_email(email) init_sending_details(email) response = dispatcher.send(email) update_sending_details(response) check_response(response) response end
Private Instance Methods
check_response(response)
click to toggle source
# File lib/mailhandler/sender.rb, line 43 def check_response(response) return unless validate_response return if dispatcher.valid_response?(response) raise SendEmailError, "Invalid sending response: #{response}." end
init_sending_details(email)
click to toggle source
# File lib/mailhandler/sender.rb, line 50 def init_sending_details(email) @sending = Sending.new @sending.started_at = Time.now @sending.email = email end
update_sending_details(response)
click to toggle source
# File lib/mailhandler/sender.rb, line 56 def update_sending_details(response) @sending.finished_at = Time.now @sending.duration = @sending.finished_at - @sending.started_at @sending.response = response end