Class: MetaSms::ISmsProvider

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

Overview

ISmsProvider acts as an interface for all sms providers in this gem. It has a method send_sms, which every sms provider class must override or else error will be thrown. There is a constant REQUIRED_OPTIONS, which represents the required options in order to send message. for now, message_text and mobile_number is the only options that are required.

> ‘Sms provider class’ refers to the class which is a sms service provider and which inherits ISmsProvider. eg: providers/sms_box.rb

Author:

  • Shobhit Dixit

Direct Known Subclasses

Smsbox

Constant Summary collapse

REQUIRED_OPTIONS =
[:message_text, :mobile_number]

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ISmsProvider

Note:

here message_text and mobile_number are required params and others are optional

Initialize options

Examples:

{:message_text* => “Some text message”, :mobile_number* => 7894561237, :logging => boolean, :metadata =>json }

Parameters:

  • options (Hash)

Author:

  • Shobhit Dixit



23
24
25
# File 'lib/meta_sms/providers/i_sms_provider.rb', line 23

def initialize(options)
  @options = options
end

Instance Method Details

#check_for_valid_mobile_number(mobile_number) ⇒ Object



50
51
52
# File 'lib/meta_sms/providers/i_sms_provider.rb', line 50

def check_for_valid_mobile_number(mobile_number)
  mobile_number
end

#check_required_option(required_option_key) ⇒ Object

This method checks the presence of the value of the required options key This is called in sms provider class.

Parameters:

  • required_option_key (Symbol)

    one of the keys of @options whose presence needs to be checked.

Returns:

  • (Object)

    returned object can be string or object depending upon the value of the key in @options.

Author:

  • Shobhit Dixit



41
42
43
44
45
46
47
48
# File 'lib/meta_sms/providers/i_sms_provider.rb', line 41

def check_required_option(required_option_key)
  value = @options[required_option_key]
  if value.blank?
    ProviderUtility.raise_error_for_blank_value(required_option_key)
  else
    value
  end
end

#send_smsObject

Method to overide in every sms provider class in order to send sms

Raises:

  • NotImplementedError

Author:

  • Shobhit Dixit



31
32
33
# File 'lib/meta_sms/providers/i_sms_provider.rb', line 31

def send_sms
  raise NotImplementedError, "send_sms"
end