Class: Incoming::Strategies::SendGrid

Inherits:
Object
  • Object
show all
Includes:
Incoming::Strategy
Defined in:
lib/incoming/strategies/sendgrid.rb

Instance Attribute Summary

Attributes included from Incoming::Strategy

#message

Instance Method Summary collapse

Methods included from Incoming::Strategy

#authenticate, included, #receive

Constructor Details

#initialize(request) ⇒ SendGrid

Returns a new instance of SendGrid.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/incoming/strategies/sendgrid.rb', line 8

def initialize(request)
  params = request.params.dup

  # TODO: Properly handle encodings
  encodings = JSON.parse(params['charsets'])

  attachments = 1.upto(params['attachments'].to_i).map do |num|
    attachment_from_params(params["attachment#{num}"])
  end

  @message = Mail.new do
    header params['headers']
    if encodings['text'].blank?
      body params['text']
    else
      body params['text'].force_encoding(encodings['text']).encode('UTF-8')
    end

    html_part do
      content_type 'text/html; charset=UTF-8'
      if encodings['html'].blank?
        body params['html']
      else
        body params['html'].force_encoding(encodings['html']).encode('UTF-8')
      end
    end if params['html']

    attachments.each do |attachment|
      add_file(attachment)
    end
  end
end