Class: Vonage::NetworkSIMSwap

Inherits:
Namespace
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/vonage/network_sim_swap.rb

Instance Method Summary collapse

Instance Method Details

#check(phone_number:, max_age: nil) ⇒ Object

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vonage/network_sim_swap.rb', line 30

def check(phone_number:, max_age: nil)
  raise ArgumentError.new("`phone_number` must be in E.164 format") unless Phonelib.parse(phone_number).valid?
  raise ArgumentError.new("`phone_number` must be prepended with a `+`") unless phone_number.start_with?('+')
  if max_age
    raise ArgumentError.new("`max_age` must between 1 and 2400") unless max_age.between?(1, 2400)
  end

  params = {phone_number: phone_number}
  params[:max_age] = max_age if max_age

  request(
    '/camara/sim-swap/v040/check',
    params: camelcase(params),
    type: Post,
    auth_data: {
      login_hint: phone_number,
      purpose: 'FraudPreventionAndDetection',
      api_scope: 'check-sim-swap',
      auth_flow: :server_authentication
    }
  )
end

#retrieve_date(phone_number:) ⇒ Object

Raises:

  • (ArgumentError)


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/vonage/network_sim_swap.rb', line 65

def retrieve_date(phone_number:)
  raise ArgumentError.new("`phone_number` must be in E.164 format") unless Phonelib.parse(phone_number).valid?
  raise ArgumentError.new("`phone_number` must be prepended with a `+`") unless phone_number.start_with?('+')

  params = {phone_number: phone_number}

  request(
    '/camara/sim-swap/v040/retrieve-date',
    params: camelcase(params),
    type: Post,
    auth_data: {
      login_hint: phone_number,
      purpose: 'FraudPreventionAndDetection',
      api_scope: 'retrieve-sim-swap-date',
      auth_flow: :server_authentication
    }
  )
end