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.
-
#scheduled_at ⇒ Object
readonly
Returns the value of attribute scheduled_at.
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. -
#scheduled? ⇒ Boolean
True when this send was scheduled for later rather than sent immediately.
- #to_h ⇒ Object
-
#wait_for_deliveries(timeout: 30, interval: 2, raise_on_timeout: false) ⇒ Array<RelayGrid::Delivery>
Poll until every delivery reaches a terminal state, or
timeoutseconds elapse.
Constructor Details
#initialize(body, client:) ⇒ SendResult
Returns a new instance of SendResult.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/relaygrid/send_result.rb', line 14 def initialize(body, client:) @raw = body @client = client = body["message"] || {} @message_id = ["id"] @rendered_subject = ["rendered_subject"] @rendered_body = ["rendered_body"] @scheduled_at = parse_time(["scheduled_at"]) @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.
11 12 13 |
# File 'lib/relaygrid/send_result.rb', line 11 def deliveries @deliveries end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
11 12 13 |
# File 'lib/relaygrid/send_result.rb', line 11 def @message_id end |
#push_token ⇒ Object (readonly)
Returns the value of attribute push_token.
11 12 13 |
# File 'lib/relaygrid/send_result.rb', line 11 def push_token @push_token end |
#push_token_expires_at ⇒ Object (readonly)
Returns the value of attribute push_token_expires_at.
11 12 13 |
# File 'lib/relaygrid/send_result.rb', line 11 def push_token_expires_at @push_token_expires_at end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
11 12 13 |
# File 'lib/relaygrid/send_result.rb', line 11 def raw @raw end |
#rendered_body ⇒ Object (readonly)
Returns the value of attribute rendered_body.
11 12 13 |
# File 'lib/relaygrid/send_result.rb', line 11 def rendered_body @rendered_body end |
#rendered_subject ⇒ Object (readonly)
Returns the value of attribute rendered_subject.
11 12 13 |
# File 'lib/relaygrid/send_result.rb', line 11 def rendered_subject @rendered_subject end |
#scheduled_at ⇒ Object (readonly)
Returns the value of attribute scheduled_at.
11 12 13 |
# File 'lib/relaygrid/send_result.rb', line 11 def scheduled_at @scheduled_at end |
Instance Method Details
#delivery_for(channel_type) ⇒ Object
45 46 47 |
# File 'lib/relaygrid/send_result.rb', line 45 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.
35 36 37 |
# File 'lib/relaygrid/send_result.rb', line 35 def delivery_ids deliveries.map(&:id) end |
#inspect ⇒ Object
84 85 86 87 |
# File 'lib/relaygrid/send_result.rb', line 84 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.
41 42 43 |
# File 'lib/relaygrid/send_result.rb', line 41 def push? !push_token.nil? end |
#scheduled? ⇒ Boolean
True when this send was scheduled for later rather than sent immediately.
50 51 52 |
# File 'lib/relaygrid/send_result.rb', line 50 def scheduled? !scheduled_at.nil? end |
#to_h ⇒ Object
80 81 82 |
# File 'lib/relaygrid/send_result.rb', line 80 def to_h raw end |
#wait_for_deliveries(timeout: 30, interval: 2, raise_on_timeout: false) ⇒ Array<RelayGrid::Delivery>
Poll until every delivery reaches a terminal state, or timeout seconds
elapse. A delivery the server is still retrying reads retrying.
A scheduled delivery is never terminal -- nothing has been handed to a
provider yet, so there is nothing to settle -- and polling it would just
burn the full timeout waiting for a state change that isn't coming
until dispatch. When scheduled? is true, this returns deliveries
(each still reading status: "scheduled") immediately without calling
the API at all.
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/relaygrid/send_result.rb', line 69 def wait_for_deliveries(timeout: 30, interval: 2, raise_on_timeout: false) return deliveries if deliveries.empty? || scheduled? @client.deliveries.wait_for( delivery_ids, timeout: timeout, interval: interval, raise_on_timeout: raise_on_timeout ) end |