Class: CommandTower::Messaging::Accept::Result
- Inherits:
-
Data
- Object
- Data
- CommandTower::Messaging::Accept::Result
- Defined in:
- app/services/command_tower/messaging/accept/result.rb
Instance Attribute Summary collapse
-
#channel_deliveries ⇒ Object
readonly
Returns the value of attribute channel_deliveries.
-
#communication_id ⇒ Object
readonly
Returns the value of attribute communication_id.
-
#destination_plan_id ⇒ Object
readonly
Returns the value of attribute destination_plan_id.
-
#excluded_destinations ⇒ Object
readonly
Returns the value of attribute excluded_destinations.
-
#host_event_identity ⇒ Object
readonly
Returns the value of attribute host_event_identity.
-
#idempotent_replay ⇒ Object
readonly
Returns the value of attribute idempotent_replay.
-
#inbox_item_id ⇒ Object
readonly
Returns the value of attribute inbox_item_id.
-
#inbox_selected ⇒ Object
readonly
Returns the value of attribute inbox_selected.
-
#notification_type_key ⇒ Object
readonly
Returns the value of attribute notification_type_key.
-
#recipient_id ⇒ Object
readonly
Returns the value of attribute recipient_id.
-
#selected_channels ⇒ Object
readonly
Returns the value of attribute selected_channels.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
- .build(communication_id:, destination_plan_id:, recipient_id:, notification_type_key:, host_event_identity:, status:, idempotent_replay:, inbox_item_id:, channel_deliveries:, selected_channels:, inbox_selected:, excluded_destinations:) ⇒ Object
- .from_communication(communication, idempotent_replay:) ⇒ Object
Instance Attribute Details
#channel_deliveries ⇒ Object (readonly)
Returns the value of attribute channel_deliveries
6 7 8 |
# File 'app/services/command_tower/messaging/accept/result.rb', line 6 def channel_deliveries @channel_deliveries end |
#communication_id ⇒ Object (readonly)
Returns the value of attribute communication_id
6 7 8 |
# File 'app/services/command_tower/messaging/accept/result.rb', line 6 def communication_id @communication_id end |
#destination_plan_id ⇒ Object (readonly)
Returns the value of attribute destination_plan_id
6 7 8 |
# File 'app/services/command_tower/messaging/accept/result.rb', line 6 def destination_plan_id @destination_plan_id end |
#excluded_destinations ⇒ Object (readonly)
Returns the value of attribute excluded_destinations
6 7 8 |
# File 'app/services/command_tower/messaging/accept/result.rb', line 6 def excluded_destinations @excluded_destinations end |
#host_event_identity ⇒ Object (readonly)
Returns the value of attribute host_event_identity
6 7 8 |
# File 'app/services/command_tower/messaging/accept/result.rb', line 6 def host_event_identity @host_event_identity end |
#idempotent_replay ⇒ Object (readonly)
Returns the value of attribute idempotent_replay
6 7 8 |
# File 'app/services/command_tower/messaging/accept/result.rb', line 6 def idempotent_replay @idempotent_replay end |
#inbox_item_id ⇒ Object (readonly)
Returns the value of attribute inbox_item_id
6 7 8 |
# File 'app/services/command_tower/messaging/accept/result.rb', line 6 def inbox_item_id @inbox_item_id end |
#inbox_selected ⇒ Object (readonly)
Returns the value of attribute inbox_selected
6 7 8 |
# File 'app/services/command_tower/messaging/accept/result.rb', line 6 def inbox_selected @inbox_selected end |
#notification_type_key ⇒ Object (readonly)
Returns the value of attribute notification_type_key
6 7 8 |
# File 'app/services/command_tower/messaging/accept/result.rb', line 6 def notification_type_key @notification_type_key end |
#recipient_id ⇒ Object (readonly)
Returns the value of attribute recipient_id
6 7 8 |
# File 'app/services/command_tower/messaging/accept/result.rb', line 6 def recipient_id @recipient_id end |
#selected_channels ⇒ Object (readonly)
Returns the value of attribute selected_channels
6 7 8 |
# File 'app/services/command_tower/messaging/accept/result.rb', line 6 def selected_channels @selected_channels end |
#status ⇒ Object (readonly)
Returns the value of attribute status
6 7 8 |
# File 'app/services/command_tower/messaging/accept/result.rb', line 6 def status @status end |
Class Method Details
.build(communication_id:, destination_plan_id:, recipient_id:, notification_type_key:, host_event_identity:, status:, idempotent_replay:, inbox_item_id:, channel_deliveries:, selected_channels:, inbox_selected:, excluded_destinations:) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/services/command_tower/messaging/accept/result.rb', line 20 def self.build( communication_id:, destination_plan_id:, recipient_id:, notification_type_key:, host_event_identity:, status:, idempotent_replay:, inbox_item_id:, channel_deliveries:, selected_channels:, inbox_selected:, excluded_destinations: ) ordered_channels = Array(selected_channels).map(&:to_s).uniq.sort.freeze ordered_deliveries = Array(channel_deliveries).sort_by { |delivery| delivery.channel_key.to_s }.freeze ordered_excluded = Array(excluded_destinations).sort_by(&:sort_key).freeze new( communication_id:, destination_plan_id:, recipient_id:, notification_type_key: notification_type_key.to_s, host_event_identity: host_event_identity.to_s, status: status.to_s, idempotent_replay: !!idempotent_replay, inbox_item_id:, channel_deliveries: ordered_deliveries, selected_channels: ordered_channels, inbox_selected: !!inbox_selected, excluded_destinations: ordered_excluded, ).freeze end |
.from_communication(communication, idempotent_replay:) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/services/command_tower/messaging/accept/result.rb', line 56 def self.from_communication(communication, idempotent_replay:) plan = communication.destination_plan raise InvariantError, "accepted communication missing destination plan" if plan.nil? decision = plan.decision.is_a?(Hash) ? plan.decision : {} selected = Array(decision["selected_channels"] || decision[:selected_channels]).map(&:to_s) inbox_selected = !!(decision.key?("inbox_selected") ? decision["inbox_selected"] : decision[:inbox_selected]) excluded = Array(decision["excluded_destinations"] || decision[:excluded_destinations]).map do |item| hash = item.respond_to?(:to_h) ? item.to_h : item ExcludedDestination.build( destination: hash["destination"] || hash[:destination], reason_class: hash["reason_class"] || hash[:reason_class], ) end deliveries = Array(communication.channel_deliveries).map do |delivery| ChannelDeliveryResult.build( id: delivery.id, channel_key: delivery.channel_key, status: delivery.status, ) end build( communication_id: communication.id, destination_plan_id: plan.id, recipient_id: communication.user_id, notification_type_key: communication.notification_type_key, host_event_identity: communication.host_event_identity, status: communication.status, idempotent_replay:, inbox_item_id: communication.inbox_item&.id, channel_deliveries: deliveries, selected_channels: selected, inbox_selected:, excluded_destinations: excluded, ) end |