Class: Sespool::Bounce

Inherits:
Object
  • Object
show all
Defined in:
lib/sespool/bounce.rb

Defined Under Namespace

Classes: Mail, Recipient

Instance Method Summary collapse

Constructor Details

#initialize(raw_data) ⇒ Bounce

Returns a new instance of Bounce.



7
8
9
10
11
# File 'lib/sespool/bounce.rb', line 7

def initialize(raw_data)
  message = JSON.parse(JSON.parse(raw_data).fetch('Message'))
  @_mail_data = message.fetch('mail')
  @_bounce_data = message.fetch('bounce')
end

Instance Method Details

#bounced_recipientsObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/sespool/bounce.rb', line 33

def bounced_recipients
  @_bounced_recipients ||= @_bounce_data.fetch('bouncedRecipients').map { |recipient|
    Recipient.new(
      recipient.fetch('emailAddress'),
      recipient.fetch('status'),
      recipient.fetch('diagnosticCode'),
      recipient.fetch('action')
    )
  }
end

#feedback_idObject



25
26
27
# File 'lib/sespool/bounce.rb', line 25

def feedback_id
  @_bounce_data.fetch('feedbackId')
end

#mailObject



44
45
46
47
48
49
50
51
# File 'lib/sespool/bounce.rb', line 44

def mail
  @_mail ||= Mail.new(
    @_mail_data.fetch('timestamp'),
    @_mail_data.fetch('source'),
    @_mail_data.fetch('messageId'),
    @_mail_data.fetch('destination')
  )
end

#reporting_mtaObject



21
22
23
# File 'lib/sespool/bounce.rb', line 21

def reporting_mta
  @_bounce_data.fetch('reportingMTA')
end

#sub_typeObject



17
18
19
# File 'lib/sespool/bounce.rb', line 17

def sub_type
  @_bounce_data.fetch('bounceSubType')
end

#timestampObject



29
30
31
# File 'lib/sespool/bounce.rb', line 29

def timestamp
  Time.parse(@_bounce_data.fetch('timestamp'))
end

#typeObject



13
14
15
# File 'lib/sespool/bounce.rb', line 13

def type
  @_bounce_data.fetch('bounceType')
end