Class: SmsNotification

Inherits:
Notification show all
Defined in:
lib/app/models/sms_notification.rb

Overview

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!

Constant Summary

Constants inherited from Notification

Notification::ALL_STATES, Notification::DELIVERY_EMAIL, Notification::DELIVERY_SLACK, Notification::DELIVERY_SMS, Notification::STATE_INVALID, Notification::STATE_NEW, Notification::STATE_PROCESSED, Notification::STATE_PROCESSING, Notification::STATE_RESUBMITTED, Notification::STATE_RETRYING, Notification::STATE_SUBMITTED, Notification::STATE_VIEWED

Instance Method Summary collapse

Methods inherited from Notification

#account_message_template, #default_message_template, #deletable?, #deliver_message, #finish_processing, #from_template, #message_from_haml_file, #message_from_haml_text, #message_from_liquid_text, #message_from_template, #name, #render_liquid_text, #retry_delivery, #search_fields, #send_notification, #sendable?, #start_processing, #stringify_all, #successful?, #viewed

Methods included from SearchAble

#after_search_text, #before_search_text, included, #method_missing, #respond_to?, #respond_to_missing?, #search_fields, #sort_fields, #update_search_and_sort_text, #update_text

Methods included from StandardModel

#audit_action, #auto_strip_attributes, #capture_user_info, #clear_cache, #created_by_display_name, #delete_and_log, #destroy_and_log, included, #last_modified_by_display_name, #log_change, #log_deletion, #remove_blank_secure_fields, #save_and_log, #save_and_log!, #secure_fields, #update, #update!, #update_and_log, #update_and_log!

Methods included from App47Logger

clean_params, #clean_params, delete_parameter_keys, #log_controller_error, log_debug, #log_debug, log_error, #log_error, log_exception, #log_message, log_message, #log_warn, log_warn, mask_parameter_keys, #update_flash_messages

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SearchAble

Instance Method Details

#deliver_message!Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/app/models/sms_notification.rb', line 31

def deliver_message!
  return unless SystemConfiguration.twilio_configured?

  config = SystemConfiguration.configuration
   = config.
  auth_token = config.twilio_auth_token
  client = Twilio::REST::Client.new , auth_token
  twilio_message = if client.respond_to?(:account)
                     client..messages.create(body: message,
                                                    to: to,
                                                    from: config.twilio_phone_number)
                   else
                     client.messages.create(body: message,
                                            to: to,
                                            from: config.twilio_phone_number)
                   end
  # We are saved in the calling class, no reason to save again
  set sid: twilio_message.sid
end

#delivery_channelObject

set the delivery channel for the templates



54
55
56
# File 'lib/app/models/sms_notification.rb', line 54

def delivery_channel
  DELIVERY_SMS
end