Class: EmailEvents::Adapters::Sendgrid::EventData

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

Instance Method Summary collapse

Methods inherited from Abstract::EventData

#simplified_status

Constructor Details

#initialize(sendgrid_data) ⇒ EventData

Returns a new instance of EventData.



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

def initialize(sendgrid_data)
  @sendgrid_data = sendgrid_data

  raise "Unrecognized Sendgrid event type" unless event_type.in?([:delivered, :bounce, :dropped, :deferred, :processed, :click,
                                                                 :open, :spamreport, :group_unsubscribe, :group_resubscribe])
end

Instance Method Details

#event_timestampObject



15
16
17
18
# File 'lib/email_events/adapters/sendgrid/event_data.rb', line 15

def event_timestamp
  return nil if @sendgrid_data.nil?
  Time.at @sendgrid_data['timestamp']
end

#event_typeObject



11
12
13
# File 'lib/email_events/adapters/sendgrid/event_data.rb', line 11

def event_type
  @sendgrid_data['event'].to_sym
end

#provider_message_idObject



39
40
41
42
# File 'lib/email_events/adapters/sendgrid/event_data.rb', line 39

def provider_message_id
  return nil if @sendgrid_data['sg_message_id'].nil?
  @sendgrid_data['sg_message_id'].gsub(/\.filter.*/,'')
end

#raw_dataObject



44
45
46
# File 'lib/email_events/adapters/sendgrid/event_data.rb', line 44

def raw_data
  @sendgrid_data
end

#reasonObject



31
32
33
# File 'lib/email_events/adapters/sendgrid/event_data.rb', line 31

def reason
  @sendgrid_data[:reason]
end

#recipientsObject



20
21
22
23
# File 'lib/email_events/adapters/sendgrid/event_data.rb', line 20

def recipients
  return nil if @sendgrid_data.nil?
  [@sendgrid_data['email']]
end

#smtp_message_idObject



35
36
37
# File 'lib/email_events/adapters/sendgrid/event_data.rb', line 35

def smtp_message_id
  @sendgrid_data['smtp-id']
end

#smtp_status_codeObject



25
26
27
28
29
# File 'lib/email_events/adapters/sendgrid/event_data.rb', line 25

def smtp_status_code
  return nil if @sendgrid_data[:status].blank?

  @sendgrid_data[:status].gsub(/\./,'').to_i
end