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"- RETRYING =
"retrying"- FAILED =
"failed"- BOUNCED =
"bounced"- OPENED =
"opened"- SUCCESS_STATUSES =
[DELIVERED, OPENED].freeze
- TERMINAL_STATUSES =
States the server will not move away from on its own.
(SUCCESS_STATUSES + [FAILED, BOUNCED]).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.
- #retrying? ⇒ Boolean
- #sent? ⇒ Boolean
-
#success? ⇒ Boolean
Reached a state the server considers final and successful.
-
#terminal? ⇒ Boolean
Reached a state the server will not move away from on its own.
- #to_h ⇒ Object
Constructor Details
#initialize(attributes, client: nil) ⇒ Delivery
Returns a new instance of Delivery.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/relaygrid/delivery.rb', line 29 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.
24 25 26 |
# File 'lib/relaygrid/delivery.rb', line 24 def channel_id @channel_id end |
#channel_name ⇒ Object (readonly)
Returns the value of attribute channel_name.
24 25 26 |
# File 'lib/relaygrid/delivery.rb', line 24 def channel_name @channel_name end |
#channel_type ⇒ Object (readonly)
Returns the value of attribute channel_type.
24 25 26 |
# File 'lib/relaygrid/delivery.rb', line 24 def channel_type @channel_type end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
24 25 26 |
# File 'lib/relaygrid/delivery.rb', line 24 def created_at @created_at end |
#delivered_at ⇒ Object (readonly)
Returns the value of attribute delivered_at.
24 25 26 |
# File 'lib/relaygrid/delivery.rb', line 24 def delivered_at @delivered_at end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
24 25 26 |
# File 'lib/relaygrid/delivery.rb', line 24 def @error_message end |
#failed_at ⇒ Object (readonly)
Returns the value of attribute failed_at.
24 25 26 |
# File 'lib/relaygrid/delivery.rb', line 24 def failed_at @failed_at end |
#friendly_error_message ⇒ Object (readonly)
Returns the value of attribute friendly_error_message.
24 25 26 |
# File 'lib/relaygrid/delivery.rb', line 24 def @friendly_error_message end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
24 25 26 |
# File 'lib/relaygrid/delivery.rb', line 24 def id @id end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
24 25 26 |
# File 'lib/relaygrid/delivery.rb', line 24 def @message_id end |
#opened_at ⇒ Object (readonly)
Returns the value of attribute opened_at.
24 25 26 |
# File 'lib/relaygrid/delivery.rb', line 24 def opened_at @opened_at end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
24 25 26 |
# File 'lib/relaygrid/delivery.rb', line 24 def raw @raw end |
#sent_at ⇒ Object (readonly)
Returns the value of attribute sent_at.
24 25 26 |
# File 'lib/relaygrid/delivery.rb', line 24 def sent_at @sent_at end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
24 25 26 |
# File 'lib/relaygrid/delivery.rb', line 24 def status @status end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
24 25 26 |
# File 'lib/relaygrid/delivery.rb', line 24 def updated_at @updated_at end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
110 111 112 |
# File 'lib/relaygrid/delivery.rb', line 110 def ==(other) other.is_a?(Delivery) && other.id == id && other.status == status end |
#bounced? ⇒ Boolean
74 75 76 |
# File 'lib/relaygrid/delivery.rb', line 74 def bounced? status == BOUNCED end |
#delivered? ⇒ Boolean
62 63 64 |
# File 'lib/relaygrid/delivery.rb', line 62 def delivered? status == DELIVERED end |
#email? ⇒ Boolean
97 98 99 |
# File 'lib/relaygrid/delivery.rb', line 97 def email? channel_type == "email" end |
#failed? ⇒ Boolean
70 71 72 |
# File 'lib/relaygrid/delivery.rb', line 70 def failed? status == FAILED end |
#hash ⇒ Object
115 116 117 |
# File 'lib/relaygrid/delivery.rb', line 115 def hash [self.class, id, status].hash end |
#inspect ⇒ Object
119 120 121 122 |
# File 'lib/relaygrid/delivery.rb', line 119 def inspect "#<RelayGrid::Delivery id: #{id.inspect}, channel_type: #{channel_type.inspect}, " \ "status: #{status.inspect}>" end |
#opened? ⇒ Boolean
78 79 80 |
# File 'lib/relaygrid/delivery.rb', line 78 def opened? status == OPENED end |
#push? ⇒ Boolean
93 94 95 |
# File 'lib/relaygrid/delivery.rb', line 93 def push? channel_type == "push" end |
#queued? ⇒ Boolean
54 55 56 |
# File 'lib/relaygrid/delivery.rb', line 54 def queued? status == QUEUED end |
#refresh ⇒ RelayGrid::Delivery
Returns this delivery's current server-side state.
102 103 104 |
# File 'lib/relaygrid/delivery.rb', line 102 def refresh client.deliveries.get(id) end |
#retrying? ⇒ Boolean
66 67 68 |
# File 'lib/relaygrid/delivery.rb', line 66 def status == RETRYING end |
#success? ⇒ Boolean
Reached a state the server considers final and successful.
83 84 85 |
# File 'lib/relaygrid/delivery.rb', line 83 def success? SUCCESS_STATUSES.include?(status) end |
#terminal? ⇒ Boolean
Reached a state the server will not move away from on its own. A delivery
being retried is retrying, not failed, so failed is final.
89 90 91 |
# File 'lib/relaygrid/delivery.rb', line 89 def terminal? TERMINAL_STATUSES.include?(status) end |
#to_h ⇒ Object
106 107 108 |
# File 'lib/relaygrid/delivery.rb', line 106 def to_h raw end |