Class: SimpleConnect::Responses::EventResponse
- Inherits:
-
Object
- Object
- SimpleConnect::Responses::EventResponse
- Defined in:
- lib/simple_connect/responses/event_response.rb
Overview
Wraps the persisted event-log row and (optionally) the linked WhatsApp message. Returned from two endpoints:
* `events.detail` — the full GET payload, where the server wraps
the log under an `"event_log"` key alongside `"message"`.
* `events.deliver` (server ≥ 0.3.0) — the same shape, embedded
under the `"event"` key on the deliver ack so callers know
immediately whether the event was queued (`"received"`) or
skipped (`"skipped_paused"`, `"skipped_disabled"`, …).
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#error_text ⇒ Object
readonly
Returns the value of attribute error_text.
-
#event_id ⇒ Object
readonly
Returns the value of attribute event_id.
-
#event_key ⇒ Object
readonly
Returns the value of attribute event_key.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#occurred_at ⇒ Object
readonly
Returns the value of attribute occurred_at.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #dispatched? ⇒ Boolean
- #failed? ⇒ Boolean
-
#initialize(json) ⇒ EventResponse
constructor
A new instance of EventResponse.
- #message? ⇒ Boolean
- #skipped? ⇒ Boolean
- #to_h ⇒ Object
- #used_previous_secret? ⇒ Boolean
Constructor Details
#initialize(json) ⇒ EventResponse
Returns a new instance of EventResponse.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/simple_connect/responses/event_response.rb', line 18 def initialize(json) @json = json.is_a?(Hash) ? json : {} event_log = @json["event_log"].is_a?(Hash) ? @json["event_log"] : {} @event_id = event_log["event_id"] @event_key = event_log["event_key"] @status = event_log["status"] @occurred_at = parse_time(event_log["occurred_at"]) @created_at = parse_time(event_log["created_at"]) @updated_at = parse_time(event_log["updated_at"]) @error_text = event_log["error_text"] @used_previous_secret = event_log["used_previous_secret"] == true @payload = event_log["payload"].is_a?(Hash) ? event_log["payload"] : {} @message = @json["message"] ? MessageResponse.new(@json["message"]) : nil end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
15 16 17 |
# File 'lib/simple_connect/responses/event_response.rb', line 15 def created_at @created_at end |
#error_text ⇒ Object (readonly)
Returns the value of attribute error_text.
15 16 17 |
# File 'lib/simple_connect/responses/event_response.rb', line 15 def error_text @error_text end |
#event_id ⇒ Object (readonly)
Returns the value of attribute event_id.
15 16 17 |
# File 'lib/simple_connect/responses/event_response.rb', line 15 def event_id @event_id end |
#event_key ⇒ Object (readonly)
Returns the value of attribute event_key.
15 16 17 |
# File 'lib/simple_connect/responses/event_response.rb', line 15 def event_key @event_key end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
15 16 17 |
# File 'lib/simple_connect/responses/event_response.rb', line 15 def @message end |
#occurred_at ⇒ Object (readonly)
Returns the value of attribute occurred_at.
15 16 17 |
# File 'lib/simple_connect/responses/event_response.rb', line 15 def occurred_at @occurred_at end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
15 16 17 |
# File 'lib/simple_connect/responses/event_response.rb', line 15 def payload @payload end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
15 16 17 |
# File 'lib/simple_connect/responses/event_response.rb', line 15 def status @status end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
15 16 17 |
# File 'lib/simple_connect/responses/event_response.rb', line 15 def updated_at @updated_at end |
Instance Method Details
#dispatched? ⇒ Boolean
33 34 35 |
# File 'lib/simple_connect/responses/event_response.rb', line 33 def dispatched? @status == "dispatched" end |
#failed? ⇒ Boolean
37 38 39 |
# File 'lib/simple_connect/responses/event_response.rb', line 37 def failed? @status == "failed" end |
#message? ⇒ Boolean
45 46 47 |
# File 'lib/simple_connect/responses/event_response.rb', line 45 def !@message.nil? end |
#skipped? ⇒ Boolean
41 42 43 |
# File 'lib/simple_connect/responses/event_response.rb', line 41 def skipped? @status.to_s.start_with?("skipped") end |
#to_h ⇒ Object
53 54 55 |
# File 'lib/simple_connect/responses/event_response.rb', line 53 def to_h @json.dup end |
#used_previous_secret? ⇒ Boolean
49 50 51 |
# File 'lib/simple_connect/responses/event_response.rb', line 49 def used_previous_secret? @used_previous_secret end |