Sha256: 2e2c10705ea10ea0f5b288b13e528c2ef24df847e554aa4618d157a9a456a2d3

Contents?: true

Size: 846 Bytes

Versions: 8

Compression:

Stored size: 846 Bytes

Contents

# frozen_string_literal: true

require "twilio-ruby"

module Decidim
  module ActionDelegator
    class TwilioSendSmsJob < ApplicationJob
      queue_as :default

      def perform(sender, mobile_phone_number, message)
        @sender = sender
        @mobile_phone_number = mobile_phone_number
        @message = message

        send_sms!
      end

      private

      attr_reader :sender, :mobile_phone_number, :message

      def send_sms!
        client.messages.create(
          from: sender,
          to: mobile_phone_number,
          body: message
        )
      end

      def client
        ::Twilio::REST::Client.new twilio_account_sid, twilio_auth_token
      end

      def twilio_account_sid
        ENV["TWILIO_ACCOUNT_SID"]
      end

      def twilio_auth_token
        ENV["TWILIO_AUTH_TOKEN"]
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

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