class Email::Delivery::Client
Attributes
bcc[RW]
body[RW]
cc[RW]
from[RW]
message[RW]
status[RW]
subject[RW]
to[RW]
Public Class Methods
new(from, to, cc, bcc, subject, body)
click to toggle source
# File lib/email/delivery/client.rb, line 23 def initialize(from, to, cc, bcc, subject, body) @from = from @to = to @cc = cc @bcc = bcc @subject = subject @body = body @status = nil @message = nil end
Public Instance Methods
dispatch()
click to toggle source
Goal of this method is to serve email by one of the service providers In case of a failure return a status code and a failure message.
# File lib/email/delivery/client.rb, line 36 def dispatch response = Email::Delivery::SendgridClient.new.dispatch(from, to, cc, bcc, subject, body) if [200, 202].include?(response[:status]) status = 0 message = 'success' else response = Email::Delivery::MailgunClient.new.dispatch(from, to, cc, bcc, subject, body) if response[:status] == 200 status = 0 message = 'success' else status = 4 message = "Emails failed in sending. The error message is as followed: #{ response[:message] }" end end {status: status, message: message} end