# require 'twilio-ruby'

class UsersController < ActionController::API
  def send_verification_code
    account_sid = ENV['TWILIO_ACCOUNT_SID']
    auth_token = ENV['TWILIO_AUTH_TOKEN']
    @client = Twilio::REST::Client.new(account_sid, auth_token)
    @client.messages.create(
      from: ENV['TWILIO_NUMBER'],
      to: params[:number],
      body: 'Random number!'
    )
    puts "it should have worked."
  end

end

# require 'twilio-ruby'

class UsersController < ActionController::API
  include UsersHelper

  def send_verification_code
    setup_sms
    send_sms(params[:number],
      "Your verification code is: " + generate_verification_code)
  end

  private

    def generate_verification_code
      totp = ROTP::TOTP.new("base32secret3232")
      totp.now.to_s
    end

    def setup_sms
      account_sid = ENV['TWILIO_ACCOUNT_SID']
      auth_token = ENV['TWILIO_AUTH_TOKEN']
      @client = Twilio::REST::Client.new(account_sid, auth_token)
    end

    def send_sms(deliver_to, body)
      @client.messages.create(
        from: ENV['TWILIO_NUMBER'],
        to: deliver_to,
        body: body)
    end

end

Add private method for generating verification codes; refactor send_verification_code by also creating private methods for setup_sms and send_sms behavior to be reused in other routes
Add private method for generating verification codes; refactor send_verification_code by also creating private methods for setup_sms and send_sms behavior to be reused in other routes
