Class: Monban::UseCase::Auth::Change::Authy

Inherits:
Base
  • Object
show all
Defined in:
lib/monban/use_case/auth/change/authy.rb

Instance Method Summary collapse

Instance Method Details

#change(params) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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