Sha256: de28c48b26be24fb77e49852de64fdad98dc3f864bd521fbd65e3ba948c428f5

Contents?: true

Size: 1.09 KB

Versions: 8

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Decidim
  module ActionDelegator
    class SmsGateway
      attr_reader :mobile_phone_number, :code, :response

      SMS_GATEWAY_PROVIDER_JOBS = {
        som_connexio: SendSmsJob,
        twilio: TwilioSendSmsJob
      }.freeze

      def initialize(mobile_phone_number, code)
        @mobile_phone_number = mobile_phone_number
        @code = code
      end

      def deliver_code
        return false unless sms_gateway_provider_valid?

        sms_gateway_job.perform_later(sender, mobile_phone_number, message)

        true
      end

      private

      def sms_gateway_job
        SMS_GATEWAY_PROVIDER_JOBS[sms_gateway_provider.to_sym]
      end

      def sender
        ENV["SMS_SENDER"]
      end

      def sms_gateway_provider
        ENV["SMS_GATEWAY_PROVIDER"]
      end

      def sms_gateway_provider_valid?
        return false unless sms_gateway_provider

        SMS_GATEWAY_PROVIDER_JOBS.keys.include? sms_gateway_provider.to_sym
      end

      def message
        I18n.t("decidim.action_delegator.sms_message", code: code)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
decidim-action_delegator-0.8.1 app/services/decidim/action_delegator/sms_gateway.rb
decidim-action_delegator-0.7.2 app/services/decidim/action_delegator/sms_gateway.rb
decidim-action_delegator-0.7.1 app/services/decidim/action_delegator/sms_gateway.rb
decidim-action_delegator-0.7.0 app/services/decidim/action_delegator/sms_gateway.rb
decidim-action_delegator-0.6.0 app/services/decidim/action_delegator/sms_gateway.rb
decidim-action_delegator-0.5.0 app/services/decidim/action_delegator/sms_gateway.rb
decidim-action_delegator-0.4.1 app/services/decidim/action_delegator/sms_gateway.rb
decidim-action_delegator-0.4 app/services/decidim/action_delegator/sms_gateway.rb