class Monban::UseCase::Auth::Change::Authy

Public Instance Methods

change(params) click to toggle source
# File lib/monban/use_case/auth/change/authy.rb, line 22
def change(params)
  Getto::Params.new.validate(params) do |v|
    v.hash(
      account_id:   v.integer                         {|val| param_error!(account_id: val) },
      country_code: v.combine([v.string, v.not_empty]){|val| param_error!(country_code: val) },
      phone_number: v.combine([v.string, v.not_empty]){|val| param_error!(phone_number: val) },
    )
  end or param_error!(params: params)

  authy_id = authy.register_user(
    country_code: params[:country_code],
    phone_number: params[:phone_number],
  ) or error.invalid_account! "params: #{params}"

  repository.transaction do
    repository.update_authy_id(
      account_id: params[:account_id],
      authy_id:   authy_id,
      now:        time.now,
    )
  end

  nil
end