Class: SimpleConnect::Responses::MessageResponse
- Inherits:
-
Object
- Object
- SimpleConnect::Responses::MessageResponse
- Defined in:
- lib/simple_connect/responses/message_response.rb
Overview
Wraps a ‘message` block — returned nested inside an `EventResponse` or, when we add future endpoints that return message payloads, as a top- level response. Discriminated on the `event` field:
"message.status" → status_callback? (delivered / read / failed)
"message.incoming" → incoming? (user-initiated inbound msg)
Constant Summary collapse
- EVENT_STATUS =
"message.status"- EVENT_INCOMING =
"message.incoming"
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
Instance Method Summary collapse
- #incoming? ⇒ Boolean
-
#initialize(json) ⇒ MessageResponse
constructor
A new instance of MessageResponse.
-
#message_id ⇒ Object
Common fields pulled from ‘data` for convenience.
- #recipient ⇒ Object
- #status ⇒ Object
- #status_callback? ⇒ Boolean
- #timestamp ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(json) ⇒ MessageResponse
Returns a new instance of MessageResponse.
16 17 18 19 20 |
# File 'lib/simple_connect/responses/message_response.rb', line 16 def initialize(json) @json = json.is_a?(Hash) ? json : {} @event = @json["event"] @data = @json["data"].is_a?(Hash) ? @json["data"] : {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
14 15 16 |
# File 'lib/simple_connect/responses/message_response.rb', line 14 def data @data end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
14 15 16 |
# File 'lib/simple_connect/responses/message_response.rb', line 14 def event @event end |
Instance Method Details
#incoming? ⇒ Boolean
26 27 28 |
# File 'lib/simple_connect/responses/message_response.rb', line 26 def incoming? @event == EVENT_INCOMING end |
#message_id ⇒ Object
Common fields pulled from ‘data` for convenience. Exact shape mirrors the outbound status callback — see SimpleWaConnect’s status-callback docs for the full field list. Use ‘#data` or `#to_h` for anything not surfaced here.
34 35 36 |
# File 'lib/simple_connect/responses/message_response.rb', line 34 def @data["message_id"] end |
#recipient ⇒ Object
46 47 48 |
# File 'lib/simple_connect/responses/message_response.rb', line 46 def recipient @data["recipient"] end |
#status ⇒ Object
38 39 40 |
# File 'lib/simple_connect/responses/message_response.rb', line 38 def status @data["status"] end |
#status_callback? ⇒ Boolean
22 23 24 |
# File 'lib/simple_connect/responses/message_response.rb', line 22 def status_callback? @event == EVENT_STATUS end |
#timestamp ⇒ Object
42 43 44 |
# File 'lib/simple_connect/responses/message_response.rb', line 42 def parse_time(@data["timestamp"]) end |
#to_h ⇒ Object
50 51 52 |
# File 'lib/simple_connect/responses/message_response.rb', line 50 def to_h @json.dup end |