nhtsa_vin 0.0.3 → 0.0.4
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/.circleci/config.yml +49 -0
- data/Gemfile +6 -0
- data/README.md +20 -4
- data/lib/nhtsa_vin/query.rb +10 -1
- data/lib/nhtsa_vin/version.rb +1 -1
- data/nhtsa_vin.gemspec +1 -1
- data/spec/lib/nhtsa_vin/query_spec.rb +41 -0
- data/spec/spec_helper.rb +9 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81eb7bb2954ef3ebc22afde17e6f70b508020acc
|
4
|
+
data.tar.gz: 6cea7414b6edc216d91ba274bced8d058bd05d59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 703a0437f83f5d03eb8ffc6bbedaf3dd422b77d3327646bca2b0ae0c262e2269dc88d702be9901bbb8b7227a230730f077c9241d0017567576ba77db18e26d56
|
7
|
+
data.tar.gz: f7244387c404bb224cf90585df93141537f7a3dc72e99f8cf543eb57d82b2469fb49f2ed3c47ca8314558e42878122fa78857067d11162a7a03c08d31f5cf1a4
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
2
|
+
#
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
+
#
|
5
|
+
version: 2
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
environment:
|
9
|
+
CC_TEST_REPORTER_ID: 2ae3d7a510acfedce89d23528ad0b3e6cfa0a7aec07bd2b978c3b8e996ee0d35
|
10
|
+
docker:
|
11
|
+
# specify the version you desire here
|
12
|
+
- image: circleci/ruby:2.4.1-node-browsers
|
13
|
+
|
14
|
+
working_directory: ~/repo
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- checkout
|
18
|
+
|
19
|
+
- run:
|
20
|
+
name: install dependencies
|
21
|
+
command: |
|
22
|
+
bundle install
|
23
|
+
|
24
|
+
- run:
|
25
|
+
name: Setup Code Climate test-reporter
|
26
|
+
command: |
|
27
|
+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
28
|
+
chmod +x ./cc-test-reporter
|
29
|
+
|
30
|
+
# run tests!
|
31
|
+
- run:
|
32
|
+
name: run tests
|
33
|
+
command: |
|
34
|
+
mkdir /tmp/test-results
|
35
|
+
./cc-test-reporter before-build
|
36
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
37
|
+
rspec spec --format progress \
|
38
|
+
--format RspecJunitFormatter \
|
39
|
+
--out /tmp/test-results/rspec.xml \
|
40
|
+
--format progress \
|
41
|
+
$TEST_FILES
|
42
|
+
./cc-test-reporter after-build --coverage-input-type simplecov --prefix coverage --exit-code $?
|
43
|
+
|
44
|
+
# collect reports
|
45
|
+
- store_test_results:
|
46
|
+
path: /tmp/test-results
|
47
|
+
- store_artifacts:
|
48
|
+
path: /tmp/test-results
|
49
|
+
destination: test-results
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# NHTSA Vin
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/nhtsa_vin)
|
4
|
+
[](https://circleci.com/gh/deliv/nhtsa_vin)
|
5
|
+
[](https://codeclimate.com/github/deliv/nhtsa_vin/maintainability)
|
6
|
+
|
4
7
|
|
5
8
|
A ruby gem for fetching and parsing vehicle identification via the vehicle identification number (VIN) from the [NHTSA webservice](https://vpic.nhtsa.dot.gov/api/Home). Note, this gem is not officially affiliated with the NHTSA.
|
6
9
|
|
@@ -24,20 +27,33 @@ Or install it yourself as:
|
|
24
27
|
|
25
28
|
## Usage
|
26
29
|
|
27
|
-
Usage is fairly simple
|
30
|
+
Usage is fairly simple, there's an exposed `get` class method that you can pass in a VIN string to, and it will return you a NhtsaVin::Query.
|
28
31
|
|
29
32
|
```ruby
|
30
|
-
query = NhtsaVin.get('1J4BA5H11AL143811')
|
33
|
+
query = NhtsaVin.get('1J4BA5H11AL143811') # => <NhtsaVin::Query>
|
31
34
|
query.valid? # => true
|
35
|
+
```
|
36
|
+
|
37
|
+
The actual data from the webservice is contained in the `response` method. This returns a struct containing the various interesting bits from the API.
|
38
|
+
|
39
|
+
```ruby
|
32
40
|
query.response # => <Struct::NhtsaResponse make="Jeep", model="Grand Cherokee", trim="Laredo/Rocky Mountain Edition", type="SUV", year="2008", size=nil, ... doors=4>
|
33
41
|
```
|
34
42
|
|
35
|
-
|
43
|
+
They query object also contains helper methods for error handling. For example, in the result no match is found, the result will be `nil`, and `#valid?` will return `false`.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
query = NhtsaVin.get('SOME_BAD_VIN') # => <NhtsaVin::Query>
|
47
|
+
query.valid? # => false
|
48
|
+
query.error_code # => 11
|
49
|
+
query.error # => "11- Incorrect Model Year, decoded data may not be accurate"
|
50
|
+
```
|
51
|
+
|
36
52
|
|
37
53
|
Vehicle Types
|
38
54
|
----
|
39
55
|
|
40
|
-
For
|
56
|
+
For brevity, we're reducing the `Vehicle Type` response to an enumerated set of `["Car", "Truck", "Van", "SUV", "Minivan"]`. We're doing a rough parse of the type and body style to achieve this. It's probably not perfect.
|
41
57
|
|
42
58
|
|
43
59
|
## License
|
data/lib/nhtsa_vin/query.rb
CHANGED
@@ -15,6 +15,7 @@ module NhtsaVin
|
|
15
15
|
|
16
16
|
def get
|
17
17
|
@raw_response = fetch
|
18
|
+
return if @raw_response.nil?
|
18
19
|
parse(JSON.parse(@raw_response))
|
19
20
|
end
|
20
21
|
|
@@ -90,7 +91,15 @@ module NhtsaVin
|
|
90
91
|
end
|
91
92
|
|
92
93
|
def fetch
|
93
|
-
|
94
|
+
begin
|
95
|
+
Net::HTTP.get(URI.parse(@url))
|
96
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, SocketError,
|
97
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
|
98
|
+
Net::ProtocolError, Errno::ECONNREFUSED => e
|
99
|
+
@valid = false
|
100
|
+
@error = e.message
|
101
|
+
nil
|
102
|
+
end
|
94
103
|
end
|
95
104
|
|
96
105
|
end
|
data/lib/nhtsa_vin/version.rb
CHANGED
data/nhtsa_vin.gemspec
CHANGED
@@ -66,5 +66,46 @@ describe NhtsaVin::Query do
|
|
66
66
|
expect(client.error_code).to eq 11
|
67
67
|
end
|
68
68
|
end
|
69
|
+
context 'connection or network error' do
|
70
|
+
before do
|
71
|
+
allow(Net::HTTP).to receive(:get_response).and_raise(Net::ReadTimeout)
|
72
|
+
client.get
|
73
|
+
end
|
74
|
+
it 'should not raise' do
|
75
|
+
expect { client.get }.to_not raise_error
|
76
|
+
end
|
77
|
+
it 'should return nil' do
|
78
|
+
expect(client.get).to be_nil
|
79
|
+
end
|
80
|
+
it 'should not be valid' do
|
81
|
+
expect(client.valid?).to be false
|
82
|
+
end
|
83
|
+
it 'should have an error message' do
|
84
|
+
expect(client.error).to eq 'Net::ReadTimeout'
|
85
|
+
end
|
86
|
+
it 'should not contain a response object' do
|
87
|
+
expect(client.response).to be_nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#vehicle_type' do
|
93
|
+
let(:query) { NhtsaVin::Query.new('') }
|
94
|
+
context 'with type of TRUCK' do
|
95
|
+
it 'returns van when the type is truck and body_class includes Van' do
|
96
|
+
expect(query.vehicle_type('Cargo Van', 'TRUCK')).to eq 'Van'
|
97
|
+
end
|
98
|
+
it 'returns truck otherwise' do
|
99
|
+
expect(query.vehicle_type('Light Duty Pickup', 'TRUCK')).to eq 'Truck'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
context 'with type MULTIPURPOSE PASSENGER VEHICLE (MPV)' do
|
103
|
+
it 'returns SUV when the body class supports it' do
|
104
|
+
expect(
|
105
|
+
query.vehicle_type('Sport Utility Vehicle (SUV)',
|
106
|
+
'MULTIPURPOSE PASSENGER VEHICLE (MPV)')
|
107
|
+
).to eq 'SUV'
|
108
|
+
end
|
109
|
+
end
|
69
110
|
end
|
70
111
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nhtsa_vin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Barclay Loftus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -61,6 +61,7 @@ executables: []
|
|
61
61
|
extensions: []
|
62
62
|
extra_rdoc_files: []
|
63
63
|
files:
|
64
|
+
- ".circleci/config.yml"
|
64
65
|
- ".gitignore"
|
65
66
|
- ".rspec"
|
66
67
|
- CHANGELOG.md
|