nhtsa_vin 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/nhtsa_vin/query.rb +12 -7
- data/lib/nhtsa_vin/version.rb +1 -1
- data/spec/lib/nhtsa_vin/query_spec.rb +10 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8aab96946256f3db71577e6c15ee5b560417dd7
|
4
|
+
data.tar.gz: 602be71041addeaaf958fb5c5f9700061293ea4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48d8b50a590d210e618a889ab1d30ca655cf515017a68cae1af235a3087263084059cec5a6a3d7302fa5780d5681ea28a8b70bd68a2e7ea7a32b8356971af351
|
7
|
+
data.tar.gz: 7aa155cdbf659315daa7a90c9ff5fe347cb22b045e5cc0c712cc1673c5483ec118491df99a42eafcb64a6feb5b31604e527b829c2d0ee85e19aefa8b5d85d271
|
data/README.md
CHANGED
@@ -7,14 +7,14 @@
|
|
7
7
|
|
8
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.
|
9
9
|
|
10
|
-
Please note, this gem is currently in early development.
|
10
|
+
Please note, this gem is currently in early development.
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
14
14
|
Add this line to your application's Gemfile:
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
gem '
|
17
|
+
gem 'nhtsa_vin'
|
18
18
|
```
|
19
19
|
|
20
20
|
And then execute:
|
@@ -23,9 +23,9 @@ And then execute:
|
|
23
23
|
|
24
24
|
Or install it yourself as:
|
25
25
|
|
26
|
-
gem install
|
26
|
+
gem install nhtsa_vin
|
27
27
|
|
28
|
-
## Usage
|
28
|
+
## Usage
|
29
29
|
|
30
30
|
Validation
|
31
31
|
----
|
@@ -65,7 +65,7 @@ The actual data from the web service is contained in the `response` method. This
|
|
65
65
|
query.response # => <Struct::NhtsaResponse make="Jeep", model="Grand Cherokee", trim="Laredo/Rocky Mountain Edition", type="SUV", year="2008", size=nil, ... doors=4>
|
66
66
|
```
|
67
67
|
|
68
|
-
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`.
|
68
|
+
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`.
|
69
69
|
|
70
70
|
```ruby
|
71
71
|
query = NhtsaVin.get('SOME_BAD_VIN') # => <NhtsaVin::Query>
|
@@ -78,7 +78,7 @@ query.error # => "11- Incorrect Model Year, decoded data may not be accurate"
|
|
78
78
|
Vehicle Types
|
79
79
|
----
|
80
80
|
|
81
|
-
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.
|
81
|
+
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.
|
82
82
|
|
83
83
|
|
84
84
|
## License
|
data/lib/nhtsa_vin/query.rb
CHANGED
@@ -16,12 +16,14 @@ module NhtsaVin
|
|
16
16
|
|
17
17
|
def get
|
18
18
|
@raw_response = fetch
|
19
|
-
return if @raw_response.nil?
|
20
19
|
begin
|
21
|
-
|
20
|
+
return if @raw_response.nil? || (json_response = JSON.parse(@raw_response)).nil?
|
21
|
+
parse(json_response)
|
22
22
|
rescue JSON::ParserError
|
23
23
|
@valid = false
|
24
24
|
@error = 'Response is not valid JSON'
|
25
|
+
rescue StandardError => ex
|
26
|
+
raise "#{ex.message}: #{@raw_response.inspect}"
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
@@ -30,6 +32,11 @@ module NhtsaVin
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def parse(json)
|
35
|
+
if json['Message']&.match(/execution error/i)
|
36
|
+
@valid = false
|
37
|
+
@error = json.dig('Results', 0, 'Message')
|
38
|
+
return
|
39
|
+
end
|
33
40
|
@data = json['Results']
|
34
41
|
|
35
42
|
# 0 - Good
|
@@ -101,11 +108,9 @@ module NhtsaVin
|
|
101
108
|
@valid = false
|
102
109
|
|
103
110
|
url = URI.parse(@url)
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
108
|
-
|
111
|
+
http_options = { use_ssl: (url.scheme == 'https') }
|
112
|
+
http_options.update(@http_options)
|
113
|
+
Net::HTTP.start(url.host, url.port, http_options) do |http|
|
109
114
|
resp = http.request_get(url)
|
110
115
|
case resp
|
111
116
|
when Net::HTTPSuccess
|
data/lib/nhtsa_vin/version.rb
CHANGED
@@ -78,6 +78,16 @@ describe NhtsaVin::Query do
|
|
78
78
|
expect(client.error).to eq 'Response is not valid JSON'
|
79
79
|
end
|
80
80
|
end
|
81
|
+
context 'timeout response' do
|
82
|
+
before do
|
83
|
+
allow(client).to receive(:fetch).and_return('{"Count":0,"Message":"Execution Error","SearchCriteria":null,"Results":[{"Message":"Error encountered retrieving data: Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=6; handshake=14988; "}]}')
|
84
|
+
client.get
|
85
|
+
end
|
86
|
+
it 'is not valid' do
|
87
|
+
expect(client).not_to be_valid
|
88
|
+
expect(client.error).to match(/connection timeout expired/i)
|
89
|
+
end
|
90
|
+
end
|
81
91
|
context 'HTTP error' do
|
82
92
|
it '5xx' do
|
83
93
|
resp = Net::HTTPServerError.new(1.1, 503, 'Service unhappy')
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Barclay Loftus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.
|
104
|
+
rubygems_version: 2.5.2.2
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: A ruby library for accessing vin records from the NHTSA
|