Class: Otp::Send

Inherits:
Object
  • Object
show all
Defined in:
lib/otp/send.rb

Overview

This class is responsible for sending a verification request to a specified phone number. It initializes with a resource (which should respond to ‘verifications`) and a phone number. It raises errors if the resource is invalid or the phone number is not valid. It creates a verification record when the `call` method is invoked.

Instance Method Summary collapse

Constructor Details

#initialize(resource, phone_number) ⇒ Send

Returns a new instance of Send.



9
10
11
12
13
14
15
# File 'lib/otp/send.rb', line 9

def initialize(resource, phone_number)
  @resource = resource
  @phone_number = phone_number

  raise Otp::Errors::InvalidResourceError unless @resource.respond_to?(:verifications)
  raise Otp::Errors::InvalidPhoneNumberError unless Phonelib.valid?(@phone_number)
end

Instance Method Details

#callUserVerification

This method creates a verification record for the given phone number. It uses the ‘verifications` association of the resource to create a new record.

Returns:



20
21
22
# File 'lib/otp/send.rb', line 20

def call
  @resource.verifications.create!(phone_number: @phone_number)
end