Class: MetaSms::ProviderUtility

Inherits:
Object
  • Object
show all
Defined in:
lib/meta_sms/providers/provider_utility.rb

Overview

This is a utility class for sms providers. This encapsulates some common class methods as

> raise_low_balance_exception

This method will be used to raise an exception if the balance in sms service provider account is low.
This method can be called in the respective sms provider class. eg: sms_box.rb.

> raise_error_for_blank_value

This method is used to raise ArgumentError. This can be called in the sms_provider_interface (i_sms_provider) in order to raise the exception is value of any
required option is blank.

> check_required_config_param

This method is used to check presence of required config variables. It can be called in the respective sms provider class. eg: sms_box.rb.

Author:

  • Shobhit Dixit

Class Method Summary collapse

Class Method Details

.authentication_errorObject

This method will raise authentication error

Raises:

  • SecurityError

Author:

  • Shobhit Dixit



53
54
55
# File 'lib/meta_sms/providers/provider_utility.rb', line 53

def self.authentication_error
  raise SecurityError.new 'Authentication Failed. Please Try Again.'
end

.check_required_config_param(config_param) ⇒ Object

This method is used to check presence of required config variables

Parameters:

  • config_param (String/Symbol)

    parameters define in config file

Returns:

  • (Object)

    Value can be string or an object depending upon the value config variable

Raises:

  • ArgumentError if the value of the config param is blank

Author:

  • Shobhit Dixit



24
25
26
27
28
29
30
# File 'lib/meta_sms/providers/provider_utility.rb', line 24

def self.check_required_config_param(config_param)
  value = eval "MetaSms.config.#{config_param}"
  if value.blank?
    raise ArgumentError.new "Property #{config_param} is not found. Please check required parameters in initializer file (config/initializers/meta_sms.rb)."
  end
  value
end

.raise_error_for_blank_value(key) ⇒ Object

This method will raise ArgumentError

Parameters:

  • key (Symbol/String)

    of the @options in i_sms_provider

Raises:

  • ArgumentError

Author:

  • Shobhit Dixit



37
38
39
# File 'lib/meta_sms/providers/provider_utility.rb', line 37

def self.raise_error_for_blank_value(key)
  raise ArgumentError.new "No #{key} found."
end

.raise_low_balance_exceptionObject

This method will raise low balance error

Raises:

  • StandardError

Author:

  • Shobhit Dixit



45
46
47
# File 'lib/meta_sms/providers/provider_utility.rb', line 45

def self.raise_low_balance_exception
  raise MetaSmsError.new "Your balance is low for sending message."
end