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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f129f1c9b8e8d9e6531231a078ea74d9b64b4b98c5e71ddabfebb263781c5bf9
4
- data.tar.gz: 85a10ee709afb2807d4b40ec82c9c1e0909147b7d6c2e967fdb65917afb0aa16
3
+ metadata.gz: 073e7f76a91c5ffa0a0f51ce7e1e79eb841d64226ecec897ee3f0961fdadcd49
4
+ data.tar.gz: 569ca3f1aceaa812b5774a9918344fd5058d96805eb93c13e552409f97d25c43
5
5
  SHA512:
6
- metadata.gz: dffa00fec79bb94acb69f5d54f5febfc5053e9067baf299c8d4c0d3522990dd5eaa13c4c015d76b52bf6644b844fc692d9495117c211dc797ff039dc37397735
7
- data.tar.gz: ad03e97f4845f4b84a3e79ec0067e3711a0ea33011ab63150e29e1317f4729b4acb56fcdcfb9b5d2c46759161fec6ce96fff87fb0dbe5c0156a897c3d4026060
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 (`make`, `model`, `trim`, `engine`, etc.).
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
- Thats it—you now have a fully tested VIN decoder client ready for reuse or publication.
182
+ That's it—you now have a fully tested VIN decoder client ready for reuse or publication.
@@ -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
@@ -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
- raw_data['EngineConfiguration']
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
- raw_data.dup
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VinDecoder
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/vin_decoder.rb CHANGED
@@ -19,5 +19,9 @@ module VinDecoder
19
19
  self.configuration ||= Configuration.new
20
20
  yield(configuration)
21
21
  end
22
+
23
+ def decode(vin)
24
+ Client.new.decode(vin)
25
+ end
22
26
  end
23
27
  end
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.1.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.8
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: []