Class: Griddler::Mandrill::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/griddler/mandrill/adapter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Adapter

Returns a new instance of Adapter.



4
5
6
# File 'lib/griddler/mandrill/adapter.rb', line 4

def initialize(params)
  @params = params
end

Class Method Details

.normalize_params(params) ⇒ Object



8
9
10
11
# File 'lib/griddler/mandrill/adapter.rb', line 8

def self.normalize_params(params)
  adapter = new(params)
  adapter.normalize_params
end

Instance Method Details

#normalize_paramsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/griddler/mandrill/adapter.rb', line 13

def normalize_params
  events.map do |event|
    to_list = recipients(:to, event)
    to_list = [event['email']] if (to_list.nil? || to_list.empty?) && event['email']
    {
      to: to_list,
      cc: recipients(:cc, event),
      from: full_email([ event[:from_email], event[:from_name] ]),
      subject: event[:subject],
      text: event.fetch(:text, ''),
      html: event.fetch(:html, ''),
      raw_body: event[:raw_msg],
      attachments: attachment_files(event),
      headers: event[:headers].to_a.map{ |x| x.join(': ') }.join("\n")
    }
  end
end