Sha256: 7370d5905287b3bc902e93635c02a46181e9e13877b90b16052fd13dff0d1179

Contents?: true

Size: 1.46 KB

Versions: 84

Compression:

Stored size: 1.46 KB

Contents

#
# SmsNotification is a concrete class of Notification, sending sms to both members
# and users, or in the case of eCommerce, customers.
#
# This object allows you to create an SmsNotification object, set it's property and
# tell it send_notification. It'll handle everything from there including
# 1. Running in the background thread
# 2. Error recovery
# 3. Retry on failure
#
# The SMS object also uses the templating engine to allow the specification of a template
# and a set of local variables for dynamic content.
#
# Usage:
#
# sms = SmsNotification.new
# sms.to = '5713326267'
# sms.message = 'Day is today!'
# sms.send_notification
#
# You are done! Go about your business of creating awesome software!
#
class SmsNotification < Notification
  #
  # Fields
  #
  field :sid, type: String

  validates :to, presence: true, format: { with: /\A\+[1-9]{1}[0-9]{3,14}\z/ }

  def deliver_message!
    return unless SystemConfiguration.twilio_configured?

    config = SystemConfiguration.configuration
    account_sid = config.twilio_account_id
    auth_token = config.twilio_auth_token
    client = Twilio::REST::Client.new account_sid, auth_token

    twilio_message = client.account.messages.create(
      body: message,
      to: to,
      from: config.twilio_phone_number
    )
    # We are saved in the calling class, no reason to save again
    set sid: twilio_message.sid
  end

  #
  # set the delivery channel for the templates
  #
  def delivery_channel
    DELIVERY_SMS
  end
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
web47core-1.1.15 lib/app/models/sms_notification.rb
web47core-1.1.14 lib/app/models/sms_notification.rb
web47core-1.1.13 lib/app/models/sms_notification.rb
web47core-1.1.12 lib/app/models/sms_notification.rb
web47core-1.1.11 lib/app/models/sms_notification.rb
web47core-2.0.1 lib/app/models/sms_notification.rb
web47core-2.0.0 lib/app/models/sms_notification.rb
web47core-1.1.10 lib/app/models/sms_notification.rb
web47core-1.1.9 lib/app/models/sms_notification.rb
web47core-1.1.8 lib/app/models/sms_notification.rb
web47core-1.1.7 lib/app/models/sms_notification.rb
web47core-1.1.6 lib/app/models/sms_notification.rb
web47core-1.1.5 lib/app/models/sms_notification.rb
web47core-1.1.4 lib/app/models/sms_notification.rb
web47core-1.1.3 lib/app/models/sms_notification.rb
web47core-1.1.2 lib/app/models/sms_notification.rb
web47core-1.1.1 lib/app/models/sms_notification.rb
web47core-1.1.0 lib/app/models/sms_notification.rb
web47core-1.0.18 lib/app/models/sms_notification.rb
web47core-1.0.17 lib/app/models/sms_notification.rb