vin_decoder 0.1.0 → 0.2.0
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 +47 -5
- data/lib/vin_decoder/client.rb +3 -3
- data/lib/vin_decoder/vehicle.rb +39 -4
- data/lib/vin_decoder/version.rb +1 -1
- data/lib/vin_decoder.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 073e7f76a91c5ffa0a0f51ce7e1e79eb841d64226ecec897ee3f0961fdadcd49
|
|
4
|
+
data.tar.gz: 569ca3f1aceaa812b5774a9918344fd5058d96805eb93c13e552409f97d25c43
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 75ab1904faf87ca88d4168f932371cad5330224cd57eb3fbea73644b08928636e83f1483bd006067e8786b2e9983907e4fb739d378fb1579b87c76067124a875
|
|
7
|
+
data.tar.gz: 294b449d927b031fcc00cc0bb263d4e107195464b7724741049de395e864b9c1b5c94ebfc8a09eb8bb6261cebe1483c99387b86f0c43a7f00c96bf2892b271a6
|
data/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
vin_decoder is a lightweight Ruby client for the NHTSA vPIC API. It decodes 17-character VINs and exposes a tidy domain object so you can access make, model, year, powertrain data, and more without sifting through raw JSON.
|
|
4
4
|
|
|
5
|
+
This is used on [Wenmar Pro](https://wenmarpro.com), a shop management software.
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
Add the gem to your project (when published):
|
|
@@ -31,14 +33,32 @@ end
|
|
|
31
33
|
|
|
32
34
|
## Usage
|
|
33
35
|
|
|
36
|
+
### Module-level shortcut
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
vehicle = VinDecoder.decode('1HGCM82633A004352')
|
|
40
|
+
|
|
41
|
+
if vehicle.valid?
|
|
42
|
+
puts [vehicle.year, vehicle.make, vehicle.model].compact.join(' ')
|
|
43
|
+
# => "2003 HONDA Accord"
|
|
44
|
+
else
|
|
45
|
+
warn 'VIN could not be decoded'
|
|
46
|
+
end
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Client instance
|
|
50
|
+
|
|
34
51
|
```ruby
|
|
35
52
|
client = VinDecoder::Client.new
|
|
36
53
|
vehicle = client.decode('1HGCM82633A004352')
|
|
37
54
|
|
|
38
55
|
if vehicle.valid?
|
|
39
|
-
puts [vehicle.year, vehicle.make, vehicle.model].compact.join(' ')
|
|
40
56
|
puts "Engine: #{vehicle.engine} (#{vehicle.engine_cylinders} cylinders)"
|
|
41
57
|
puts "Fuel: #{vehicle.fuel_type}"
|
|
58
|
+
puts "Body style: #{vehicle.body_style}"
|
|
59
|
+
puts "Transmission: #{vehicle.transmission}"
|
|
60
|
+
puts "Drivetrain: #{vehicle.drivetrain}"
|
|
61
|
+
puts "Submodel: #{vehicle.submodel}"
|
|
42
62
|
puts "Fuel type (raw accessor): #{vehicle['FuelTypePrimary']}"
|
|
43
63
|
puts "Lot size (dynamic): #{vehicle.lot_size}"
|
|
44
64
|
else
|
|
@@ -51,11 +71,33 @@ The client raises:
|
|
|
51
71
|
- `VinDecoder::NotFoundError` when the API responds with HTTP 404.
|
|
52
72
|
- `VinDecoder::ApiError` for any other non-200 HTTP status code.
|
|
53
73
|
|
|
74
|
+
### Vehicle object
|
|
75
|
+
|
|
54
76
|
Each `VinDecoder::Vehicle` exposes the entire response payload:
|
|
55
77
|
|
|
56
|
-
- Common helper methods
|
|
57
|
-
- Hash-style access with string or symbol keys (`vehicle['ModelYear']` / `vehicle[:ModelYear]`).
|
|
58
|
-
- Dynamic snake_case readers derived from the raw keys (`vehicle.vehicle_descriptor`, `vehicle.fuel_type_secondary`). Missing fields raise `NoMethodError` so mistakes are caught quickly.
|
|
78
|
+
- **Common helper methods**: `make`, `model`, `year`, `trim`, `submodel`, `body_style`, `engine`, `engine_cylinders`, `transmission`, `drivetrain`, `fuel_type`, `vin`.
|
|
79
|
+
- **Hash-style access** with string or symbol keys (`vehicle['ModelYear']` / `vehicle[:ModelYear]`).
|
|
80
|
+
- **Dynamic snake_case readers** derived from the raw keys (`vehicle.vehicle_descriptor`, `vehicle.fuel_type_secondary`). Missing fields raise `NoMethodError` so mistakes are caught quickly.
|
|
81
|
+
- **`to_h`** — Returns a plain Ruby hash with all structured fields, suitable for serializing or passing to form builders:
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
vehicle.to_h
|
|
85
|
+
# => {
|
|
86
|
+
# vin: "1HGCM82633A004352",
|
|
87
|
+
# year: "2003",
|
|
88
|
+
# make: "HONDA",
|
|
89
|
+
# model: "Accord",
|
|
90
|
+
# submodel: "EX-V6",
|
|
91
|
+
# body_style: "...",
|
|
92
|
+
# engine: "HONDA V6 240",
|
|
93
|
+
# transmission: "...",
|
|
94
|
+
# drivetrain: "...",
|
|
95
|
+
# fuel_type: "Gasoline",
|
|
96
|
+
# raw_data: { ... },
|
|
97
|
+
# trim: "EX-V6",
|
|
98
|
+
# engine_cylinders: "6"
|
|
99
|
+
# }
|
|
100
|
+
```
|
|
59
101
|
|
|
60
102
|
## Rails Integration
|
|
61
103
|
|
|
@@ -137,4 +179,4 @@ To refresh the live cassette, delete `spec/fixtures/vcr_cassettes/decode_success
|
|
|
137
179
|
|
|
138
180
|
5. Tag the release in git and push tags to GitHub for reference.
|
|
139
181
|
|
|
140
|
-
That
|
|
182
|
+
That's it—you now have a fully tested VIN decoder client ready for reuse or publication.
|
data/lib/vin_decoder/client.rb
CHANGED
|
@@ -13,17 +13,17 @@ module VinDecoder
|
|
|
13
13
|
def decode(vin)
|
|
14
14
|
response = @connection.get("DecodeVinValuesExtended/#{vin}", format: 'json')
|
|
15
15
|
|
|
16
|
-
handle_response(response)
|
|
16
|
+
handle_response(response, vin)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
private
|
|
20
20
|
|
|
21
|
-
def handle_response(response)
|
|
21
|
+
def handle_response(response, vin)
|
|
22
22
|
case response.status
|
|
23
23
|
when 200
|
|
24
24
|
payload = JSON.parse(response.body)
|
|
25
25
|
result_hash = payload['Results']&.first || {}
|
|
26
|
-
Vehicle.new(result_hash)
|
|
26
|
+
Vehicle.new(result_hash, vin: vin)
|
|
27
27
|
when 404
|
|
28
28
|
raise NotFoundError, 'VIN not found'
|
|
29
29
|
else
|
data/lib/vin_decoder/vehicle.rb
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module VinDecoder
|
|
4
4
|
class Vehicle
|
|
5
|
-
attr_reader :raw_data
|
|
5
|
+
attr_reader :raw_data, :vin
|
|
6
6
|
|
|
7
|
-
def initialize(data)
|
|
7
|
+
def initialize(data, vin: nil)
|
|
8
8
|
@raw_data = data || {}
|
|
9
|
+
@vin = vin
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
def make
|
|
@@ -20,12 +21,32 @@ module VinDecoder
|
|
|
20
21
|
raw_data['ModelYear']
|
|
21
22
|
end
|
|
22
23
|
|
|
24
|
+
def submodel
|
|
25
|
+
raw_data['Series']
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def body_style
|
|
29
|
+
raw_data['BodyClass']
|
|
30
|
+
end
|
|
31
|
+
|
|
23
32
|
def engine_cylinders
|
|
24
33
|
raw_data['EngineCylinders']
|
|
25
34
|
end
|
|
26
35
|
|
|
27
36
|
def engine
|
|
28
|
-
|
|
37
|
+
[
|
|
38
|
+
raw_data['EngineManufacturer'],
|
|
39
|
+
raw_data['EngineModel'],
|
|
40
|
+
raw_data['EngineHP']
|
|
41
|
+
].compact.join(' ').presence
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def transmission
|
|
45
|
+
raw_data['TransmissionDescriptor']
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def drivetrain
|
|
49
|
+
raw_data['DriveType']
|
|
29
50
|
end
|
|
30
51
|
|
|
31
52
|
def fuel_type
|
|
@@ -45,7 +66,21 @@ module VinDecoder
|
|
|
45
66
|
end
|
|
46
67
|
|
|
47
68
|
def to_h
|
|
48
|
-
|
|
69
|
+
{
|
|
70
|
+
vin: vin,
|
|
71
|
+
year: year,
|
|
72
|
+
make: make,
|
|
73
|
+
model: model,
|
|
74
|
+
submodel: submodel,
|
|
75
|
+
body_style: body_style,
|
|
76
|
+
engine: engine,
|
|
77
|
+
transmission: transmission,
|
|
78
|
+
drivetrain: drivetrain,
|
|
79
|
+
fuel_type: fuel_type,
|
|
80
|
+
raw_data: raw_data,
|
|
81
|
+
trim: trim,
|
|
82
|
+
engine_cylinders: engine_cylinders
|
|
83
|
+
}
|
|
49
84
|
end
|
|
50
85
|
|
|
51
86
|
def method_missing(method_name, *args, &block)
|
data/lib/vin_decoder/version.rb
CHANGED
data/lib/vin_decoder.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vin_decoder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ben D'Angelo
|
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
141
141
|
- !ruby/object:Gem::Version
|
|
142
142
|
version: '0'
|
|
143
143
|
requirements: []
|
|
144
|
-
rubygems_version: 4.0.
|
|
144
|
+
rubygems_version: 4.0.10
|
|
145
145
|
specification_version: 4
|
|
146
146
|
summary: A Ruby client for the NHTSA vPIC VIN decoding API.
|
|
147
147
|
test_files: []
|