Class: Griddler::AmazonSES::Adapter

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Adapter

Returns a new instance of Adapter.



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

def initialize(params)
  @sns_json = params
end

Instance Attribute Details

#sns_jsonObject (readonly)

Returns the value of attribute sns_json.



7
8
9
# File 'lib/griddler/amazon_ses/adapter.rb', line 7

def sns_json
  @sns_json
end

Class Method Details

.normalize_params(params) ⇒ Object



13
14
15
16
# File 'lib/griddler/amazon_ses/adapter.rb', line 13

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

Instance Method Details

#normalize_paramsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/griddler/amazon_ses/adapter.rb', line 18

def normalize_params
  sns_msg = AWS::SnsMessage.new sns_json
  raise "Invalid SNS message" unless sns_msg.authentic? && sns_msg.topic_arn.end_with?('griddler')

  case sns_msg.type
  when :SubscriptionConfirmation
    confirm_sns_subscription_request
    # this is not an actual email reply (and griddler has no way to bail at this point), so return empty parameters
    {}
  when :Notification
    ensure_valid_notification_type!
    sns_json.merge(
      to: recipients,
      from: sender,
      cc: cc,
      bcc: bcc,
      subject: subject,
      text: text_part,
      html: html_part,
      headers: raw_headers,
      attachments: attachment_files
    )
  else
    raise "Invalid SNS message type"
  end
end