vin_decoder 0.1.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 +7 -0
- data/LICENSE +201 -0
- data/README.md +140 -0
- data/lib/vin_decoder/client.rb +34 -0
- data/lib/vin_decoder/configuration.rb +12 -0
- data/lib/vin_decoder/vehicle.rb +86 -0
- data/lib/vin_decoder/version.rb +5 -0
- data/lib/vin_decoder.rb +23 -0
- metadata +147 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f129f1c9b8e8d9e6531231a078ea74d9b64b4b98c5e71ddabfebb263781c5bf9
|
|
4
|
+
data.tar.gz: 85a10ee709afb2807d4b40ec82c9c1e0909147b7d6c2e967fdb65917afb0aa16
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: dffa00fec79bb94acb69f5d54f5febfc5053e9067baf299c8d4c0d3522990dd5eaa13c4c015d76b52bf6644b844fc692d9495117c211dc797ff039dc37397735
|
|
7
|
+
data.tar.gz: ad03e97f4845f4b84a3e79ec0067e3711a0ea33011ab63150e29e1317f4729b4acb56fcdcfb9b5d2c46759161fec6ce96fff87fb0dbe5c0156a897c3d4026060
|
data/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# VinDecoder
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add the gem to your project (when published):
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'vin_decoder'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or install directly from source:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/Wenmar-Pro/vin_decoder.git
|
|
17
|
+
cd vin_decoder
|
|
18
|
+
bundle install
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
|
|
23
|
+
Use the top-level `VinDecoder.configure` block to customize the base URL (handy for mocking) or request timeout. Defaults target the official NHTSA API with a 10-second timeout.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
VinDecoder.configure do |config|
|
|
27
|
+
config.base_url = 'https://vpic.nhtsa.dot.gov/api/vehicles'
|
|
28
|
+
config.timeout = 5
|
|
29
|
+
end
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
client = VinDecoder::Client.new
|
|
36
|
+
vehicle = client.decode('1HGCM82633A004352')
|
|
37
|
+
|
|
38
|
+
if vehicle.valid?
|
|
39
|
+
puts [vehicle.year, vehicle.make, vehicle.model].compact.join(' ')
|
|
40
|
+
puts "Engine: #{vehicle.engine} (#{vehicle.engine_cylinders} cylinders)"
|
|
41
|
+
puts "Fuel: #{vehicle.fuel_type}"
|
|
42
|
+
puts "Fuel type (raw accessor): #{vehicle['FuelTypePrimary']}"
|
|
43
|
+
puts "Lot size (dynamic): #{vehicle.lot_size}"
|
|
44
|
+
else
|
|
45
|
+
warn 'VIN could not be decoded'
|
|
46
|
+
end
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The client raises:
|
|
50
|
+
|
|
51
|
+
- `VinDecoder::NotFoundError` when the API responds with HTTP 404.
|
|
52
|
+
- `VinDecoder::ApiError` for any other non-200 HTTP status code.
|
|
53
|
+
|
|
54
|
+
Each `VinDecoder::Vehicle` exposes the entire response payload:
|
|
55
|
+
|
|
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.
|
|
59
|
+
|
|
60
|
+
## Rails Integration
|
|
61
|
+
|
|
62
|
+
Add the gem to your Rails app (from RubyGems or a local path while developing).
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
# Gemfile
|
|
66
|
+
gem 'vin_decoder', path: '../path/to/vin_decoder'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Create an initializer to configure timeouts and base URL:
|
|
70
|
+
|
|
71
|
+
```ruby
|
|
72
|
+
# config/initializers/vin_decoder.rb
|
|
73
|
+
VinDecoder.configure do |config|
|
|
74
|
+
config.timeout = ENV.fetch('VIN_DECODER_TIMEOUT', 5).to_i
|
|
75
|
+
config.base_url = ENV.fetch('VIN_DECODER_BASE_URL', 'https://vpic.nhtsa.dot.gov/api/vehicles')
|
|
76
|
+
end
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Wrap the client in a PORO/service for controllers or jobs:
|
|
80
|
+
|
|
81
|
+
```ruby
|
|
82
|
+
# app/services/vin_lookup.rb
|
|
83
|
+
class VinLookup
|
|
84
|
+
def initialize(client: VinDecoder::Client.new)
|
|
85
|
+
@client = client
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def call(vin)
|
|
89
|
+
vehicle = @client.decode(vin)
|
|
90
|
+
raise VinDecoder::NotFoundError unless vehicle.valid?
|
|
91
|
+
|
|
92
|
+
vehicle
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Example controller usage:
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
class VehiclesController < ApplicationController
|
|
101
|
+
def show
|
|
102
|
+
@vehicle = VinLookup.new.call(params[:vin])
|
|
103
|
+
rescue VinDecoder::NotFoundError
|
|
104
|
+
redirect_to root_path, alert: 'VIN not found'
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
You can also enqueue lookups via ActiveJob/Sidekiq and cache results to avoid repeated external calls.
|
|
110
|
+
|
|
111
|
+
## Testing & VCR Cassettes
|
|
112
|
+
|
|
113
|
+
Tests run via RSpec and rely on VCR/WebMock for deterministic HTTP interactions.
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
bundle exec rspec
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
To refresh the live cassette, delete `spec/fixtures/vcr_cassettes/decode_success.yml` and rerun the specs. VCR will connect to the real API once, capture the response, and reuse it on subsequent runs.
|
|
120
|
+
|
|
121
|
+
## Publishing Checklist
|
|
122
|
+
|
|
123
|
+
1. Ensure version in `lib/vin_decoder/version.rb` reflects the release.
|
|
124
|
+
2. Update `CHANGELOG` or release notes as needed (add one if not yet created).
|
|
125
|
+
3. Build the gem and inspect the package contents:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
gem build vin_decoder.gemspec
|
|
129
|
+
gem install vin_decoder-<version>.gem
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
4. Push the artifact to RubyGems:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
gem push vin_decoder-<version>.gem
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
5. Tag the release in git and push tags to GitHub for reference.
|
|
139
|
+
|
|
140
|
+
That’s it—you now have a fully tested VIN decoder client ready for reuse or publication.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module VinDecoder
|
|
4
|
+
class Client
|
|
5
|
+
def initialize
|
|
6
|
+
config = VinDecoder.configuration || Configuration.new
|
|
7
|
+
@connection = Faraday.new(url: config.base_url) do |faraday|
|
|
8
|
+
faraday.options.timeout = config.timeout
|
|
9
|
+
faraday.adapter Faraday.default_adapter
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def decode(vin)
|
|
14
|
+
response = @connection.get("DecodeVinValuesExtended/#{vin}", format: 'json')
|
|
15
|
+
|
|
16
|
+
handle_response(response)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def handle_response(response)
|
|
22
|
+
case response.status
|
|
23
|
+
when 200
|
|
24
|
+
payload = JSON.parse(response.body)
|
|
25
|
+
result_hash = payload['Results']&.first || {}
|
|
26
|
+
Vehicle.new(result_hash)
|
|
27
|
+
when 404
|
|
28
|
+
raise NotFoundError, 'VIN not found'
|
|
29
|
+
else
|
|
30
|
+
raise ApiError, "API returned status #{response.status}: #{response.body}"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module VinDecoder
|
|
4
|
+
class Vehicle
|
|
5
|
+
attr_reader :raw_data
|
|
6
|
+
|
|
7
|
+
def initialize(data)
|
|
8
|
+
@raw_data = data || {}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def make
|
|
12
|
+
raw_data['Make']
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def model
|
|
16
|
+
raw_data['Model']
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def year
|
|
20
|
+
raw_data['ModelYear']
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def engine_cylinders
|
|
24
|
+
raw_data['EngineCylinders']
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def engine
|
|
28
|
+
raw_data['EngineConfiguration']
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def fuel_type
|
|
32
|
+
raw_data['FuelTypePrimary']
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def trim
|
|
36
|
+
raw_data['Trim']
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def [](key)
|
|
40
|
+
raw_data[key.to_s]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def valid?
|
|
44
|
+
raw_data['ErrorCode'] == '0'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_h
|
|
48
|
+
raw_data.dup
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def method_missing(method_name, *args, &block)
|
|
52
|
+
return super unless args.empty?
|
|
53
|
+
|
|
54
|
+
key = lookup_key(method_name)
|
|
55
|
+
return super unless key
|
|
56
|
+
|
|
57
|
+
raw_data[key]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
61
|
+
lookup_key(method_name) || super
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def lookup_key(method_name)
|
|
67
|
+
return if method_name.nil?
|
|
68
|
+
|
|
69
|
+
normalized_key_cache[method_name] ||= begin
|
|
70
|
+
normalized = method_name.to_s
|
|
71
|
+
raw_data.keys.find { |key| normalize_key(key) == normalized }
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def normalized_key_cache
|
|
76
|
+
@normalized_key_cache ||= {}
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def normalize_key(key)
|
|
80
|
+
key.to_s
|
|
81
|
+
.gsub(/[^a-zA-Z0-9]+/, '_')
|
|
82
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
|
83
|
+
.downcase
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
data/lib/vin_decoder.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "zeitwerk"
|
|
4
|
+
require "faraday"
|
|
5
|
+
require "json"
|
|
6
|
+
|
|
7
|
+
loader = Zeitwerk::Loader.for_gem
|
|
8
|
+
loader.setup
|
|
9
|
+
|
|
10
|
+
module VinDecoder
|
|
11
|
+
class Error < StandardError; end
|
|
12
|
+
class ApiError < Error; end
|
|
13
|
+
class NotFoundError < Error; end
|
|
14
|
+
|
|
15
|
+
class << self
|
|
16
|
+
attr_accessor :configuration
|
|
17
|
+
|
|
18
|
+
def configure
|
|
19
|
+
self.configuration ||= Configuration.new
|
|
20
|
+
yield(configuration)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: vin_decoder
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ben D'Angelo
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: faraday
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: json
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: zeitwerk
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '2.6'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '2.6'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: rspec
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '3.0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '3.0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: vcr
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '6.0'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '6.0'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: webmock
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '3.0'
|
|
89
|
+
type: :development
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - "~>"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '3.0'
|
|
96
|
+
- !ruby/object:Gem::Dependency
|
|
97
|
+
name: irb
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
type: :development
|
|
104
|
+
prerelease: false
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
description: Decodes 17-character VINs to provide vehicle specifications like make,
|
|
111
|
+
model, and engine type.
|
|
112
|
+
email:
|
|
113
|
+
- ben@bendangelo.me
|
|
114
|
+
executables: []
|
|
115
|
+
extensions: []
|
|
116
|
+
extra_rdoc_files: []
|
|
117
|
+
files:
|
|
118
|
+
- LICENSE
|
|
119
|
+
- README.md
|
|
120
|
+
- lib/vin_decoder.rb
|
|
121
|
+
- lib/vin_decoder/client.rb
|
|
122
|
+
- lib/vin_decoder/configuration.rb
|
|
123
|
+
- lib/vin_decoder/vehicle.rb
|
|
124
|
+
- lib/vin_decoder/version.rb
|
|
125
|
+
homepage: https://github.com/Wenmar-Pro/vin_decoder
|
|
126
|
+
licenses:
|
|
127
|
+
- Apache-2.0
|
|
128
|
+
metadata:
|
|
129
|
+
allowed_push_host: https://rubygems.org
|
|
130
|
+
rdoc_options: []
|
|
131
|
+
require_paths:
|
|
132
|
+
- lib
|
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: 3.0.0
|
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
|
+
requirements:
|
|
140
|
+
- - ">="
|
|
141
|
+
- !ruby/object:Gem::Version
|
|
142
|
+
version: '0'
|
|
143
|
+
requirements: []
|
|
144
|
+
rubygems_version: 4.0.8
|
|
145
|
+
specification_version: 4
|
|
146
|
+
summary: A Ruby client for the NHTSA vPIC VIN decoding API.
|
|
147
|
+
test_files: []
|