apiverve_vindecoder 1.2.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 +7 -0
- data/LICENSE +21 -0
- data/README.md +284 -0
- data/lib/apiverve_vindecoder/client.rb +184 -0
- data/lib/apiverve_vindecoder.rb +9 -0
- metadata +103 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a1ef0e2457f86148b2722fe0ba82a8b440327e6e98afc06c69823001a3a59885
|
|
4
|
+
data.tar.gz: a2c3e356d6e6e6048c7d4e73ac416b7ef9bb9216a4998507ee0d18baee5a8053
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 53107a732499739611cf92c0545dc50ba859c997fde7b6c490a7906ec806bea827fcfe247c80941d2ac4c6d33f0ee3851899b18828a5da32f36acaf15cf0373a
|
|
7
|
+
data.tar.gz: a807bdfe206fd4e235ad572a77ce636ac64b65d759f8c9ed1a226475c4f130fd57c8f51c638adff35c11494060d83bb585f9b7278d95a066eb94787efa1c52d0
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 APIVerve and EvlarSoft LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# VIN Decoder API - Ruby Gem
|
|
2
|
+
|
|
3
|
+
VIN Decoder turns a 17-character Vehicle Identification Number into the vehicle it identifies. Returns make, model, year, trim, body class and manufacturer, plus engine specifications, plant of manufacture, and the safety equipment fitted to that specific build. Optionally adds every safety recall issued for that vehicle and its NHTSA 5-star crash-test rating.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'apiverve_vindecoder'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
$ bundle install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
$ gem install apiverve_vindecoder
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Getting Started
|
|
26
|
+
|
|
27
|
+
Get your API key at [APIVerve](https://apiverve.com)
|
|
28
|
+
|
|
29
|
+
### Basic Usage
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
require 'apiverve_vindecoder'
|
|
33
|
+
|
|
34
|
+
# Initialize the client
|
|
35
|
+
client = APIVerve::Vindecoder::Client.new(api_key: "YOUR_API_KEY")
|
|
36
|
+
|
|
37
|
+
# Make a request
|
|
38
|
+
response = client.execute({
|
|
39
|
+
vin: "1HGCM82633A004352",
|
|
40
|
+
recalls: true,
|
|
41
|
+
safetyRating: true
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
# Print the response
|
|
45
|
+
puts response
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### Error Handling
|
|
50
|
+
|
|
51
|
+
```ruby
|
|
52
|
+
begin
|
|
53
|
+
response = client.execute({ vin: "1HGCM82633A004352", recalls: true, safetyRating: true })
|
|
54
|
+
puts response["data"]
|
|
55
|
+
rescue APIVerve::Vindecoder::ValidationError => e
|
|
56
|
+
puts "Validation error: #{e.errors.join(', ')}"
|
|
57
|
+
rescue APIVerve::Vindecoder::APIError => e
|
|
58
|
+
puts "API error: #{e.message}"
|
|
59
|
+
puts "Status code: #{e.status_code}"
|
|
60
|
+
end
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Debug Mode
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
# Enable debug logging
|
|
67
|
+
client = APIVerve::Vindecoder::Client.new(
|
|
68
|
+
api_key: "YOUR_API_KEY",
|
|
69
|
+
debug: true
|
|
70
|
+
)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Example Response
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"status": "ok",
|
|
78
|
+
"error": null,
|
|
79
|
+
"data": {
|
|
80
|
+
"vin": "1HGCM82633A004352",
|
|
81
|
+
"valid": true,
|
|
82
|
+
"decoded": true,
|
|
83
|
+
"vehicleDescriptor": "1HGCM826*3A",
|
|
84
|
+
"make": "HONDA",
|
|
85
|
+
"model": "Accord",
|
|
86
|
+
"year": 2003,
|
|
87
|
+
"trim": "EX-V6",
|
|
88
|
+
"trim2": null,
|
|
89
|
+
"series": null,
|
|
90
|
+
"series2": null,
|
|
91
|
+
"manufacturer": "AMERICAN HONDA MOTOR CO., INC.",
|
|
92
|
+
"vehicleType": "PASSENGER CAR",
|
|
93
|
+
"bodyClass": "Coupe",
|
|
94
|
+
"plant": {
|
|
95
|
+
"state": "OHIO",
|
|
96
|
+
"country": "UNITED STATES (USA)",
|
|
97
|
+
"city": "MARYSVILLE"
|
|
98
|
+
},
|
|
99
|
+
"engine": {
|
|
100
|
+
"displacementL": "2.998832712",
|
|
101
|
+
"displacementCc": "2998.832712",
|
|
102
|
+
"engineNumberOfCylinders": "6",
|
|
103
|
+
"engineModel": "J30A4",
|
|
104
|
+
"engineConfiguration": "V-Shaped",
|
|
105
|
+
"engineBrakeHpFrom": "240",
|
|
106
|
+
"displacementCi": "183",
|
|
107
|
+
"fuelTypePrimary": "Gasoline",
|
|
108
|
+
"valveTrainDesign": "Single Overhead Cam (SOHC)"
|
|
109
|
+
},
|
|
110
|
+
"features": {
|
|
111
|
+
"passiveSafetySystem": {
|
|
112
|
+
"otherRestraintSystemInfo": "Seat Belt (Rr center position)",
|
|
113
|
+
"seatBeltType": "Manual",
|
|
114
|
+
"sideAirBagLocations": "1st Row (Driver and Passenger)",
|
|
115
|
+
"curtainAirBagLocations": "1st and 2nd Rows",
|
|
116
|
+
"frontAirBagLocations": "1st Row (Driver and Passenger)"
|
|
117
|
+
},
|
|
118
|
+
"exterior": {
|
|
119
|
+
"grossVehicleWeightRatingFrom": "Class 1C: 4,001 - 5,000 lb (1,814 - 2,268 kg)",
|
|
120
|
+
"grossVehicleWeightRatingTo": "Class 1: 6,000 lb or less (2,722 kg or less)",
|
|
121
|
+
"doors": "2"
|
|
122
|
+
},
|
|
123
|
+
"mechanical": {
|
|
124
|
+
"transmissionStyle": "Automatic",
|
|
125
|
+
"transmissionSpeeds": "5"
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"validation": {
|
|
129
|
+
"errorText": "0 - VIN decoded clean. Check Digit (9th position) is correct",
|
|
130
|
+
"errorCode": "0",
|
|
131
|
+
"errorCodes": [
|
|
132
|
+
"0"
|
|
133
|
+
]
|
|
134
|
+
},
|
|
135
|
+
"recalls": {
|
|
136
|
+
"count": 13,
|
|
137
|
+
"doNotDrive": false,
|
|
138
|
+
"parkOutside": false,
|
|
139
|
+
"bySeverity": {
|
|
140
|
+
"critical": 0,
|
|
141
|
+
"high": 10,
|
|
142
|
+
"medium": 3,
|
|
143
|
+
"low": 0
|
|
144
|
+
},
|
|
145
|
+
"latestReportedOn": "2019-06-27",
|
|
146
|
+
"items": [
|
|
147
|
+
{
|
|
148
|
+
"id": "19V499000",
|
|
149
|
+
"manufacturerRecallId": "Q5A, Y58",
|
|
150
|
+
"manufacturer": "Honda (American Honda Motor Co.)",
|
|
151
|
+
"reportedOn": "2019-06-27",
|
|
152
|
+
"ownersNotifiedOn": "2019-08-12",
|
|
153
|
+
"initiatedBy": "nhtsa",
|
|
154
|
+
"components": [
|
|
155
|
+
{
|
|
156
|
+
"system": "Air Bags",
|
|
157
|
+
"detail": "Frontal › Driver Side › Inflator Module"
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
"summary": "Honda (American Honda Motor Co.) is recalling certain 2003 Acura 3.2CL, 2002-2003 3.2TL, 2003-2006 MDX, 2001-2007 Honda Accord, 2001-2005 Civic, 2003-2005 Civic Hybrid, 2001-2005 Civic GX NGV, 2002-2006 CR-V, 2003-2011 Element, 2002-2004 Odyssey, 2003-2008 Pilot and 2006 Ridgeline vehicles. These vehicles are equipped with driver frontal air bag inflators assembled as a recall remedy part or replacement service part, that may explode due to propellant degradation occurring after long-term exposure to high absolute humidity, temperature and temperature cycling.",
|
|
161
|
+
"consequence": "An inflator explosion may result in sharp metal fragments striking the driver or other occupants resulting in serious injury or death.",
|
|
162
|
+
"hazards": [
|
|
163
|
+
"injury",
|
|
164
|
+
"death"
|
|
165
|
+
],
|
|
166
|
+
"doNotDrive": false,
|
|
167
|
+
"parkOutside": false,
|
|
168
|
+
"remedy": {
|
|
169
|
+
"description": "Honda will notify owners, and dealers will replace the driver frontal air bag inflator, free of charge. The recall began August 12, 2019. Owners may contact Honda customer service at 1-888-234-2138. Honda's numbers for this recall are Q5A and Y58.",
|
|
170
|
+
"status": "available",
|
|
171
|
+
"overTheAir": false,
|
|
172
|
+
"freeOfCharge": true
|
|
173
|
+
},
|
|
174
|
+
"unitsAffected": 3947,
|
|
175
|
+
"manufactured": {
|
|
176
|
+
"from": "2000-07-10",
|
|
177
|
+
"to": "2011-02-22"
|
|
178
|
+
},
|
|
179
|
+
"scope": {
|
|
180
|
+
"makes": 2,
|
|
181
|
+
"models": 12,
|
|
182
|
+
"modelYears": {
|
|
183
|
+
"from": 2001,
|
|
184
|
+
"to": 2011
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
"url": "https://www.nhtsa.gov/recalls?nhtsaId=19V499000",
|
|
188
|
+
"severity": "high",
|
|
189
|
+
"match": "exact",
|
|
190
|
+
"listedAs": "ACCORD"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"id": "19V501000",
|
|
194
|
+
"manufacturerRecallId": "E5D, X5C",
|
|
195
|
+
"manufacturer": "Honda (American Honda Motor Co.)",
|
|
196
|
+
"reportedOn": "2019-06-27",
|
|
197
|
+
"ownersNotifiedOn": "2019-08-12",
|
|
198
|
+
"initiatedBy": "nhtsa",
|
|
199
|
+
"components": [
|
|
200
|
+
{
|
|
201
|
+
"system": "Air Bags",
|
|
202
|
+
"detail": "Frontal › Passenger Side › Inflator Module"
|
|
203
|
+
}
|
|
204
|
+
],
|
|
205
|
+
"summary": "Honda (American Honda Motor Co.) is recalling certain 2003-2006 Acura MDX, 2005-2012 RL, 2003-2007 Honda Accord, 2001-2005 Civic, 2003-2005 Civic Hybrid, 2001-2005 Civic GX NGV, 2002-2006 CR-V, 2003-2011 Element, 2007-2008 Fit, 2002-2004 Odyssey, 2003-2008 Pilot, and 2006-2014 Ridgeline vehicles. The vehicles are equipped with passenger frontal air bag inflators assembled as a recall remedy part or replacement service part, that may explode due to propellant degradation occurring after long-term exposure to high absolute humidity, temperature and temperature cycling.",
|
|
206
|
+
"consequence": "An inflator explosion may result in sharp metal fragments striking the driver or other occupants resulting in serious injury or death.",
|
|
207
|
+
"hazards": [
|
|
208
|
+
"injury",
|
|
209
|
+
"death"
|
|
210
|
+
],
|
|
211
|
+
"doNotDrive": false,
|
|
212
|
+
"parkOutside": false,
|
|
213
|
+
"remedy": {
|
|
214
|
+
"description": "Honda will notify owners, and dealers will replace the passenger frontal airbag inflator, free of charge. The recall began August 12, 2019. Owners may contact Honda customer service at 1-888-234-2138. Honda's numbers for this recall are E5D and X5C.",
|
|
215
|
+
"status": "available",
|
|
216
|
+
"overTheAir": false,
|
|
217
|
+
"freeOfCharge": true
|
|
218
|
+
},
|
|
219
|
+
"unitsAffected": 1657752,
|
|
220
|
+
"manufactured": {
|
|
221
|
+
"from": "2000-04-25",
|
|
222
|
+
"to": "2014-06-02"
|
|
223
|
+
},
|
|
224
|
+
"scope": {
|
|
225
|
+
"makes": 2,
|
|
226
|
+
"models": 12,
|
|
227
|
+
"modelYears": {
|
|
228
|
+
"from": 2001,
|
|
229
|
+
"to": 2014
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
"url": "https://www.nhtsa.gov/recalls?nhtsaId=19V501000",
|
|
233
|
+
"severity": "high",
|
|
234
|
+
"match": "exact",
|
|
235
|
+
"listedAs": "ACCORD"
|
|
236
|
+
}
|
|
237
|
+
]
|
|
238
|
+
},
|
|
239
|
+
"safetyRating": {
|
|
240
|
+
"testedVehicle": "2003 Honda Accord 2-DR. w/SAB",
|
|
241
|
+
"match": "exact",
|
|
242
|
+
"variantsTested": 4,
|
|
243
|
+
"overall": null,
|
|
244
|
+
"frontal": {
|
|
245
|
+
"overall": null,
|
|
246
|
+
"driver": 5,
|
|
247
|
+
"passenger": 5
|
|
248
|
+
},
|
|
249
|
+
"side": {
|
|
250
|
+
"overall": null,
|
|
251
|
+
"driver": null,
|
|
252
|
+
"passenger": null,
|
|
253
|
+
"barrier": null,
|
|
254
|
+
"pole": null,
|
|
255
|
+
"frontSeat": null,
|
|
256
|
+
"rearSeat": null
|
|
257
|
+
},
|
|
258
|
+
"rollover": {
|
|
259
|
+
"rating": 4,
|
|
260
|
+
"riskPercent": null,
|
|
261
|
+
"tipped": null
|
|
262
|
+
},
|
|
263
|
+
"driverAssist": {
|
|
264
|
+
"electronicStabilityControl": "notAvailable",
|
|
265
|
+
"forwardCollisionWarning": "notAvailable",
|
|
266
|
+
"laneDepartureWarning": "notAvailable"
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Documentation
|
|
274
|
+
|
|
275
|
+
For more information, visit the [API Documentation](https://docs.apiverve.com/ref/vindecoder?utm_source=rubygems&utm_medium=referral&utm_content=readme).
|
|
276
|
+
|
|
277
|
+
## Support
|
|
278
|
+
|
|
279
|
+
- Website: [https://apiverve.com/marketplace/vindecoder?utm_source=ruby&utm_medium=referral&utm_content=readme](https://apiverve.com/marketplace/vindecoder?utm_source=ruby&utm_medium=referral&utm_content=readme)
|
|
280
|
+
- Email: hello@apiverve.com
|
|
281
|
+
|
|
282
|
+
## License
|
|
283
|
+
|
|
284
|
+
This gem is available under the [MIT License](LICENSE).
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "faraday"
|
|
4
|
+
require "faraday/multipart"
|
|
5
|
+
require "json"
|
|
6
|
+
|
|
7
|
+
module APIVerve
|
|
8
|
+
module Vindecoder
|
|
9
|
+
# Client for the VIN Decoder API
|
|
10
|
+
#
|
|
11
|
+
# @example Basic usage
|
|
12
|
+
# client = APIVerve::Vindecoder::Client.new(api_key: "your_api_key")
|
|
13
|
+
# response = client.execute({ vin: "1HGCM82633A004352", recalls: true, safetyRating: true })
|
|
14
|
+
# puts response
|
|
15
|
+
#
|
|
16
|
+
# @see https://apiverve.com/marketplace/vindecoder?utm_source=ruby&utm_medium=referral&utm_content=readme
|
|
17
|
+
class Client
|
|
18
|
+
BASE_URL = "https://api.apiverve.com/v1/vindecoder"
|
|
19
|
+
DEFAULT_TIMEOUT = 30
|
|
20
|
+
|
|
21
|
+
# Validation rules for parameters
|
|
22
|
+
VALIDATION_RULES = { 'vin' => { type: 'string', required: true, min_length: 1, max_length: 17 }, 'recalls' => { type: 'boolean', required: false }, 'safetyRating' => { type: 'boolean', required: false } }
|
|
23
|
+
|
|
24
|
+
# Format validation patterns
|
|
25
|
+
FORMAT_PATTERNS = {
|
|
26
|
+
'email' => /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
27
|
+
'url' => /^https?:\/\/.+/,
|
|
28
|
+
'ip' => /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/,
|
|
29
|
+
'date' => /^\d{4}-\d{2}-\d{2}$/,
|
|
30
|
+
'hexColor' => /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
|
|
31
|
+
}.freeze
|
|
32
|
+
|
|
33
|
+
# Initialize the client
|
|
34
|
+
#
|
|
35
|
+
# @param api_key [String] Your APIVerve API key
|
|
36
|
+
# @param timeout [Integer] Request timeout in seconds (default: 30)
|
|
37
|
+
# @param debug [Boolean] Enable debug logging (default: false)
|
|
38
|
+
# @raise [ArgumentError] If API key is invalid
|
|
39
|
+
def initialize(api_key:, timeout: DEFAULT_TIMEOUT, debug: false)
|
|
40
|
+
validate_api_key!(api_key)
|
|
41
|
+
|
|
42
|
+
@api_key = api_key
|
|
43
|
+
@timeout = timeout
|
|
44
|
+
@debug = debug
|
|
45
|
+
|
|
46
|
+
@connection = Faraday.new(url: BASE_URL) do |conn|
|
|
47
|
+
conn.request :multipart
|
|
48
|
+
conn.request :url_encoded
|
|
49
|
+
conn.adapter Faraday.default_adapter
|
|
50
|
+
conn.options.timeout = @timeout
|
|
51
|
+
conn.headers["x-api-key"] = @api_key
|
|
52
|
+
conn.headers["auth-mode"] = "rubygems-package"
|
|
53
|
+
conn.headers["Content-Type"] = "application/json"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Execute the API request
|
|
58
|
+
#
|
|
59
|
+
# @param params [Hash] Query parameters or request body
|
|
60
|
+
# @return [Hash] API response
|
|
61
|
+
# @raise [APIError] If the request fails
|
|
62
|
+
# @raise [ValidationError] If parameter validation fails
|
|
63
|
+
def execute(params = {})
|
|
64
|
+
validate_params!(params)
|
|
65
|
+
|
|
66
|
+
log("Making GET request to #{BASE_URL}")
|
|
67
|
+
log("Parameters: #{params.inspect}") if params.any?
|
|
68
|
+
|
|
69
|
+
response = @connection.get do |req|
|
|
70
|
+
params.each { |k, v| req.params[k.to_s] = v }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
handle_response(response)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def validate_api_key!(api_key)
|
|
79
|
+
raise ArgumentError, "API key is required. Get your API key at: https://apiverve.com" if api_key.nil? || api_key.strip.empty?
|
|
80
|
+
|
|
81
|
+
unless api_key.match?(/^[a-zA-Z0-9_-]+$/)
|
|
82
|
+
raise ArgumentError, "Invalid API key format. API key should only contain letters, numbers, hyphens, and underscores."
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def validate_params!(params)
|
|
87
|
+
return if VALIDATION_RULES.empty?
|
|
88
|
+
|
|
89
|
+
errors = []
|
|
90
|
+
|
|
91
|
+
VALIDATION_RULES.each do |param_name, rules|
|
|
92
|
+
value = params[param_name.to_sym] || params[param_name]
|
|
93
|
+
|
|
94
|
+
# Check required
|
|
95
|
+
if rules[:required] && (value.nil? || value.to_s.empty?)
|
|
96
|
+
errors << "Required parameter [#{param_name}] is missing."
|
|
97
|
+
next
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
next if value.nil?
|
|
101
|
+
|
|
102
|
+
case rules[:type]
|
|
103
|
+
when "integer", "number"
|
|
104
|
+
begin
|
|
105
|
+
num_value = rules[:type] == "number" ? Float(value) : Integer(value)
|
|
106
|
+
errors << "Parameter [#{param_name}] must be at least #{rules[:min]}." if rules[:min] && num_value < rules[:min]
|
|
107
|
+
errors << "Parameter [#{param_name}] must be at most #{rules[:max]}." if rules[:max] && num_value > rules[:max]
|
|
108
|
+
rescue ArgumentError, TypeError
|
|
109
|
+
errors << "Parameter [#{param_name}] must be a valid #{rules[:type]}."
|
|
110
|
+
end
|
|
111
|
+
when "string"
|
|
112
|
+
unless value.is_a?(String)
|
|
113
|
+
errors << "Parameter [#{param_name}] must be a string."
|
|
114
|
+
next
|
|
115
|
+
end
|
|
116
|
+
errors << "Parameter [#{param_name}] must be at least #{rules[:min_length]} characters." if rules[:min_length] && value.length < rules[:min_length]
|
|
117
|
+
errors << "Parameter [#{param_name}] must be at most #{rules[:max_length]} characters." if rules[:max_length] && value.length > rules[:max_length]
|
|
118
|
+
|
|
119
|
+
if rules[:format] && FORMAT_PATTERNS[rules[:format]]
|
|
120
|
+
unless value.match?(FORMAT_PATTERNS[rules[:format]])
|
|
121
|
+
errors << "Parameter [#{param_name}] must be a valid #{rules[:format]}."
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
when "boolean"
|
|
125
|
+
unless [true, false, "true", "false"].include?(value)
|
|
126
|
+
errors << "Parameter [#{param_name}] must be a boolean."
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Enum validation
|
|
131
|
+
if rules[:enum] && !rules[:enum].include?(value)
|
|
132
|
+
errors << "Parameter [#{param_name}] must be one of: #{rules[:enum].join(', ')}."
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
raise ValidationError, errors unless errors.empty?
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def handle_response(response)
|
|
140
|
+
log("Response status: #{response.status}")
|
|
141
|
+
|
|
142
|
+
data = JSON.parse(response.body)
|
|
143
|
+
|
|
144
|
+
if data["status"] == "error"
|
|
145
|
+
raise APIError.new(data["error"] || "Unknown API error", response.status, data)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
unless response.success?
|
|
149
|
+
raise APIError.new(data["error"] || "HTTP #{response.status} error", response.status, data)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
log("Request successful")
|
|
153
|
+
data
|
|
154
|
+
rescue JSON::ParserError => e
|
|
155
|
+
raise APIError.new("Invalid JSON response: #{e.message}", response.status)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def log(message)
|
|
159
|
+
puts "[APIVerve::Vindecoder] #{message}" if @debug
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# Custom error class for API errors
|
|
164
|
+
class APIError < StandardError
|
|
165
|
+
attr_reader :status_code, :response
|
|
166
|
+
|
|
167
|
+
def initialize(message, status_code = nil, response = nil)
|
|
168
|
+
@status_code = status_code
|
|
169
|
+
@response = response
|
|
170
|
+
super(message)
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# Custom error class for validation errors
|
|
175
|
+
class ValidationError < StandardError
|
|
176
|
+
attr_reader :errors
|
|
177
|
+
|
|
178
|
+
def initialize(errors)
|
|
179
|
+
@errors = errors
|
|
180
|
+
super("Validation failed: #{errors.join(' ')}")
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: apiverve_vindecoder
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.2.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- APIVerve
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-10-21 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: faraday
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.0'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '3.0'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '1.0'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '3.0'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: faraday-multipart
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '1.0'
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '1.0'
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: json
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '2.0'
|
|
54
|
+
type: :runtime
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '2.0'
|
|
61
|
+
description: VIN Decoder turns a 17-character Vehicle Identification Number into the
|
|
62
|
+
vehicle it identifies. Returns make, model, year, trim, body class and manufacturer,
|
|
63
|
+
plus engine specifications, plant of manufacture, and the safety equipment fitted
|
|
64
|
+
to that specific build. Optionally adds every safety recall issued for that vehicle
|
|
65
|
+
and its NHTSA 5-star crash-test rating.
|
|
66
|
+
email:
|
|
67
|
+
- hello@apiverve.com
|
|
68
|
+
executables: []
|
|
69
|
+
extensions: []
|
|
70
|
+
extra_rdoc_files: []
|
|
71
|
+
files:
|
|
72
|
+
- LICENSE
|
|
73
|
+
- README.md
|
|
74
|
+
- lib/apiverve_vindecoder.rb
|
|
75
|
+
- lib/apiverve_vindecoder/client.rb
|
|
76
|
+
homepage: https://apiverve.com/marketplace/vindecoder?utm_source=ruby&utm_medium=referral&utm_content=homepage
|
|
77
|
+
licenses:
|
|
78
|
+
- MIT
|
|
79
|
+
metadata:
|
|
80
|
+
homepage_uri: https://apiverve.com/marketplace/vindecoder?utm_source=ruby&utm_medium=referral&utm_content=homepage
|
|
81
|
+
source_code_uri: https://github.com/apiverve/vindecoder-API/tree/main/ruby
|
|
82
|
+
changelog_uri: https://apiverve.com/changelog
|
|
83
|
+
documentation_uri: https://docs.apiverve.com/ref/vindecoder
|
|
84
|
+
post_install_message:
|
|
85
|
+
rdoc_options: []
|
|
86
|
+
require_paths:
|
|
87
|
+
- lib
|
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
|
+
requirements:
|
|
90
|
+
- - ">="
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: 2.7.0
|
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
|
+
requirements:
|
|
95
|
+
- - ">="
|
|
96
|
+
- !ruby/object:Gem::Version
|
|
97
|
+
version: '0'
|
|
98
|
+
requirements: []
|
|
99
|
+
rubygems_version: 3.0.3.1
|
|
100
|
+
signing_key:
|
|
101
|
+
specification_version: 4
|
|
102
|
+
summary: VIN Decoder API - Ruby Client
|
|
103
|
+
test_files: []
|