Class: RelayGrid::Delivery
- Inherits:
-
Object
- Object
- RelayGrid::Delivery
- Defined in:
- lib/relaygrid/delivery.rb
Overview
One attempt to deliver a message over one channel (email, push, ...).
Immutable: #refresh returns a new Delivery rather than mutating this one,
so a Delivery handed to another thread never changes underneath it.
Constant Summary collapse
- QUEUED =
"queued"- SENT =
"sent"- DELIVERED =
"delivered"- FAILED =
"failed"- BOUNCED =
"bounced"- OPENED =
"opened"- SUCCESS_STATUSES =
States the server will not move away from on its own.
[DELIVERED, OPENED].freeze
Instance Attribute Summary collapse
-
#channel_id ⇒ Object
readonly
Returns the value of attribute channel_id.
-
#channel_name ⇒ Object
readonly
Returns the value of attribute channel_name.
-
#channel_type ⇒ Object
readonly
Returns the value of attribute channel_type.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#delivered_at ⇒ Object
readonly
Returns the value of attribute delivered_at.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#failed_at ⇒ Object
readonly
Returns the value of attribute failed_at.
-
#friendly_error_message ⇒ Object
readonly
Returns the value of attribute friendly_error_message.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#message_id ⇒ Object
readonly
Returns the value of attribute message_id.
-
#opened_at ⇒ Object
readonly
Returns the value of attribute opened_at.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#sent_at ⇒ Object
readonly
Returns the value of attribute sent_at.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #bounced? ⇒ Boolean
- #delivered? ⇒ Boolean
- #email? ⇒ Boolean
- #failed? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(attributes, client: nil) ⇒ Delivery
constructor
A new instance of Delivery.
- #inspect ⇒ Object
- #opened? ⇒ Boolean
- #push? ⇒ Boolean
- #queued? ⇒ Boolean
-
#refresh ⇒ RelayGrid::Delivery
This delivery's current server-side state.
- #sent? ⇒ Boolean
-
#success? ⇒ Boolean
Reached a state the server considers final and successful.
- #to_h ⇒ Object
Constructor Details
#initialize(attributes, client: nil) ⇒ Delivery
Returns a new instance of Delivery.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/relaygrid/delivery.rb', line 26 def initialize(attributes, client: nil) @raw = attributes @client = client @id = attributes["id"] @message_id = attributes["message_id"] @status = attributes["status"] @error_message = attributes["error_message"] @friendly_error_message = attributes["friendly_error_message"] channel = attributes["notification_channel"] || {} @channel_id = channel["id"] @channel_name = channel["name"] @channel_type = channel["channel_type"] @sent_at = parse_time(attributes["sent_at"]) @delivered_at = parse_time(attributes["delivered_at"]) @failed_at = parse_time(attributes["failed_at"]) @opened_at = parse_time(attributes["opened_at"]) @created_at = parse_time(attributes["created_at"]) @updated_at = parse_time(attributes["updated_at"]) freeze end |
Instance Attribute Details
#channel_id ⇒ Object (readonly)
Returns the value of attribute channel_id.
21 22 23 |
# File 'lib/relaygrid/delivery.rb', line 21 def channel_id @channel_id end |
#channel_name ⇒ Object (readonly)
Returns the value of attribute channel_name.
21 22 23 |
# File 'lib/relaygrid/delivery.rb', line 21 def channel_name @channel_name end |
#channel_type ⇒ Object (readonly)
Returns the value of attribute channel_type.
21 22 23 |
# File 'lib/relaygrid/delivery.rb', line 21 def channel_type @channel_type end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
21 22 23 |
# File 'lib/relaygrid/delivery.rb', line 21 def created_at @created_at end |
#delivered_at ⇒ Object (readonly)
Returns the value of attribute delivered_at.
21 22 23 |
# File 'lib/relaygrid/delivery.rb', line 21 def delivered_at @delivered_at end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
21 22 23 |
# File 'lib/relaygrid/delivery.rb', line 21 def @error_message end |
#failed_at ⇒ Object (readonly)
Returns the value of attribute failed_at.
21 22 23 |
# File 'lib/relaygrid/delivery.rb', line 21 def failed_at @failed_at end |
#friendly_error_message ⇒ Object (readonly)
Returns the value of attribute friendly_error_message.
21 22 23 |
# File 'lib/relaygrid/delivery.rb', line 21 def @friendly_error_message end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
21 22 23 |
# File 'lib/relaygrid/delivery.rb', line 21 def id @id end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
21 22 23 |
# File 'lib/relaygrid/delivery.rb', line 21 def @message_id end |
#opened_at ⇒ Object (readonly)
Returns the value of attribute opened_at.
21 22 23 |
# File 'lib/relaygrid/delivery.rb', line 21 def opened_at @opened_at end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
21 22 23 |
# File 'lib/relaygrid/delivery.rb', line 21 def raw @raw end |
#sent_at ⇒ Object (readonly)
Returns the value of attribute sent_at.
21 22 23 |
# File 'lib/relaygrid/delivery.rb', line 21 def sent_at @sent_at end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
21 22 23 |
# File 'lib/relaygrid/delivery.rb', line 21 def status @status end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
21 22 23 |
# File 'lib/relaygrid/delivery.rb', line 21 def updated_at @updated_at end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
101 102 103 |
# File 'lib/relaygrid/delivery.rb', line 101 def ==(other) other.is_a?(Delivery) && other.id == id && other.status == status end |
#bounced? ⇒ Boolean
67 68 69 |
# File 'lib/relaygrid/delivery.rb', line 67 def bounced? status == BOUNCED end |
#delivered? ⇒ Boolean
59 60 61 |
# File 'lib/relaygrid/delivery.rb', line 59 def delivered? status == DELIVERED end |
#email? ⇒ Boolean
88 89 90 |
# File 'lib/relaygrid/delivery.rb', line 88 def email? channel_type == "email" end |
#failed? ⇒ Boolean
63 64 65 |
# File 'lib/relaygrid/delivery.rb', line 63 def failed? status == FAILED end |
#hash ⇒ Object
106 107 108 |
# File 'lib/relaygrid/delivery.rb', line 106 def hash [self.class, id, status].hash end |
#inspect ⇒ Object
110 111 112 113 |
# File 'lib/relaygrid/delivery.rb', line 110 def inspect "#<RelayGrid::Delivery id: #{id.inspect}, channel_type: #{channel_type.inspect}, " \ "status: #{status.inspect}>" end |
#opened? ⇒ Boolean
71 72 73 |
# File 'lib/relaygrid/delivery.rb', line 71 def opened? status == OPENED end |
#push? ⇒ Boolean
84 85 86 |
# File 'lib/relaygrid/delivery.rb', line 84 def push? channel_type == "push" end |
#queued? ⇒ Boolean
51 52 53 |
# File 'lib/relaygrid/delivery.rb', line 51 def queued? status == QUEUED end |
#refresh ⇒ RelayGrid::Delivery
Returns this delivery's current server-side state.
93 94 95 |
# File 'lib/relaygrid/delivery.rb', line 93 def refresh client.deliveries.get(id) end |
#success? ⇒ Boolean
Reached a state the server considers final and successful.
failed is deliberately not terminal: delivery jobs retry, so a failed
row can still flip to sent. This mirrors the dashboard's polling
semantics (see docs/DELIVERY_STATUS_PLAN.md in the API repo).
80 81 82 |
# File 'lib/relaygrid/delivery.rb', line 80 def success? SUCCESS_STATUSES.include?(status) end |
#to_h ⇒ Object
97 98 99 |
# File 'lib/relaygrid/delivery.rb', line 97 def to_h raw end |