Class: MnoEnterprise::MailAdapters::MandrillAdapter
- Defined in:
- lib/mno_enterprise/mail_adapters/mandrill_adapter.rb
Class Method Summary collapse
-
.client ⇒ Object
Return a mandrill client configured with the right API key.
-
.deliver(template, from, to, vars = {}, opts = {}) ⇒ Object
Send a template.
-
.send_template(*args) ⇒ Object
Send the provided template with options MandrillClient.send_template(template_name(string), template_content(array), message(hash)).
Methods inherited from Adapter
Class Method Details
.client ⇒ Object
Return a mandrill client configured with the right API key
9 10 11 |
# File 'lib/mno_enterprise/mail_adapters/mandrill_adapter.rb', line 9 def client @client ||= Mandrill::API.new(ENV['MANDRILL_API_KEY'] || MnoEnterprise.mandrill_key) end |
.deliver(template, from, to, vars = {}, opts = {}) ⇒ Object
Send a template
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mno_enterprise/mail_adapters/mandrill_adapter.rb', line 15 def deliver(template, from, to, vars={}, opts={}) # Prepare message from args = { from_name: from[:name], from_email: from[:email]} [:to] = [to].flatten.map { |t| {name: t[:name], email: t[:email], type: (t[:type] || :to) } } # Sanitize merge vars full_sanitizer = Rails::Html::FullSanitizer.new [:global_merge_vars] = vars.map { |k,v| {name: k.to_s, content: full_sanitizer.sanitize(v)} } # Merge additional mandrill options .merge!(opts) self.send_template(template,[],) end |
.send_template(*args) ⇒ Object
Send the provided template with options MandrillClient.send_template(template_name(string), template_content(array), message(hash))
32 33 34 35 36 37 38 |
# File 'lib/mno_enterprise/mail_adapters/mandrill_adapter.rb', line 32 def send_template(*args) if self.test? self.base_deliveries.push(args) else self.client..send_template(*args) end end |