Class: CommandTower::Messaging::Execution::Adapters::Expo::Adapter
- Inherits:
-
Object
- Object
- CommandTower::Messaging::Execution::Adapters::Expo::Adapter
- Defined in:
- app/services/command_tower/messaging/execution/adapters/expo/adapter.rb
Overview
Execution adapter: fans out to eligible push endpoints, sends via Expo Push API, fetches receipts once for ok tickets, and marks invalid devices.
Defined Under Namespace
Classes: EndpointAttempt
Constant Summary collapse
- DEVICE_INVALID_ERRORS =
%w[DeviceNotRegistered].freeze
Instance Method Summary collapse
- #call(request:) ⇒ Object
-
#initialize(configuration: nil, http_client: nil, secret_reader: nil) ⇒ Adapter
constructor
A new instance of Adapter.
Constructor Details
#initialize(configuration: nil, http_client: nil, secret_reader: nil) ⇒ Adapter
Returns a new instance of Adapter.
23 24 25 26 27 |
# File 'app/services/command_tower/messaging/execution/adapters/expo/adapter.rb', line 23 def initialize(configuration: nil, http_client: nil, secret_reader: nil) @configuration = configuration || Configuration.new @http_client = http_client || HttpClient.new(configuration: @configuration) @secret_reader = secret_reader || Endpoints::SecretReader end |
Instance Method Details
#call(request:) ⇒ Object
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 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/services/command_tower/messaging/execution/adapters/expo/adapter.rb', line 29 def call(request:) raise ArgumentError, "request must be an AdapterRequest" unless request.is_a?(AdapterRequest) rendered = request.rendered unless rendered.is_a?(Rendering::RenderedPushPayload) return AdapterResult.build(outcome: :terminal_failure, error_code: "render_failed") end unless @configuration.expo_configured? return AdapterResult.build(outcome: :terminal_failure, error_code: "adapter_unconfigured") end endpoint_ids = Array(request.eligible_endpoint_ids) if endpoint_ids.empty? return AdapterResult.build(outcome: :terminal_failure, error_code: "recipient_missing") end delivery = Messaging::ChannelDelivery.includes(:communication).find_by(id: request.channel_delivery_id) owner_user_id = delivery&.communication&.user_id if owner_user_id.nil? return AdapterResult.build(outcome: :terminal_failure, error_code: "recipient_missing") end attempts = build_endpoint_attempts(owner_user_id:, endpoint_ids:) return attempts if attempts.is_a?(AdapterResult) case @configuration.adapter_name when "fake", "log" AdapterResult.build(outcome: :success, normalized_provider_status: "accepted") when "http" deliver_http(attempts:, rendered:, owner_user_id:) else AdapterResult.build(outcome: :terminal_failure, error_code: "adapter_unconfigured") end rescue StandardError AdapterResult.build(outcome: :retryable_failure, error_code: "expo_transient") end |