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::NumberValidator::Types::GetNumberValidatorResponse
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.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/wavix/number_validator/client.rb', line 65 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::NumberValidator::Types::GetNumberValidatorResponse
Validates a single phone number and returns line type, carrier, portability, and reachability details.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wavix/number_validator/client.rb', line 26 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::NumberValidator::Types::GetNumberValidatorResponse.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
89 90 91 |
# File 'lib/wavix/number_validator/client.rb', line 89 def results @results ||= Wavix::NumberValidator::Results::Client.new(client: @client) end |