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.16.1 app/models/message_sms_notification.rb
think_feel_do_engine-3.15.7 app/models/message_sms_notification.rb
think_feel_do_engine-3.16.0 app/models/message_sms_notification.rb
think_feel_do_engine-3.15.6 app/models/message_sms_notification.rb
think_feel_do_engine-3.15.5 app/models/message_sms_notification.rb
think_feel_do_engine-3.15.4 app/models/message_sms_notification.rb
think_feel_do_engine-3.15.3 app/models/message_sms_notification.rb
think_feel_do_engine-3.15.2 app/models/message_sms_notification.rb
think_feel_do_engine-3.15.1 app/models/message_sms_notification.rb
think_feel_do_engine-3.15.0 app/models/message_sms_notification.rb
think_feel_do_engine-3.14.9 app/models/message_sms_notification.rb
think_feel_do_engine-3.14.8 app/models/message_sms_notification.rb
think_feel_do_engine-3.14.7 app/models/message_sms_notification.rb
think_feel_do_engine-3.14.6 app/models/message_sms_notification.rb
think_feel_do_engine-3.14.5 app/models/message_sms_notification.rb
think_feel_do_engine-3.14.4 app/models/message_sms_notification.rb
think_feel_do_engine-3.14.3 app/models/message_sms_notification.rb
think_feel_do_engine-3.14.2 app/models/message_sms_notification.rb
think_feel_do_engine-3.14.1 app/models/message_sms_notification.rb
think_feel_do_engine-3.14.0 app/models/message_sms_notification.rb