Class: SimpleConnect::Responses::EventResponse
- Inherits:
-
Object
- Object
- SimpleConnect::Responses::EventResponse
- Defined in:
- lib/simple_connect/responses/event_response.rb
Overview
Wraps the ‘events.detail` success payload. Holds the event-log row and, optionally, a nested `MessageResponse` if a WhatsApp message is linked to the event.
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.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/simple_connect/responses/event_response.rb', line 12 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.
9 10 11 |
# File 'lib/simple_connect/responses/event_response.rb', line 9 def created_at @created_at end |
#error_text ⇒ Object (readonly)
Returns the value of attribute error_text.
9 10 11 |
# File 'lib/simple_connect/responses/event_response.rb', line 9 def error_text @error_text end |
#event_id ⇒ Object (readonly)
Returns the value of attribute event_id.
9 10 11 |
# File 'lib/simple_connect/responses/event_response.rb', line 9 def event_id @event_id end |
#event_key ⇒ Object (readonly)
Returns the value of attribute event_key.
9 10 11 |
# File 'lib/simple_connect/responses/event_response.rb', line 9 def event_key @event_key end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
9 10 11 |
# File 'lib/simple_connect/responses/event_response.rb', line 9 def @message end |
#occurred_at ⇒ Object (readonly)
Returns the value of attribute occurred_at.
9 10 11 |
# File 'lib/simple_connect/responses/event_response.rb', line 9 def occurred_at @occurred_at end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
9 10 11 |
# File 'lib/simple_connect/responses/event_response.rb', line 9 def payload @payload end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
9 10 11 |
# File 'lib/simple_connect/responses/event_response.rb', line 9 def status @status end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
9 10 11 |
# File 'lib/simple_connect/responses/event_response.rb', line 9 def updated_at @updated_at end |
Instance Method Details
#dispatched? ⇒ Boolean
27 28 29 |
# File 'lib/simple_connect/responses/event_response.rb', line 27 def dispatched? @status == "dispatched" end |
#failed? ⇒ Boolean
31 32 33 |
# File 'lib/simple_connect/responses/event_response.rb', line 31 def failed? @status == "failed" end |
#message? ⇒ Boolean
39 40 41 |
# File 'lib/simple_connect/responses/event_response.rb', line 39 def !@message.nil? end |
#skipped? ⇒ Boolean
35 36 37 |
# File 'lib/simple_connect/responses/event_response.rb', line 35 def skipped? @status.to_s.start_with?("skipped") end |
#to_h ⇒ Object
47 48 49 |
# File 'lib/simple_connect/responses/event_response.rb', line 47 def to_h @json.dup end |
#used_previous_secret? ⇒ Boolean
43 44 45 |
# File 'lib/simple_connect/responses/event_response.rb', line 43 def used_previous_secret? @used_previous_secret end |