genderapi-phone-validator 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcbce725066c9e0c1b241a4a73f1224e7b6586501ca98e709aa87fa1ee2fe417
4
- data.tar.gz: 377a2c529ac9f17f4c337486b91849935e803dda0837a1b70b17cf083af4cedc
3
+ metadata.gz: 817e466060635482fe40ff3e62438539c85dbd9ce998e2f5ee14ef96b386c2af
4
+ data.tar.gz: d63736a55f0c66d996d17c8faf6c73bc8ca2164178710accd47f2772c49a2a0f
5
5
  SHA512:
6
- metadata.gz: 775b58044a8433964cc7a4b37da29d89338ba83dc7a7c993e0148d7604577a65bfb5ead37f5b554dc08771b8df07d665e4f50aa7b255121fbb90e71888a89fda
7
- data.tar.gz: aee42e5100ba41e97b61e5d60dbea35d972666117468f012d7435865ea850cc138a3000316ecf4eb54fe2ee1db008b22019d78c111af77b678937805f9f43ff4
6
+ metadata.gz: 5e506a1c7c6cacdf63daa787872d5750b131f85f6bd516ab648178bf899eee2e99ca97e75a9abba1fb1b58b1ba28721c9d71b2dcad9d25cdfb0cbd51652f8afb
7
+ data.tar.gz: 52e9476ea6a953c06c5b981c14f88dbadc6fedd96e9a28caba8a074a6b9082a8b533501a3c711a52415a6559aad5bb3693ddad4cf9ea0337c33243375124e5ca
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # 📞 Phone Number Validation & Formatter API (Ruby SDK)
2
2
 
3
- The `phonevalidator` gem uses the official [GenderAPI Phone Number Validation & Formatter API](https://www.genderapi.io/) to validate and format phone numbers from over 240 countries and territories.
3
+ The `genderapi-phone-validator` gem uses the official [GenderAPI Phone Number Validation & Formatter API](https://www.genderapi.io/) to validate and format phone numbers from over 240 countries and territories.
4
4
 
5
5
  Whether your users enter phone numbers in various formats (e.g., `12128675309`, `+1 212 867 5309`, `001-212-867-5309`), this library will intelligently detect, validate, and convert the input into a standardized E.164 format (e.g., `+12128675309`).
6
6
 
@@ -5,25 +5,30 @@ require "json"
5
5
 
6
6
  module PhoneValidator
7
7
  ##
8
- # Ruby SDK for Phone Number Validation & Formatter API from www.genderapi.io
8
+ # PhoneValidator::Client
9
9
  #
10
- # This SDK allows you to:
11
- # - Validate international phone numbers
12
- # - Detect number type (mobile, landline, VoIP, etc.)
13
- # - Retrieve region and country metadata
14
- # - Format numbers to E.164 or national format
10
+ # Ruby SDK for the Phone Number Validation & Formatter API provided by [GenderAPI](https://www.genderapi.io).
15
11
  #
16
- # Learn more: https://www.genderapi.io
12
+ # This class allows you to:
13
+ # - Validate international phone numbers
14
+ # - Detect number type (mobile, landline, VoIP, etc.)
15
+ # - Retrieve region and country metadata
16
+ # - Format numbers to E.164 or national format
17
+ #
18
+ # @example Basic usage
19
+ # client = PhoneValidator::Client.new(api_key: "your_api_key")
20
+ # result = client.validate(number: "+1 212 867 5309", address: "US")
21
+ # puts result["e164"]
17
22
  #
18
23
  class Client
19
24
  include HTTParty
20
25
  base_uri "https://api.genderapi.io"
21
26
 
22
27
  ##
23
- # Initialize the PhoneValidator client.
28
+ # Initializes a new client instance.
24
29
  #
25
30
  # @param api_key [String] Your GenderAPI API key as a Bearer token.
26
- # @param base_url [String] Optional override for the API base URL.
31
+ # @param base_url [String] Optional override for the base URL (defaults to api.genderapi.io).
27
32
  #
28
33
  def initialize(api_key:, base_url: nil)
29
34
  @api_key = api_key
@@ -35,12 +40,15 @@ module PhoneValidator
35
40
  end
36
41
 
37
42
  ##
38
- # Validate and format a phone number.
43
+ # Validates and formats a phone number.
44
+ #
45
+ # @param number [String] Phone number in any format (required).
46
+ # @param address [String] Optional. Country code (e.g., 'US'), full country name, or city name to improve accuracy.
39
47
  #
40
- # @param number [String] The phone number to validate (required).
41
- # @param address [String] Optional address or country hint for better accuracy.
48
+ # @return [Hash] The parsed JSON response as a Ruby Hash.
42
49
  #
43
- # @return [Hash] Parsed JSON response containing validation results.
50
+ # @example Validate number
51
+ # client.validate(number: "+1 212 867 5309", address: "US")
44
52
  #
45
53
  def validate(number:, address: "")
46
54
  payload = {
@@ -54,17 +62,12 @@ module PhoneValidator
54
62
  private
55
63
 
56
64
  ##
57
- # Internal helper for sending POST requests to the GenderAPI.io API.
58
- #
59
- # Handles:
60
- # - Bearer token authorization
61
- # - Payload cleanup (removal of nil values)
62
- # - Error handling and JSON parsing
65
+ # Internal helper to POST a request to the API and parse the result.
63
66
  #
64
- # @param endpoint [String] API endpoint path (e.g. "/api/phone")
65
- # @param payload [Hash] Request body
67
+ # @param endpoint [String] API endpoint path (e.g. "/api/phone").
68
+ # @param payload [Hash] Request body to be sent as JSON.
66
69
  #
67
- # @return [Hash] Parsed JSON response
70
+ # @return [Hash] Parsed JSON response.
68
71
  #
69
72
  def _post_request(endpoint, payload)
70
73
  cleaned_payload = payload.reject { |_k, v| v.nil? }
@@ -89,10 +92,10 @@ module PhoneValidator
89
92
  end
90
93
 
91
94
  ##
92
- # Safely parse JSON response.
95
+ # Safely parses a JSON string to a Ruby Hash.
93
96
  #
94
- # @param body [String] JSON string
95
- # @return [Hash] Ruby Hash
97
+ # @param body [String] Raw JSON response.
98
+ # @return [Hash] Parsed JSON as Hash.
96
99
  #
97
100
  def parse_json(body)
98
101
  JSON.parse(body)
@@ -1,5 +1,5 @@
1
1
  # lib/phonevalidador/version.rb
2
2
 
3
3
  module PhoneValidator
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genderapi-phone-validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Onur Ozturk
@@ -73,6 +73,7 @@ licenses:
73
73
  metadata:
74
74
  source_code_uri: https://github.com/GenderAPI/phone-validator-ruby
75
75
  changelog_uri: https://github.com/GenderAPI/phone-validator-ruby/blob/main/CHANGELOG.md
76
+ documentation_uri: https://rubydoc.info/github/GenderAPI/phone-validator-ruby
76
77
  post_install_message:
77
78
  rdoc_options: []
78
79
  require_paths: