Class: Otp::Send
- Inherits:
-
Object
- Object
- Otp::Send
- 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
-
#call ⇒ UserVerification
This method creates a verification record for the given phone number.
-
#initialize(resource, phone_number) ⇒ Send
constructor
A new instance of Send.
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
#call ⇒ UserVerification
This method creates a verification record for the given phone number. It uses the ‘verifications` association of the resource to create a new record.
20 21 22 |
# File 'lib/otp/send.rb', line 20 def call @resource.verifications.create!(phone_number: @phone_number) end |