class SmsMisr::Handler
This class is responsible for sending the sms for the whole app
`send_message` uses sms misr SMS API which takes a longer time to receive the message `send_otp` uses sms misr OTP API which has a pre-set message identified by `token` and `Msignature` fields which is found on their website
Attributes
options[R]
Public Class Methods
new(phone_number)
click to toggle source
# File lib/sms_misr.rb, line 16 def initialize(phone_number) @options = { query: { username: username, password: password, mobile: phone_number, }, } end
Public Instance Methods
send_message(message, sender, language = 1)
click to toggle source
# File lib/sms_misr.rb, line 27 def send_message(message, sender, language = 1) return unenabled_message unless send_sms_enabled? @options[:query].merge!(message_params(message, sender, language)) result = self.class.post('/webapi', @options) result.parsed_response end
send_otp(otp)
click to toggle source
# File lib/sms_misr.rb, line 35 def send_otp(otp) return unenabled_message unless send_sms_enabled? @options[:query].merge!(otp_params(otp)) result = self.class.post('/vSMS', @options) result.parsed_response end
Private Instance Methods
fixed_message_signature()
click to toggle source
# File lib/sms_misr.rb, line 77 def fixed_message_signature ENV.fetch('FIXED_OTP_SMS_SIGNATURE') end
fixed_message_token()
click to toggle source
# File lib/sms_misr.rb, line 73 def fixed_message_token ENV.fetch('FIXED_OTP_SMS_TOKEN') end
message_params(message, sender, language)
click to toggle source
# File lib/sms_misr.rb, line 45 def message_params(message, sender, language) { language: language, sender: sender, message: message, } end
otp_params(otp)
click to toggle source
# File lib/sms_misr.rb, line 53 def otp_params(otp) { code: otp, token: fixed_message_token, Msignature: fixed_message_signature, } end
password()
click to toggle source
# File lib/sms_misr.rb, line 65 def password ENV.fetch('SMS_PASSWORD') end
send_sms_enabled?()
click to toggle source
# File lib/sms_misr.rb, line 69 def send_sms_enabled? ENV.fetch('SEND_SMS_ENABLED') == 'true' end
unenabled_message()
click to toggle source
# File lib/sms_misr.rb, line 81 def unenabled_message { message: 'sending sms is not enabled' } end
username()
click to toggle source
# File lib/sms_misr.rb, line 61 def username ENV.fetch('SMS_USERNAME') end