Class: Soteria::SMS

Inherits:
Object
  • Object
show all
Defined in:
lib/soteria/sms.rb

Instance Method Summary collapse

Instance Method Details

#check_otp(client, user_id, otp) ⇒ Hash

Check if the otp that a user entered is valid or not.

Parameters:

  • user_id (String)

    Id of the user to authenticate. This is the user id that is stored in the Symantec db.

  • otp (Object)

    The otp that was sent to the user via sms or voice

  • client (Savon::Client)

    A Savon client object to make the call with. This needs to be created with the VIP authentication WSDL.

Returns:

  • (Hash)

    A hash with all information about if the otp was successful



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/soteria/sms.rb', line 65

def check_otp(client, user_id, otp)
  check_otp_response = client.call(:check_otp, message: create_check_otp_body(user_id, otp))
  result_hash = check_otp_response.body[:check_otp_response]

  success = result_hash[:status] == '0000'

  {
      success: success,
      id: result_hash[:request_id],
      message: result_hash[:status_message]
  }
end

#create_check_otp_body(user_id, otp) ⇒ Hash

Creates the body for a check otp request.

Parameters:

  • user_id (String)

    Id of the user to authenticate. This is the user id that is stored in the Symantec db.

  • otp (Object)

    The otp that was sent to the user via sms or voice

Returns:

  • (Hash)

    A hash representing the body of the soap request to check if an otp is valid.



47
48
49
50
51
52
53
54
55
56
# File 'lib/soteria/sms.rb', line 47

def create_check_otp_body(user_id, otp)
  {
      'vip:requestId': Utilities.get_request_id('check_sms_otp'),
      'vip:userId': user_id,
      'vip:otpAuthData':
          {
              'vip:otp': otp
          }
  }
end

#create_send_sms_body(user_id, phone_number) ⇒ Hash

Creates the body for a send SMS otp request.

Parameters:

  • user_id (String)

    Id of the user to authenticate. This is the user id that is stored in the Symantec database.

  • phone_number (Int)

    The phone number that the sms code should be sent to.

Returns:

  • (Hash)

    A hash with all information about if the otp was successful.



11
12
13
14
15
16
17
18
19
20
# File 'lib/soteria/sms.rb', line 11

def create_send_sms_body(user_id, phone_number)
  {
      'vip:requestId': Utilities.get_request_id('send_sms_otp'),
      'vip:userId': user_id,
      'vip:smsDeliveryInfo':
          {
              'vip:phoneNumber': phone_number
          }
  }
end

#send_sms(client, user_id, phone_number) ⇒ Hash

Send a sms One Time Password to a user.

Parameters:

  • user_id (String)

    Id of the user to authenticate. This is the user id that is stored in the Symantec database.

  • client (Savon::Client)

    A Savon client object to make the call with. This needs to be created with the VIP management WSDL.

  • phone_number (Int)

    The phone number that the sms code should be sent to.

Returns:

  • (Hash)

    A hash with all the appropriate information about the status of the SMS.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/soteria/sms.rb', line 29

def send_sms(client, user_id, phone_number)
  sms_res = client.call(:send_otp, message: create_send_sms_body(user_id, phone_number))
  result_hash = sms_res.body[:send_otp_response]
  success = result_hash[:status] == '0000'

  {
      success: success,
      id: result_hash[:request_id],
      message: result_hash[:status_message]
  }
end