Class: SimpleConnect::Responses::MessageDeliverResponse

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

Overview

Wraps the ‘messages.deliver` acknowledgement.

Server returns (200, or 422 when nothing queued):

{ "success": true,
  "queued_messages": [{ "message_id":, "recipient":, "status": }],
  "errors": [ ... ] }

Partial success is possible — some recipients queued, some rejected —so consumers read both ‘#queued_messages` and `#errors`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ MessageDeliverResponse

Returns a new instance of MessageDeliverResponse.



17
18
19
20
21
# File 'lib/simple_connect/responses/message_deliver_response.rb', line 17

def initialize(json)
  @json            = json.is_a?(Hash) ? json : {}
  @queued_messages = @json["queued_messages"] || []
  @errors          = @json["errors"] || []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



15
16
17
# File 'lib/simple_connect/responses/message_deliver_response.rb', line 15

def errors
  @errors
end

#queued_messagesObject (readonly)

Returns the value of attribute queued_messages.



15
16
17
# File 'lib/simple_connect/responses/message_deliver_response.rb', line 15

def queued_messages
  @queued_messages
end

Instance Method Details

#any_queued?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/simple_connect/responses/message_deliver_response.rb', line 23

def any_queued?
  @queued_messages.any?
end

#to_hObject



27
28
29
# File 'lib/simple_connect/responses/message_deliver_response.rb', line 27

def to_h
  @json.dup
end