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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 987b6fadc99bac8045a8288ca6effb187501f19d
4
- data.tar.gz: bcdb074f6bf27055805bd9a6821446c3fed38ec6
3
+ metadata.gz: 81eb7bb2954ef3ebc22afde17e6f70b508020acc
4
+ data.tar.gz: 6cea7414b6edc216d91ba274bced8d058bd05d59
5
5
  SHA512:
6
- metadata.gz: 28447017cd5ea2d27cf6cc684085fe2720744cc64a0f37587916574fd138c018e80c0313a694921524a53c0117163a53fd170aa86e8a73533ee5bbc11c6e2ff9
7
- data.tar.gz: c82a876e940ca2aea5ae07d0f533614129b644cc7f824c571f89b543779edfac53e734729ba46274b8b4656c3b0f3a331da7398fc137ed592adcacbea938ea33
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
@@ -1,3 +1,9 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ group :test, :development do
4
+ gem 'rspec_junit_formatter'
5
+ gem 'codeclimate-test-reporter', require: false
6
+ gem 'simplecov-json', require: false
7
+ end
8
+
3
9
  gemspec
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # NHTSA Vin
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/nhtsa_vin.svg)](https://badge.fury.io/rb/nhtsa_vin)
4
+ [![CircleCI](https://circleci.com/gh/deliv/nhtsa_vin.svg?style=svg)](https://circleci.com/gh/deliv/nhtsa_vin)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/5096bcc9d52e5253c532/maintainability)](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. Provide a VIN, and the gem will return a struct of vehicle data.
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
- In the result no match is found, the result will be `nil`, and `#valid?` will return `false`.
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 brievity, 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.
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
@@ -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
- Net::HTTP.get(URI.parse(@url))
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
@@ -1,3 +1,3 @@
1
1
  module NhtsaVin
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'.freeze
3
3
  end
@@ -24,5 +24,5 @@ Gem::Specification.new do |gem|
24
24
  gem.required_ruby_version = '>= 2.3.0'
25
25
  gem.add_development_dependency 'rake'
26
26
  gem.add_development_dependency 'bundler'
27
- gem.add_development_dependency 'rspec'
27
+ gem.add_development_dependency 'rspec'
28
28
  end
@@ -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
@@ -1 +1,9 @@
1
- require 'nhtsa_vin'
1
+ require 'simplecov'
2
+ require 'simplecov-json'
3
+ SimpleCov.formatters = [
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ SimpleCov::Formatter::JSONFormatter,
6
+ ]
7
+
8
+ SimpleCov.start
9
+ require 'nhtsa_vin'
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.3
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-02 00:00:00.000000000 Z
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