Class: SendOtp::Otp
- Inherits:
-
Object
- Object
- SendOtp::Otp
- Defined in:
- lib/send_otp.rb
Instance Method Summary collapse
-
#initialize(auth_key, message_template = nil) ⇒ Otp
constructor
Creates a new SendOtp instance.
-
#retry(contact_number, retry_voice) ⇒ Object
Retry Otp to given mobile number.
-
#send_otp(contact_number, sender_id, otp = '', n = 4) ⇒ Object
Send Otp to given mobile number.
-
#verify(contact_number, otp) ⇒ Object
Verify Otp to given mobile number Return true if OTP verified successfully.
Constructor Details
#initialize(auth_key, message_template = nil) ⇒ Otp
Creates a new SendOtp instance
16 17 18 19 20 21 22 23 |
# File 'lib/send_otp.rb', line 16 def initialize(auth_key, =nil) @auth_key = auth_key if @message_template = else @message_template = 'Your otp is {{otp}}. Please do not share it with anybody' end end |
Instance Method Details
#retry(contact_number, retry_voice) ⇒ Object
Retry Otp to given mobile number
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/send_otp.rb', line 50 def retry(contact_number, retry_voice) # if retry voice is false, set `retry_type` as `text` else set it to `voice` call msg91 API to retry otp # return msg91 API response retry_type = 'voice' retry_type = 'text' unless retry_voice args = { authkey: @auth_key, mobile: contact_number, retrytype: retry_type } do_request('retryotp.php', args) end |
#send_otp(contact_number, sender_id, otp = '', n = 4) ⇒ Object
Send Otp to given mobile number
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/send_otp.rb', line 31 def send_otp(contact_number, sender_id, otp = '', n = 4) otp = generate_otp(n) if otp.to_s.empty? @message_template.gsub! '{{otp}}', otp.to_s args = { authkey: @auth_key, mobile: contact_number, sender: sender_id, message: @message_template, otp: otp } do_request('sendotp.php', args) end |
#verify(contact_number, otp) ⇒ Object
Verify Otp to given mobile number Return true if OTP verified successfully
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/send_otp.rb', line 70 def verify(contact_number, otp) args = { authkey: @auth_key, mobile: contact_number, otp: otp } response = do_request('verifyRequestOTP.php', args) body = eval(response.body) if body[:type] == 'success' true else false end rescue false end |