Class: MetaSms::SmsLogging

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/meta_sms/sms_logging.rb

Overview

This is an ActiveRecord class. It is used to save sms log in db.

Author:

  • Shobhit Dixit

Class Method Summary collapse

Class Method Details

.get_sms_logging_object(result, options, error) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/meta_sms/sms_logging.rb', line 22

def self.get_sms_logging_object(result, options, error)
  sms_logging_object = {
    message_text: options[:message_text],
    mobile_number: options[:mobile_number],
    error_message: error.try(:message)
  }
   = options[:metadata]
  sms_logging_object[:metadata] = {:response => result}.as_json
  sms_logging_object[:metadata].merge() if .present?
  sms_logging_object
end

.log_sms(result, options, error) ⇒ Object

Description of method

Parameters:

  • result (String)

    of .send_sms method in provider class

  • options (Hash)

    provided in ISmsProvider

  • error (Error)

    raised by .send_sms method in provider class

Author:

  • Shobhit Dixit



14
15
16
17
18
19
20
# File 'lib/meta_sms/sms_logging.rb', line 14

def self.log_sms(result, options, error)
  if ActiveRecord::Base.connection.table_exists? self.table_name
    SmsLogging.create( SmsLogging.get_sms_logging_object(result, options, error) )
  else
    raise StandardError.new "No table exists. Please run 'rails g meta_sms:migrations_for_logger' and then run 'rake db:migrate'. To disable this warning, make config.logging=false, in config/initializers/meta_sms.rb."
  end
end