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 +4 -4
- data/README.md +1 -1
- data/lib/genderapi-phone-validator/client.rb +28 -25
- data/lib/genderapi-phone-validator/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 817e466060635482fe40ff3e62438539c85dbd9ce998e2f5ee14ef96b386c2af
|
4
|
+
data.tar.gz: d63736a55f0c66d996d17c8faf6c73bc8ca2164178710accd47f2772c49a2a0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 `
|
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
|
-
#
|
8
|
+
# PhoneValidator::Client
|
9
9
|
#
|
10
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
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
|
-
#
|
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
|
-
# @
|
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
|
-
# @
|
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
|
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
|
95
|
+
# Safely parses a JSON string to a Ruby Hash.
|
93
96
|
#
|
94
|
-
# @param body [String] JSON
|
95
|
-
# @return [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)
|
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.
|
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:
|