dni_peru 0.1.0 → 0.1.2

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: 7847ab9a63151aa066c6e6132fb8c153607a992011a09029718bb7de1f4aca2e
4
- data.tar.gz: b68a9e93403b81cb5add28774122308fcbeb046de481378a5fd6793139fa1034
3
+ metadata.gz: e99c7d27242e218e76a5020a70025b2264d2b1b65e097167bc2c787479c825c7
4
+ data.tar.gz: f8e14cda0b1e52e36125d3b3cffe75af7296baf90da81d0819f31899d0f2efaf
5
5
  SHA512:
6
- metadata.gz: ab9be7bab4c723630871fc454df03c13ba5e17b8c2ba9233b1ec6ce6b6628fc3c4e7a6a150f4b334deb20cd3d44cacb41d0419f6875e7f088e670ea999131dca
7
- data.tar.gz: 0ec1fefcc683bcd0af7a048d2c4203e9e5b3464b78ebd97c2739520233cd8870c1320bd458740bb37904493113246f88d278e8a02f3071ca8dc5d871a8d23e0c
6
+ metadata.gz: 51f8b123dd45070d251139d50c337fe45d47d267b7b8486715edfdac16808cac00cac0012692856d2da909505f579de267111b86b863113faa28fb2d6c95ccf8
7
+ data.tar.gz: 5e916caaf3fcf1ec8be57d6e329183b5de1349073e1f03968161510ecdd314fdfe1c6c6d76946e2310e180999b64885365acbe5d7b424caf28ee8874a32bd40a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.2] - 2025-12-09
4
+
5
+ ### Fixed
6
+ - Fixed Decolecta provider field mapping to match actual API response format
7
+ - Updated field names: `document_number`, `first_name`, `first_last_name`, `second_last_name`
8
+ - Provider now correctly parses Decolecta API responses
9
+
3
10
  ## [0.1.0] - 2025-11-28
4
11
 
5
12
  ### Added
