Class: MonkeyMail::Clients::MailgunClient

Inherits:
BaseClient
  • Object
show all
Defined in:
lib/monkey_mail/clients/mailgun_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseClient

#render_template

Constructor Details

#initialize(api_key, domain) ⇒ MailgunClient

Returns a new instance of MailgunClient.



9
10
11
12
# File 'lib/monkey_mail/clients/mailgun_client.rb', line 9

def initialize(api_key, domain)
  @api_key = api_key
  @domain = domain
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/monkey_mail/clients/mailgun_client.rb', line 7

def api_key
  @api_key
end

#domainObject (readonly)

Returns the value of attribute domain.



7
8
9
# File 'lib/monkey_mail/clients/mailgun_client.rb', line 7

def domain
  @domain
end

Instance Method Details

#send_template(template_name:, subject:, from_email:, from_name:, to:, vars:, attachment: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/monkey_mail/clients/mailgun_client.rb', line 14

def send_template(template_name:, subject:, from_email:, from_name:, to:, vars:, attachment: nil)
  payload = { :from => "#{from_name} <#{from_email}>",
              :to => to.join(', '),
              :subject => subject,
              :template => template_name,
              :attachment => attachment,
              't:variables' => vars.to_json }

  RestClient::Request.execute(method: :post,
                              url: messages_url,
                              payload: payload)
end