countriesdb-validator 1.0.2 → 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: 026bd1abf019234cfa5a5e08a050b3ab17c3e99e319bf57069443c3db9dbc863
4
- data.tar.gz: aa98cd6d11a466069cce9e09bbf4338b98e47e27209f4201965ce5a0ebe57950
3
+ metadata.gz: 20fcd315ef042db5a02d2f38ae2ea88bed36a5a06e56d0bb2e86adfb8392fc88
4
+ data.tar.gz: 02dd3af60deb0fc770a8b744604280ad5b0e2e385c95aefc017af2f7eaa3936b
5
5
  SHA512:
6
- metadata.gz: 6b6aeebf408fa743eec4c54854169d179359bed45299de778ae5935a7d9d4b398a580ed3bd874ca5e96ce06f3f24dd748b2174095be3303bd68f2db43c95efe4
7
- data.tar.gz: fb946815907c2308c9c55551aedc1b408db7621eba1b9acc4da6c141860d81dc89375de4789398a55a0036dbf6cca016dd4f594a6e07cface9a379c4b99eff30
6
+ metadata.gz: 28cbe56f977aea0d43557d2c690ba9391ce8ef9ec03739c617f4d32f2b1c26d9a257d99b8dc9984e8fd1689f3a8f35c2daf1b8f2c184e074add7a7cc6ab247f0
7
+ data.tar.gz: 2341e668e3fd206734b3ea017e4e59c727f78f6c204bf2f9dcb96db9aaaabb3e26301e363d5d3596ff95362f48746e4071b660a488b266c2329d26f0538add3d
data/README.md CHANGED
@@ -199,6 +199,52 @@ post '/api/user' do
199
199
  end
200
200
  ```
201
201
 
202
+ ## Error Handling
203
+
204
+ ### Single-Value Methods
205
+
206
+ Single-value methods (`validate_country`, `validate_subdivision`) return validation results with `valid: false` for invalid input. They only raise exceptions on network errors:
207
+
208
+ ```ruby
209
+ begin
210
+ result = validator.validate_country('US')
211
+ unless result[:valid]
212
+ puts "Validation failed: #{result[:message]}"
213
+ end
214
+ rescue StandardError => e
215
+ puts "Network error: #{e.message}"
216
+ end
217
+ ```
218
+
219
+ ### Multi-Value Methods
220
+
221
+ Multi-value methods (`validate_countries`, `validate_subdivisions`) return per-item results. Invalid codes are included in the results array with `valid: false`. They only raise exceptions on network errors or invalid input types:
222
+
223
+ ```ruby
224
+ begin
225
+ results = validator.validate_countries(['US', 'BAD', 'CA'])
226
+ # Results: [
227
+ # {code: 'US', valid: true},
228
+ # {code: 'BAD', valid: false, message: 'Invalid country code.'},
229
+ # {code: 'CA', valid: true}
230
+ # ]
231
+
232
+ results.each do |result|
233
+ unless result[:valid]
234
+ puts "Code #{result[:code]} failed: #{result[:message]}"
235
+ end
236
+ end
237
+ rescue StandardError => e
238
+ puts "Network error: #{e.message}"
239
+ end
240
+ ```
241
+
242
+ **Note:**
243
+ - Empty arrays return empty results arrays (not an error)
244
+ - Basic type checks are performed client-side (e.g., ensuring arrays are arrays, country is a string)
245
+ - Format validation (e.g., 2-character country codes) is handled by the backend and included in results with appropriate error messages
246
+ - Invalid format codes or invalid country codes are returned in the results array with `valid: false` rather than raising exceptions
247
+
202
248
  ## Requirements
203
249
 
204
250
  - Ruby 2.7+
@@ -38,14 +38,8 @@ module CountriesDB
38
38
  # @param codes [Array<String>] Array of ISO 3166-1 alpha-2 country codes
39
39
  # @return [Array<Hash>] Array of results with :code, :valid, and optional :message
40
40
  def validate_countries(codes, follow_upward: false)
41
- return [] if codes.nil? || codes.empty?
42
-
43
- # Validate format
44
- codes.each do |code|
45
- if code.nil? || code.length != 2
46
- raise ArgumentError, 'Invalid country code format. All codes must be 2-character strings.'
47
- end
48
- end
41
+ raise ArgumentError, 'Codes must be an array' unless codes.is_a?(Array)
42
+ return [] if codes.empty?
49
43
 
50
44
  begin
51
45
  response = make_request('/api/validate/country', {
@@ -89,8 +83,11 @@ module CountriesDB
89
83
  # @param allow_parent_selection [Boolean] Whether to allow selecting parent subdivisions
90
84
  # @return [Array<Hash>] Array of results with :code, :valid, and optional :message
91
85
  def validate_subdivisions(codes, country, follow_related: false, allow_parent_selection: false)
92
- raise ArgumentError, 'Invalid country code.' if country.nil? || country.length != 2
93
- return [] if codes.nil? || codes.empty?
86
+ raise ArgumentError, 'Codes must be an array' unless codes.is_a?(Array)
87
+ return [] if codes.empty?
88
+
89
+ # Basic type check for country - format validation handled by backend
90
+ raise ArgumentError, 'Country must be a string' unless country.is_a?(String)
94
91
 
95
92
  begin
96
93
  response = make_request('/api/validate/subdivision', {
@@ -1,5 +1,5 @@
1
1
  module CountriesDB
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
4
4
 
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: countriesdb-validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - NAYEE LLC
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-12-23 00:00:00.000000000 Z
12
+ date: 2026-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json