data/debug_api.rb ADDED
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env ruby
2
+ # Diagnostic script to test Decolecta API
3
+ # Usage: ruby debug_api.rb YOUR_API_KEY DNI_NUMBER
4
+
5
+ require "bundler/setup"
6
+ require "faraday"
7
+ require "json"
8
+
9
+ api_key = ARGV[0]
10
+ dni = ARGV[1] || "12345678"
11
+
12
+ if api_key.nil? || api_key.empty?
13
+ puts "❌ Usage: ruby debug_api.rb YOUR_API_KEY [DNI_NUMBER]"
14
+ puts " Example: ruby debug_api.rb abc123xyz 12345678"
15
+ exit 1
16
+ end
17
+
18
+ puts "=" * 80
19
+ puts "Decolecta API Diagnostic Test"
20
+ puts "=" * 80
21
+ puts "API Key: #{api_key[0..10]}..."
22
+ puts "DNI: #{dni}"
23
+ puts "=" * 80
24
+ puts ""
25
+
26
+ # Test 1: Direct API call
27
+ puts "Test 1: Direct API Request"
28
+ puts "-" * 80
29
+
30
+ base_url = "https://api.decolecta.com/v1/reniec/dni"
31
+
32
+ begin
33
+ conn = Faraday.new do |f|
34
+ f.adapter Faraday.default_adapter
35
+ f.options.timeout = 30
36
+ end
37
+
38
+ puts "Request URL: #{base_url}?numero=#{dni}"
39
+ puts "Authorization: Bearer #{api_key[0..10]}..."
40
+ puts ""
41
+
42
+ response = conn.get(base_url) do |req|
43
+ req.params["numero"] = dni
44
+ req.headers["Authorization"] = "Bearer #{api_key}"
45
+ req.headers["Accept"] = "application/json"
46
+ end
47
+
48
+ puts "Response Status: #{response.status}"
49
+ puts "Response Headers:"
50
+ response.headers.each do |key, value|
51
+ puts " #{key}: #{value}"
52
+ end
53
+ puts ""
54
+ puts "Response Body:"
55
+ puts response.body
56
+ puts ""
57
+
58
+ if response.status == 200
59
+ begin
60
+ data = JSON.parse(response.body, symbolize_names: true)
61
+ puts "✅ Success! Parsed JSON:"
62
+ puts JSON.pretty_generate(data)
63
+ rescue JSON::ParserError => e
64
+ puts "⚠️ Warning: Response is not valid JSON"
65
+ puts "Error: #{e.message}"
66
+ end
67
+ else
68
+ puts "❌ Error Response:"
69
+ case response.status
70
+ when 401
71
+ puts " - Invalid or missing API key"
72
+ puts " - Check your API key at: https://decolecta.com/profile/"
73
+ when 404
74
+ puts " - DNI not found in database"
75
+ puts " - Try a different DNI number"
76
+ when 429
77
+ puts " - Rate limit exceeded"
78
+ puts " - Wait a moment and try again"
79
+ when 500, 502, 503
80
+ puts " - Server error"
81
+ puts " - The API service might be down"
82
+ else
83
+ puts " - Unexpected error code: #{response.status}"
84
+ end
85
+ end
86
+ rescue Faraday::ConnectionFailed => e
87
+ puts "❌ Connection Failed"
88
+ puts "Error: #{e.message}"
89
+ puts "Check your internet connection and API service status"
90
+ rescue Faraday::TimeoutError => e
91
+ puts "❌ Request Timeout"
92
+ puts "Error: #{e.message}"
93
+ puts "The API is taking too long to respond"
94
+ rescue StandardError => e
95
+ puts "❌ Unexpected Error"
96
+ puts "Error: #{e.class}: #{e.message}"
97
+ puts e.backtrace.first(5)
98
+ end
99
+
100
+ puts ""
101
+ puts "=" * 80
102
+
103
+ # Test 2: Try alternative endpoint format
104
+ puts "Test 2: Testing Alternative Endpoint Formats"
105
+ puts "-" * 80
106
+
107
+ alternative_urls = [
108
+ "https://api.decolecta.com/v1/reniec/dni?numero=#{dni}",
109
+ "https://api.decolecta.com/v1/dni?numero=#{dni}",
110
+ "https://api.decolecta.com/reniec/dni?numero=#{dni}"
111
+ ]
112
+
113
+ alternative_urls.each_with_index do |url, index|
114
+ puts "\n#{index + 1}. Testing: #{url}"
115
+
116
+ begin
117
+ conn = Faraday.new
118
+ response = conn.get(url) do |req|
119
+ req.headers["Authorization"] = "Bearer #{api_key}"
120
+ req.headers["Accept"] = "application/json"
121
+ end
122
+
123
+ puts " Status: #{response.status}"
124
+ if response.status == 200
125
+ puts " ✅ This endpoint works!"
126
+ puts " Body: #{response.body[0..100]}..."
127
+ end
128
+ rescue StandardError => e
129
+ puts " ❌ Error: #{e.message}"
130
+ end
131
+ end
132
+
133
+ puts ""
134
+ puts "=" * 80
135
+ puts "Diagnostic complete!"
136
+ puts ""
137
+ puts "Next steps:"
138
+ puts "1. If 401: Check your API key at https://decolecta.com/profile/"
139
+ puts "2. If 404: Try a real DNI number (8 digits)"
140
+ puts "3. If connection error: Check API status or try later"
141
+ puts "4. If successful: Use that exact endpoint format in the gem"
142
+ puts "=" * 80
@@ -21,10 +21,10 @@ module DniPeru
21
21
 
22
22
  def normalize_data(data)
23
23
  {
24
- dni: data[:numeroDocumento] || data[:numero_documento],
25
- nombres: data[:nombres],
26
- apellido_paterno: data[:apellidoPaterno] || data[:apellido_paterno],
27
- apellido_materno: data[:apellidoMaterno] || data[:apellido_materno]
24
+ dni: data[:document_number] || data[:numeroDocumento] || data[:numero_documento],
25
+ nombres: data[:first_name] || data[:nombres],
26
+ apellido_paterno: data[:first_last_name] || data[:apellidoPaterno] || data[:apellido_paterno],
27
+ apellido_materno: data[:second_last_name] || data[:apellidoMaterno] || data[:apellido_materno]
28
28
  }
