Class: SimpleConnect::Responses::DeliverResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_connect/responses/deliver_response.rb

Overview

Wraps the ‘events.deliver` acknowledgement.

Server returns:

202 on a new event       → { status, log_id, event_id, event_log, message }
200 on a duplicate replay → { status, log_id, event_id, event_log, message, duplicate: true }

Either code is a success; consumers check ‘#duplicate?` to distinguish. If the request was signed with a recently-rotated previous secret, the server adds `“used_previous_secret”: true` at the top level — a hint to rotate credentials before the grace window ends.

As of server v0.3.0, the response also carries the persisted event-log row + symmetric message under the same ‘event_log` / `message` keys that `events.detail` uses, so the same `EventResponse` parser wraps both. `#event` returns that wrapped row — the caller can read `#event.status`, `#event.error_text`, `#event.skipped?`, etc., to see at a glance whether the event was actually queued for dispatch (`“received”`) or skipped because the integration is paused / the per-event flow is disabled. Without this, a paused integration looked identical to a live one from the sender’s perspective.

‘#event.message` is almost always `nil` at deliver time — dispatch is async and the outbound Message does not exist yet at the moment of the ack; populated only on duplicate replays of an already-dispatched event.

The flat ‘#log_id` / `#event_id` accessors are preserved for backward compatibility.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ DeliverResponse

Returns a new instance of DeliverResponse.



35
36
37
38
39
40
41
42
43
# File 'lib/simple_connect/responses/deliver_response.rb', line 35

def initialize(json)
  @json                 = json.is_a?(Hash) ? json : {}
  @status               = @json["status"]
  @log_id               = @json["log_id"]
  @event_id             = @json["event_id"]
  @duplicate            = @json["duplicate"] == true
  @used_previous_secret = @json["used_previous_secret"] == true
  @event                = @json["event_log"].is_a?(Hash) ? EventResponse.new(@json) : nil
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



33
34
35
# File 'lib/simple_connect/responses/deliver_response.rb', line 33

def event
  @event
end

#event_idObject (readonly)

Returns the value of attribute event_id.



33
34
35
# File 'lib/simple_connect/responses/deliver_response.rb', line 33

def event_id
  @event_id
end

#log_idObject (readonly)

Returns the value of attribute log_id.



33
34
35
# File 'lib/simple_connect/responses/deliver_response.rb', line 33

def log_id
  @log_id
end

#statusObject (readonly)

Returns the value of attribute status.



33
34
35
# File 'lib/simple_connect/responses/deliver_response.rb', line 33

def status
  @status
end

Instance Method Details

#duplicate?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/simple_connect/responses/deliver_response.rb', line 45

def duplicate?
  @duplicate
end

#to_hObject



53
54
55
# File 'lib/simple_connect/responses/deliver_response.rb', line 53

def to_h
  @json.dup
end

#used_previous_secret?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/simple_connect/responses/deliver_response.rb', line 49

def used_previous_secret?
  @used_previous_secret
end