Class: Ravelin::AuthenticationMechanisms::MagicLink

Inherits:
RavelinObject
  • Object
show all
Defined in:
lib/ravelin/authentication_mechanisms/magic_link.rb

Constant Summary collapse

TRANSPORTATION_MECHANISM =
%w(email sms)
FAILURE_REASONS =
%w(INVALID_LINK TIMEOUT INTERNAL_ERROR RATE_LIMIT BANNED_USER)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RavelinObject

attr_accessor, attr_required, #initialize, required_attributes, #serializable_hash

Constructor Details

This class inherits a constructor from Ravelin::RavelinObject

Instance Attribute Details

#emailObject

Returns the value of attribute email.



7
8
9
# File 'lib/ravelin/authentication_mechanisms/magic_link.rb', line 7

def email
  @email
end

#failure_reasonObject

Returns the value of attribute failure_reason.



7
8
9
# File 'lib/ravelin/authentication_mechanisms/magic_link.rb', line 7

def failure_reason
  @failure_reason
end

#phone_numberObject

Returns the value of attribute phone_number.



7
8
9
# File 'lib/ravelin/authentication_mechanisms/magic_link.rb', line 7

def phone_number
  @phone_number
end

#successObject

Returns the value of attribute success.



7
8
9
# File 'lib/ravelin/authentication_mechanisms/magic_link.rb', line 7

def success
  @success
end

#transportObject

Returns the value of attribute transport.



7
8
9
# File 'lib/ravelin/authentication_mechanisms/magic_link.rb', line 7

def transport
  @transport
end

Instance Method Details

#validateObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ravelin/authentication_mechanisms/magic_link.rb', line 14

def validate
  super

  if !success && !FAILURE_REASONS.include?(failure_reason)
    raise ArgumentError.new("Failure reason value must be one of #{FAILURE_REASONS.join(', ')}")
  end

  if !TRANSPORTATION_MECHANISM.include?(transport)
    raise ArgumentError.new("Transportation mechanism value must be one of #{TRANSPORTATION_MECHANISM.join(', ')}")
  end

  if transport == 'email' && email.nil?
    raise ArgumentError.new("email must be present for email transportation mechanism")
  end

  if transport == 'sms' && phone_number.nil?
    raise ArgumentError.new("phone_number must be present for sms transportation mechanism")
  end
end