nhtsa_vin 0.0.1
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/.gitignore +6 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +0 -0
- data/CONTRIBUTING.md +9 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +44 -0
- data/Rakefile +7 -0
- data/lib/nhtsa_vin.rb +13 -0
- data/lib/nhtsa_vin/query.rb +96 -0
- data/lib/nhtsa_vin/version.rb +3 -0
- data/nhtsa_vin.gemspec +24 -0
- data/spec/fixtures/not_found.json +586 -0
- data/spec/fixtures/success.json +586 -0
- data/spec/lib/nhtsa_vin/query_spec.rb +59 -0
- data/spec/spec_helper.rb +1 -0
- metadata +120 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NhtsaVin::Query do
|
4
|
+
let(:client) { NhtsaVin::Query.new('2G1WT57K291223396') }
|
5
|
+
|
6
|
+
let(:success_response) { File.read(File.join('spec', 'fixtures', 'success.json')) }
|
7
|
+
let(:not_found_response) { File.read(File.join('spec', 'fixtures', 'not_found.json')) }
|
8
|
+
|
9
|
+
describe '#initialize' do
|
10
|
+
it 'stores the complete URL of the request' do
|
11
|
+
expect(client.url)
|
12
|
+
.to eq 'https://vpic.nhtsa.dot.gov/api/vehicles/decodevin/2G1WT57K291223396?format=json'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#get' do
|
17
|
+
context 'successful response' do
|
18
|
+
before do
|
19
|
+
allow(client).to receive(:fetch).and_return(success_response)
|
20
|
+
client.get
|
21
|
+
end
|
22
|
+
it 'fetches json and response is valid' do
|
23
|
+
expect(client.raw_response).to eq success_response
|
24
|
+
expect(client.valid?).to be true
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'its response' do
|
28
|
+
let(:response) { client.get }
|
29
|
+
it 'returns a struct' do
|
30
|
+
expect(response.class).to be Struct::NhtsaResponse
|
31
|
+
end
|
32
|
+
it 'returns the correct vehicle data' do
|
33
|
+
expect(response.year).to eq '2004'
|
34
|
+
expect(response.make).to eq 'Cadillac'
|
35
|
+
expect(response.model).to eq 'SRX'
|
36
|
+
expect(response.body_style).to eq 'Wagon'
|
37
|
+
expect(response.doors).to eq 4
|
38
|
+
end
|
39
|
+
it 'parses out the type' do
|
40
|
+
expect(response.type).to eq 'Minivan'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'error response' do
|
46
|
+
before do
|
47
|
+
allow(client).to receive(:fetch).and_return(not_found_response)
|
48
|
+
client.get
|
49
|
+
end
|
50
|
+
it 'fetches json and response is not valid' do
|
51
|
+
expect(client.raw_response).to eq not_found_response
|
52
|
+
expect(client.valid?).to be false
|
53
|
+
end
|
54
|
+
it 'returns nil' do
|
55
|
+
expect(client.get).to be_nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'nhtsa_vin'
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nhtsa_vin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Barclay Loftus
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: "# NHTSA Vin\n----\n\nA ruby gem for fetching and parsing vehicle identification
|
56
|
+
via the vehicle identification number (VIN) from the [NHTSA webservice](https://vpic.nhtsa.dot.gov/api/Home).
|
57
|
+
Note, this gem is not officially affiliated with the NHTSA.\n\nPlease note, this
|
58
|
+
gem is currently in early development. \n\n## Installation\n\nAdd this line to your
|
59
|
+
application's Gemfile:\n\n```ruby\ngem 'nhsta_vin'\n```\n\nAnd then execute:\n\n
|
60
|
+
\ bundle\n\nOr install it yourself as:\n\n gem install nhsta_vin\n\n## Usage\n\nUsage
|
61
|
+
is fairly simple. Provide a VIN, and the gem will return a struct of vehicle data.
|
62
|
+
\n\n```ruby\nquery = NhtsaVin.get('1J4BA5H11AL143811')\nquery.valid? # => true\nquery.response
|
63
|
+
# => <Struct::NhtsaResponse make=\"Jeep\", model=\"Grand Cherokee\", trim=\"Laredo/Rocky
|
64
|
+
Mountain Edition\", type=\"SUV\", year=\"2008\", size=nil, ... doors=4>\n```\n\nIn
|
65
|
+
the result no match is found, the result will be `nil`, and `#valid?` will return
|
66
|
+
`false`. \n\nVehicle Types\n----\n\nFor brievity, we're reducing the `Vehicle Type`
|
67
|
+
response to an enumerated set of `[\"Car\", \"Truck\", \"Van\", \"SUV\", \"Minivan\"]`.
|
68
|
+
We're doing a rough parse of the type and body style to achieve this. It's probably
|
69
|
+
not perfect. \n\n\n## License\n\nLicensed under the MIT License.\n"
|
70
|
+
email:
|
71
|
+
- barclay@deliv.co
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- CHANGELOG.md
|
79
|
+
- CONTRIBUTING.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- lib/nhtsa_vin.rb
|
85
|
+
- lib/nhtsa_vin/query.rb
|
86
|
+
- lib/nhtsa_vin/version.rb
|
87
|
+
- nhtsa_vin.gemspec
|
88
|
+
- spec/fixtures/not_found.json
|
89
|
+
- spec/fixtures/success.json
|
90
|
+
- spec/lib/nhtsa_vin/query_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
homepage: https://github.com/deliv/nhtsa_vin
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 2.3.0
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.6.14
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: A ruby library for accessing vin records from the NHTSA
|
116
|
+
test_files:
|
117
|
+
- spec/fixtures/not_found.json
|
118
|
+
- spec/fixtures/success.json
|
119
|
+
- spec/lib/nhtsa_vin/query_spec.rb
|
120
|
+
- spec/spec_helper.rb
|