Sha256: 6651174a67ba398869a31ac722a70c3bba8e4f6a936768db35c2c5ed184fefe7

Contents?: true

Size: 836 Bytes

Versions: 39

Compression:

Stored size: 836 Bytes

Contents

# SMS notification service for Messages and Notifications sent to Participants.
class MessageSmsNotification
  attr_reader :body, :phone_number

  def initialize(body:, phone_number:)
    @body = body
    @phone_number = phone_number
  end

  def deliver
    if environment.staging? || environment.production?
      sms_client.account.messages.create message
    else
      message
    end
  end

  private

  def config
    Rails.application.config
  end

  def environment
    Rails.env
  end

  def from_telephone_number
    config.try(:twilio_account_telephone_number)
  end

  def message
    {
      to: "+1#{ phone_number }",
      from: from_telephone_number,
      body: body
    }
  end

  def sms_client
    @sms_client ||= Twilio::REST::Client.new(
      config.twilio_account_sid,
      config.twilio_auth_token)
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
think_feel_do_engine-3.13.1 app/models/message_sms_notification.rb
think_feel_do_engine-3.13.0 app/models/message_sms_notification.rb
think_feel_do_engine-3.12.9 app/models/message_sms_notification.rb
think_feel_do_engine-3.12.8 app/models/message_sms_notification.rb
think_feel_do_engine-3.12.7 app/models/message_sms_notification.rb
think_feel_do_engine-3.12.6 app/models/message_sms_notification.rb
think_feel_do_engine-3.12.5 app/models/message_sms_notification.rb
think_feel_do_engine-3.12.4 app/models/message_sms_notification.rb
think_feel_do_engine-3.12.3 app/models/message_sms_notification.rb
think_feel_do_engine-3.12.2 app/models/message_sms_notification.rb
think_feel_do_engine-3.12.1 app/models/message_sms_notification.rb
think_feel_do_engine-3.12.0 app/models/message_sms_notification.rb
think_feel_do_engine-3.11.3 app/models/message_sms_notification.rb
think_feel_do_engine-3.11.0 app/models/message_sms_notification.rb
think_feel_do_engine-3.10.10 app/models/message_sms_notification.rb
think_feel_do_engine-3.10.9 app/models/message_sms_notification.rb
think_feel_do_engine-3.10.8 app/models/message_sms_notification.rb
think_feel_do_engine-3.10.7 app/models/message_sms_notification.rb
think_feel_do_engine-3.10.6 app/models/message_sms_notification.rb