Class: Posthaste::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/posthaste/result.rb

Overview

What the API said about one send.

Reachable as mail.posthaste_result after deliver_now, because ActionMailer's own return value is the Mail::Message and there is nowhere else to put a message id that a caller needs in order to look the delivery up later.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, mapping_warnings: []) ⇒ Result

Returns a new instance of Result.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/posthaste/result.rb', line 14

def initialize(body, mapping_warnings: [])
  @raw = body
  @id = body['id']
  @status = body['status']
  @group_id = body['groupId']
  @scheduled_at = body['scheduledAt']
  # Per-recipient outcome, present only when there was more than one.
  @emails = body['emails'] || []
  # Recipients skipped because they are on the suppression list. Repeated
  # here as well as inside `emails` deliberately: a recipient we did not
  # send to is the one outcome that must be impossible to miss.
  @suppressed = body['suppressed'] || []
  # The platform's pre-send lint findings, warnings included.
  @warnings = body['warnings'] || []
  # What this gem had to change to express the message.
  @mapping_warnings = mapping_warnings
end

Instance Attribute Details

#emailsObject (readonly)

Returns the value of attribute emails.



11
12
13
# File 'lib/posthaste/result.rb', line 11

def emails
  @emails
end

#group_idObject (readonly)

Returns the value of attribute group_id.



11
12
13
# File 'lib/posthaste/result.rb', line 11

def group_id
  @group_id
end

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/posthaste/result.rb', line 11

def id
  @id
end

#mapping_warningsObject (readonly)

Returns the value of attribute mapping_warnings.



11
12
13
# File 'lib/posthaste/result.rb', line 11

def mapping_warnings
  @mapping_warnings
end

#rawObject (readonly)

Returns the value of attribute raw.



11
12
13
# File 'lib/posthaste/result.rb', line 11

def raw
  @raw
end

#scheduled_atObject (readonly)

Returns the value of attribute scheduled_at.



11
12
13
# File 'lib/posthaste/result.rb', line 11

def scheduled_at
  @scheduled_at
end

#statusObject (readonly)

Returns the value of attribute status.



11
12
13
# File 'lib/posthaste/result.rb', line 11

def status
  @status
end

#suppressedObject (readonly)

Returns the value of attribute suppressed.



11
12
13
# File 'lib/posthaste/result.rb', line 11

def suppressed
  @suppressed
end

#warningsObject (readonly)

Returns the value of attribute warnings.



11
12
13
# File 'lib/posthaste/result.rb', line 11

def warnings
  @warnings
end

Instance Method Details

#duplicate?Boolean

An idempotency replay: no new message was created and id is the original's.

Read off the BODY, not off a 200-versus-202, because the body is the authoritative answer and survives a proxy that normalises the status.

Returns:

  • (Boolean)


37
38
39
# File 'lib/posthaste/result.rb', line 37

def duplicate?
  status == 'duplicate'
end

#inspectObject



45
46
47
48
# File 'lib/posthaste/result.rb', line 45

def inspect
  "#<Posthaste::Result id=#{id.inspect} status=#{status.inspect} " \
    "suppressed=#{suppressed.length} warnings=#{warnings.length}>"
end

#scheduled?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/posthaste/result.rb', line 41

def scheduled?
  status == 'scheduled'
end