Class: PhoneValidator::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/genderapi-phone-validator/client.rb

Overview

Ruby SDK for Phone Number Validation & Formatter API from www.genderapi.io

This SDK allows you to:

- Validate international phone numbers
- Detect number type (mobile, landline, VoIP, etc.)
- Retrieve region and country 
- Format numbers to E.164 or national format

Learn more: www.genderapi.io

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, base_url: nil) ⇒ Client

Initialize the PhoneValidator client.

Parameters:

  • api_key (String)

    Your GenderAPI API key as a Bearer token.

  • base_url (String) (defaults to: nil)

    Optional override for the API base URL.



28
29
30
31
32
33
34
35
# File 'lib/genderapi-phone-validator/client.rb', line 28

def initialize(api_key:, base_url: nil)
  @api_key = api_key
  self.class.base_uri(base_url) if base_url
  @headers = {
    "Authorization" => "Bearer #{@api_key}",
    "Content-Type" => "application/json"
  }
end

Instance Method Details

#validate(number:, address: "") ⇒ Hash

Validate and format a phone number.

Parameters:

  • number (String)

    The phone number to validate (required).

  • address (String) (defaults to: "")

    Optional address or country hint for better accuracy.

Returns:

  • (Hash)

    Parsed JSON response containing validation results.



45
46
47
48
49
50
51
52
# File 'lib/genderapi-phone-validator/client.rb', line 45

def validate(number:, address: "")
  payload = {
    number: number,
    address: address
  }

  _post_request("/api/phone", payload)
end