29
29
  end
30
30
  end
@@ -1,3 +1,3 @@
1
1
  module DniPeru
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.1.2".freeze
3
3
  end
data/test_gem.rb ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ # Test the gem with real Decolecta API
3
+ # Usage: ruby test_gem.rb YOUR_API_KEY DNI_NUMBER
4
+
5
+ require_relative "lib/dni_peru"
6
+
7
+ api_key = ARGV[0]
8
+ dni = ARGV[1] || "45603792"
9
+
10
+ if api_key.nil? || api_key.empty?
11
+ puts "❌ Usage: ruby test_gem.rb YOUR_API_KEY [DNI_NUMBER]"
12
+ puts " Example: ruby test_gem.rb sk_xxx 45603792"
13
+ exit 1
14
+ end
15
+
16
+ puts "=" * 80
17
+ puts "Testing DniPeru Gem with Decolecta"
18
+ puts "=" * 80
19
+ puts ""
20
+
21
+ # Configure the gem
22
+ DniPeru.configure do |config|
23
+ config.set_api_key(:decolecta, api_key)
24
+ config.default_provider = :decolecta
25
+ config.timeout = 30
26
+ end
27
+
28
+ puts "Configuration:"
29
+ puts " Provider: #{DniPeru.configuration.default_provider}"
30
+ puts " API Key: #{api_key[0..10]}..."
31
+ puts " DNI: #{dni}"
32
+ puts ""
33
+ puts "-" * 80
34
+
35
+ begin
36
+ puts "Querying DNI: #{dni}..."
37
+ response = DniPeru.query(dni)
38
+
39
+ if response.success?
40
+ puts "✅ Success!"
41
+ puts ""
42
+ puts "Results:"
43
+ puts " DNI: #{response.dni}"
44
+ puts " Nombres: #{response.nombres}"
45
+ puts " Apellido Paterno: #{response.apellido_paterno}"
46
+ puts " Apellido Materno: #{response.apellido_materno}"
47
+ puts " Nombre Completo: #{response.nombre_completo}"
48
+ puts " Provider: #{response.provider}"
49
+ puts ""
50
+ puts "Hash format:"
51
+ puts " #{response.to_h.inspect}"
52
+ puts ""
53
+ puts "Raw data:"
54
+ puts " #{response.raw_data.inspect}"
55
+ else
56
+ puts "⚠️ No data found"
57
+ end
58
+ rescue DniPeru::InvalidDniError => e
59
+ puts "❌ Invalid DNI: #{e.message}"
60
+ rescue DniPeru::UnauthorizedError => e
61
+ puts "❌ Authentication Error: #{e.message}"
62
+ puts " Check your API key at https://decolecta.com/profile/"
63
+ rescue DniPeru::NotFoundError => e
64
+ puts "❌ DNI Not Found: #{e.message}"
65
+ rescue DniPeru::ConnectionError => e
66
+ puts "❌ Connection Error: #{e.message}"
67
+ rescue DniPeru::Error => e
68
+ puts "❌ Error: #{e.message}"
69
+ puts " #{e.class}"
70
+ end
71
+
72
+ puts ""
73
+ puts "=" * 80
74
+ puts "Test complete!"
75
+ puts "=" * 80
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dni_peru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruben Paz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-11-28 00:00:00.000000000 Z
11
+ date: 2025-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -55,6 +55,7 @@ files:
55
55
  - README.md
56
56
  - Rakefile
57
57
  - TEST_COVERAGE.md
58
+ - debug_api.rb
58
59
  - dni_peru.gemspec
59
60
  - examples/basic_usage.rb
60
61
  - examples/rails_integration.rb
@@ -69,6 +70,7 @@ files:
69
70
  - lib/dni_peru/providers/decolecta.rb
70
71
  - lib/dni_peru/response.rb
71
72
  - lib/dni_peru/version.rb
73
+ - test_gem.rb
72
74
  homepage: https://github.com/rubenpazch/dni-peru
73
75
  licenses:
74
76
  - MIT