Class: RelayGrid::SendResult
- Inherits:
-
Object
- Object
- RelayGrid::SendResult
- Defined in:
- lib/relaygrid/send_result.rb
Overview
What RelayGrid.client.notify hands back: the message that was created, the
deliveries queued for it, and -- when the template has a live push channel
-- the short-lived token the recipient's device needs to subscribe to the
realtime channel.
Instance Attribute Summary collapse
-
#deliveries ⇒ Object
readonly
Returns the value of attribute deliveries.
-
#message_id ⇒ Object
readonly
Returns the value of attribute message_id.
-
#push_token ⇒ Object
readonly
Returns the value of attribute push_token.
-
#push_token_expires_at ⇒ Object
readonly
Returns the value of attribute push_token_expires_at.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#rendered_body ⇒ Object
readonly
Returns the value of attribute rendered_body.
-
#rendered_subject ⇒ Object
readonly
Returns the value of attribute rendered_subject.
Instance Method Summary collapse
- #delivery_for(channel_type) ⇒ Object
-
#delivery_ids ⇒ Object
Ids to hand to
client.deliveries.get_alllater. -
#initialize(body, client:) ⇒ SendResult
constructor
A new instance of SendResult.
- #inspect ⇒ Object
-
#push? ⇒ Boolean
True when the template dispatched over a push channel, so
push_tokenis present and worth handing down to the recipient's device. - #to_h ⇒ Object
-
#wait_for_deliveries(timeout: 30, interval: 2, raise_on_timeout: false) ⇒ Array<RelayGrid::Delivery>
Poll until every delivery settles into a success state, or
timeoutseconds elapse.
Constructor Details
#initialize(body, client:) ⇒ SendResult
Returns a new instance of SendResult.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/relaygrid/send_result.rb', line 12 def initialize(body, client:) @raw = body @client = client = body["message"] || {} @message_id = ["id"] @rendered_subject = ["rendered_subject"] @rendered_body = ["rendered_body"] @push_token = body["push_token"] expires_in = body["push_token_expires_in"] @push_token_expires_at = expires_in ? Time.now + expires_in.to_i : nil @deliveries = Array(["deliveries"]).map { |d| Delivery.new(d, client: client) }.freeze freeze end |
Instance Attribute Details
#deliveries ⇒ Object (readonly)
Returns the value of attribute deliveries.
9 10 11 |
# File 'lib/relaygrid/send_result.rb', line 9 def deliveries @deliveries end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
9 10 11 |
# File 'lib/relaygrid/send_result.rb', line 9 def @message_id end |
#push_token ⇒ Object (readonly)
Returns the value of attribute push_token.
9 10 11 |
# File 'lib/relaygrid/send_result.rb', line 9 def push_token @push_token end |
#push_token_expires_at ⇒ Object (readonly)
Returns the value of attribute push_token_expires_at.
9 10 11 |
# File 'lib/relaygrid/send_result.rb', line 9 def push_token_expires_at @push_token_expires_at end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
9 10 11 |
# File 'lib/relaygrid/send_result.rb', line 9 def raw @raw end |
#rendered_body ⇒ Object (readonly)
Returns the value of attribute rendered_body.
9 10 11 |
# File 'lib/relaygrid/send_result.rb', line 9 def rendered_body @rendered_body end |
#rendered_subject ⇒ Object (readonly)
Returns the value of attribute rendered_subject.
9 10 11 |
# File 'lib/relaygrid/send_result.rb', line 9 def rendered_subject @rendered_subject end |
Instance Method Details
#delivery_for(channel_type) ⇒ Object
42 43 44 |
# File 'lib/relaygrid/send_result.rb', line 42 def delivery_for(channel_type) deliveries.find { |delivery| delivery.channel_type == channel_type.to_s } end |
#delivery_ids ⇒ Object
Ids to hand to client.deliveries.get_all later. The primary reason a
caller keeps anything from a send.
32 33 34 |
# File 'lib/relaygrid/send_result.rb', line 32 def delivery_ids deliveries.map(&:id) end |
#inspect ⇒ Object
73 74 75 76 |
# File 'lib/relaygrid/send_result.rb', line 73 def inspect "#<RelayGrid::SendResult message_id: #{.inspect}, " \ "delivery_ids: #{delivery_ids.inspect}, push: #{push?}>" end |
#push? ⇒ Boolean
True when the template dispatched over a push channel, so push_token is
present and worth handing down to the recipient's device.
38 39 40 |
# File 'lib/relaygrid/send_result.rb', line 38 def push? !push_token.nil? end |
#to_h ⇒ Object
69 70 71 |
# File 'lib/relaygrid/send_result.rb', line 69 def to_h raw end |
#wait_for_deliveries(timeout: 30, interval: 2, raise_on_timeout: false) ⇒ Array<RelayGrid::Delivery>
Poll until every delivery settles into a success state, or timeout
seconds elapse.
failed is not treated as terminal inside the window: delivery jobs
retry, so a failed row can still flip to sent and then delivered.
That mirrors the dashboard's semantics.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/relaygrid/send_result.rb', line 58 def wait_for_deliveries(timeout: 30, interval: 2, raise_on_timeout: false) return deliveries if deliveries.empty? @client.deliveries.wait_for( delivery_ids, timeout: timeout, interval: interval, raise_on_timeout: raise_on_timeout ) end |