Class: EmailEvents::Adapters::Ses::EventData

Inherits:
Abstract::EventData show all
Defined in:
lib/email_events/adapters/ses/event_data.rb

Instance Method Summary collapse

Methods inherited from Abstract::EventData

#simplified_status

Constructor Details

#initialize(raw_data) ⇒ EventData

Returns a new instance of EventData.



4
5
6
7
8
# File 'lib/email_events/adapters/ses/event_data.rb', line 4

def initialize(raw_data)
  @sns_data = JSON.parse raw_data['Message']

  raise "Unrecognized SES event type" if event_type.nil?
end

Instance Method Details

#event_timestampObject



23
24
25
# File 'lib/email_events/adapters/ses/event_data.rb', line 23

def event_timestamp
  Time.parse @sns_data['mail']['timestamp']
end

#event_typeObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/email_events/adapters/ses/event_data.rb', line 10

def event_type
  case @sns_data['notificationType']
  when 'Bounce'
    :bounce
  when 'Complaint'
    :spamreport
  when 'Delivery'
    :delivered
  else
    nil
  end
end

#provider_message_idObject



53
54
55
# File 'lib/email_events/adapters/ses/event_data.rb', line 53

def provider_message_id
  @sns_data['mail']['messageId']
end

#raw_dataObject



57
58
59
# File 'lib/email_events/adapters/ses/event_data.rb', line 57

def raw_data
  @sns_data
end

#reasonObject



41
42
43
44
45
46
# File 'lib/email_events/adapters/ses/event_data.rb', line 41

def reason
  # only supported for bounce events
  return nil unless event_type == :bounce

  @sns_data['bounce']['bounceSubType']
end

#recipientsObject



27
28
29
# File 'lib/email_events/adapters/ses/event_data.rb', line 27

def recipients
  @sns_data['mail']['destination']
end

#smtp_message_idObject



48
49
50
51
# File 'lib/email_events/adapters/ses/event_data.rb', line 48

def smtp_message_id
  # not supported by SNS
  nil
end

#smtp_status_codeObject



31
32
33
34
35
36
37
38
39
# File 'lib/email_events/adapters/ses/event_data.rb', line 31

def smtp_status_code
  # only supported for bounce events
  return nil unless event_type == :bounce

  status_code_str = @sns_data['bounce']['bouncedRecipients'].last['status']
  return nil if status_code_str.nil?

  status_code_str.gsub(/\./,'').to_i
end