Class: Wavix::NumberValidator::Client
- Inherits:
-
Object
- Object
- Wavix::NumberValidator::Client
- Defined in:
- lib/wavix/number_validator/client.rb
Instance Method Summary collapse
-
#create_bulk(request_options: {}, **params) ⇒ Wavix::Types::NumberValidatorCreateBulkResponse
Validates a batch of phone numbers.
-
#get(request_options: {}, **params) ⇒ Wavix::Types::PhoneValidationResponse
Validates a single phone number and returns line type, carrier, portability, and reachability details.
- #initialize(client:) ⇒ void constructor
- #results ⇒ Wavix::Results::Client
Constructor Details
#initialize(client:) ⇒ void
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.
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: [:base_url], method: "POST", path: "v1/validation", body: Wavix::NumberValidator::Types::PhoneValidationRequest.new(params).to_h, 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.
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: [:base_url], method: "GET", path: "v1/validation", query: query_params, 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
92 93 94 |
# File 'lib/wavix/number_validator/client.rb', line 92 def results @results ||= Wavix::NumberValidator::Results::Client.new(client: @client) end |