Class: Twilio::Rails::FindOrCreatePhoneCallerOperation

Inherits:
ApplicationOperation show all
Defined in:
app/operations/twilio/rails/find_or_create_phone_caller_operation.rb

Overview

Finds and returns a Models::PhoneCaller by phone number, or creates a new one if it does not exist. The operation will halt if the phone number is not valid or blank.

Note: Operations should be called with call(params) and not by calling new(params).execute directly.

Instance Method Summary collapse

Instance Method Details

#executeTwilio::Rails::Models::PhoneCaller

Returns The found or newly created phone caller.

Parameters:

  • phone_number (String)

    The phone number to find or create the phone caller.

Returns:



13
14
15
16
17
18
19
20
# File 'app/operations/twilio/rails/find_or_create_phone_caller_operation.rb', line 13

def execute
  halt nil unless valid_phone_number

  phone_caller = ::Twilio::Rails.config.phone_caller_class.find_or_initialize_by(phone_number: valid_phone_number)
  phone_caller.save! if phone_caller.new_record?

  phone_caller
end