Class: Wavix::NumberValidator::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/wavix/number_validator/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/wavix/number_validator/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#create_bulk(request_options: {}, **params) ⇒ Wavix::Types::NumberValidatorCreateBulkResponse

Validates a batch of phone numbers. When async is true, returns a request_id to poll for results instead of the validation details.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/wavix/number_validator/client.rb', line 68

def create_bulk(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  request = Wavix::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v1/validation",
    body: Wavix::NumberValidator::Types::PhoneValidationRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Wavix::Types::NumberValidatorCreateBulkResponse.load(response.body)
  else
    error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get(request_options: {}, **params) ⇒ Wavix::Types::PhoneValidationResponse

Validates a single phone number and returns line type, carrier, portability, and reachability details. The response's error_code is a per-number result code (000 success; 013 internal error; 021 invalid format; 041 remote timeout; 042 remote query failed; 091 insufficient funds) — distinct from the HTTP status codes below.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/wavix/number_validator/client.rb', line 29

def get(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["phone_number"] = params[:phone_number] if params.key?(:phone_number)
  query_params["type"] = params[:type] if params.key?(:type)

  request = Wavix::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v1/validation",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Wavix::Types::PhoneValidationResponse.load(response.body)
  else
    error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#results ⇒ Wavix::Results::Client

Returns:

  • (Wavix::Results::Client)


92
93
94
# File 'lib/wavix/number_validator/client.rb', line 92

def results
  @results ||= Wavix::NumberValidator::Results::Client.new(client: @client)
end