nhtsa_vin 0.0.6 → 0.0.7
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 +9 -9
- data/lib/nhtsa_vin/query.rb +31 -6
- data/lib/nhtsa_vin/validation.rb +1 -1
- data/lib/nhtsa_vin/version.rb +1 -1
- data/spec/lib/nhtsa_vin/query_spec.rb +22 -1
- data/spec/lib/nhtsa_vin/validation_spec.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c417b90ce601fa0150143c271fded5fa77e06a9
|
4
|
+
data.tar.gz: a2a5c574e0f4ce6c8761dc363a50dfd6c6ca777b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5c0100a5a611a127f8fbedd315b28be5580cd33420783c1e7f98b29dd3d82f969a19011ca78ac4d808325520cd0582786a9addab3563f7e00e9459b2e6c1e82
|
7
|
+
data.tar.gz: ca722daf6017b49ce6775249fa666bcff33aa7585b7ac43347b8110d95aa3035236b879d59246e4cf06d1a45a8482230d47f1341199ceb9c7825dfac9acbd920
|
data/.circleci/config.yml
CHANGED
@@ -16,17 +16,17 @@ jobs:
|
|
16
16
|
steps:
|
17
17
|
- checkout
|
18
18
|
|
19
|
-
- run:
|
20
|
-
name: install dependencies
|
21
|
-
command: |
|
22
|
-
bundle install
|
23
|
-
|
24
19
|
- run:
|
25
20
|
name: Setup Code Climate test-reporter
|
26
21
|
command: |
|
27
22
|
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
28
23
|
chmod +x ./cc-test-reporter
|
29
|
-
|
24
|
+
|
25
|
+
- run:
|
26
|
+
name: install dependencies
|
27
|
+
command: |
|
28
|
+
bundle install
|
29
|
+
|
30
30
|
# run tests!
|
31
31
|
- run:
|
32
32
|
name: run tests
|
@@ -34,12 +34,12 @@ jobs:
|
|
34
34
|
mkdir /tmp/test-results
|
35
35
|
./cc-test-reporter before-build
|
36
36
|
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
37
|
-
rspec spec --format progress \
|
37
|
+
bundle exec rspec spec --format progress \
|
38
38
|
--format RspecJunitFormatter \
|
39
39
|
--out /tmp/test-results/rspec.xml \
|
40
|
-
--format progress \
|
41
40
|
$TEST_FILES
|
42
|
-
./cc-test-reporter
|
41
|
+
./cc-test-reporter sum-coverage coverage/coverage.json
|
42
|
+
./cc-test-reporter after-build --coverage-input-type simplecov --prefix coverage --exit-code $?
|
43
43
|
|
44
44
|
# collect reports
|
45
45
|
- store_test_results:
|
data/lib/nhtsa_vin/query.rb
CHANGED
@@ -9,14 +9,20 @@ module NhtsaVin
|
|
9
9
|
attr_reader :vin, :url, :response, :data, :error, :error_code, :raw_response
|
10
10
|
|
11
11
|
def initialize(vin, options={})
|
12
|
-
@vin = vin
|
12
|
+
@vin = vin.strip.upcase
|
13
|
+
@http_options = options[:http] || {}
|
13
14
|
build_url
|
14
15
|
end
|
15
16
|
|
16
17
|
def get
|
17
18
|
@raw_response = fetch
|
18
19
|
return if @raw_response.nil?
|
19
|
-
|
20
|
+
begin
|
21
|
+
parse(JSON.parse(@raw_response))
|
22
|
+
rescue JSON::ParserError
|
23
|
+
@valid = false
|
24
|
+
@error = 'Response is not valid JSON'
|
25
|
+
end
|
20
26
|
end
|
21
27
|
|
22
28
|
def valid?
|
@@ -92,19 +98,38 @@ module NhtsaVin
|
|
92
98
|
|
93
99
|
def fetch
|
94
100
|
begin
|
95
|
-
|
101
|
+
@valid = false
|
102
|
+
|
103
|
+
url = URI.parse(@url)
|
104
|
+
Net::HTTP.start(url.host, url.port, use_ssl: (url.scheme == 'https')) do |http|
|
105
|
+
@http_options.each do |key, val|
|
106
|
+
http.send("#{key}=", val) if val
|
107
|
+
end
|
108
|
+
|
109
|
+
resp = http.request_get(url)
|
110
|
+
case resp
|
111
|
+
when Net::HTTPSuccess
|
112
|
+
@valid = true
|
113
|
+
resp.body
|
114
|
+
when Net::HTTPRedirection
|
115
|
+
raise 'No support for HTTP redirection from NHTSA API'
|
116
|
+
when Net::HTTPClientError
|
117
|
+
@error = "Client error: #{resp.code} #{resp.message}"
|
118
|
+
nil
|
119
|
+
else
|
120
|
+
@error = resp.message
|
121
|
+
nil
|
122
|
+
end
|
123
|
+
end
|
96
124
|
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, SocketError,
|
97
125
|
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
|
98
126
|
Net::ProtocolError, Errno::ECONNREFUSED => e
|
99
|
-
@valid = false
|
100
127
|
@error = e.message
|
101
128
|
nil
|
102
129
|
end
|
103
130
|
end
|
104
|
-
|
105
131
|
end
|
106
132
|
|
107
133
|
Struct.new('NhtsaResponse', :vin, :make, :model, :trim, :type, :year,
|
108
134
|
:body_style, :vehicle_class, :doors)
|
109
135
|
end
|
110
|
-
|
data/lib/nhtsa_vin/validation.rb
CHANGED
data/lib/nhtsa_vin/version.rb
CHANGED
@@ -66,9 +66,30 @@ describe NhtsaVin::Query do
|
|
66
66
|
expect(client.error_code).to eq 11
|
67
67
|
end
|
68
68
|
end
|
69
|
+
context 'invalid response format' do
|
70
|
+
before do
|
71
|
+
allow(client).to receive(:fetch).and_return('This is not JSON')
|
72
|
+
client.get
|
73
|
+
end
|
74
|
+
it 'is not valid' do
|
75
|
+
expect(client).not_to be_valid
|
76
|
+
end
|
77
|
+
it 'has an error message' do
|
78
|
+
expect(client.error).to eq 'Response is not valid JSON'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
context 'HTTP error' do
|
82
|
+
it '5xx' do
|
83
|
+
resp = Net::HTTPServerError.new(1.1, 503, 'Service unhappy')
|
84
|
+
allow_any_instance_of(Net::HTTP).to receive(:request).and_return(resp)
|
85
|
+
client.get
|
86
|
+
expect(client).not_to be_valid
|
87
|
+
expect(client.error).to eq 'Service unhappy'
|
88
|
+
end
|
89
|
+
end
|
69
90
|
context 'connection or network error' do
|
70
91
|
before do
|
71
|
-
|
92
|
+
allow_any_instance_of(Net::HTTP).to receive(:request).and_raise(Net::ReadTimeout)
|
72
93
|
client.get
|
73
94
|
end
|
74
95
|
it 'should not raise' do
|
@@ -41,6 +41,10 @@ describe NhtsaVin::Validation do
|
|
41
41
|
expect(NhtsaVin::Validation.new(' 4T1BD1FK5CU061770 ').valid?)
|
42
42
|
.to be true
|
43
43
|
end
|
44
|
+
it 'converts to uppercase' do
|
45
|
+
expect(NhtsaVin::Validation.new('4t1bd1fk5cu061770').valid?)
|
46
|
+
.to be true
|
47
|
+
end
|
44
48
|
it 'validates BMW VINs' do
|
45
49
|
expect(NhtsaVin::Validation.new('WBAEV534X2KM16113').valid?)
|
46
50
|
.to be true
|
@@ -105,4 +109,4 @@ describe NhtsaVin::Validation do
|
|
105
109
|
end
|
106
110
|
end
|
107
111
|
end
|
108
|
-
end
|
112
|
+
end
|
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.7
|
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-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|