Class: HttpMailer::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/http_mailer/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Client

Returns a new instance of Client.



5
6
7
# File 'lib/http_mailer/client.rb', line 5

def initialize(settings)
  configure(settings)
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



3
4
5
# File 'lib/http_mailer/client.rb', line 3

def configuration
  @configuration
end

#mailgunObject (readonly)

Returns the value of attribute mailgun.



3
4
5
# File 'lib/http_mailer/client.rb', line 3

def mailgun
  @mailgun
end

#mandrillObject (readonly)

Returns the value of attribute mandrill.



3
4
5
# File 'lib/http_mailer/client.rb', line 3

def mandrill
  @mandrill
end

#sendgridObject (readonly)

Returns the value of attribute sendgrid.



3
4
5
# File 'lib/http_mailer/client.rb', line 3

def sendgrid
  @sendgrid
end

Instance Method Details

#configure(settings) ⇒ Object



9
10
11
12
13
# File 'lib/http_mailer/client.rb', line 9

def configure(settings)
  @mailgun = MailgunServiceHandler.new(settings[:mailgun])
  @sendgrid = SendGridServiceHandler.new(settings[:sendgrid])
  @mandrill = MandrillServiceHandler.new(settings[:mandrill])
end

#send_message(from, to, subject, body, from_name = '', to_name = '') ⇒ Object

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/http_mailer/client.rb', line 15

def send_message(from, to, subject, body, from_name='', to_name='')
  response = nil

  [sendgrid, mailgun, mandrill].each do |service|
    if service.configured?
      response = service.send_message(from, to, subject, body, to_name, from_name)
      break if response.code == 200
    end
  end

  raise EmailDeliveryError if response.code != 200
  return response
end