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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c417b90ce601fa0150143c271fded5fa77e06a9
4
- data.tar.gz: a2a5c574e0f4ce6c8761dc363a50dfd6c6ca777b
3
+ metadata.gz: e8aab96946256f3db71577e6c15ee5b560417dd7
4
+ data.tar.gz: 602be71041addeaaf958fb5c5f9700061293ea4a
5
5
  SHA512:
6
- metadata.gz: a5c0100a5a611a127f8fbedd315b28be5580cd33420783c1e7f98b29dd3d82f969a19011ca78ac4d808325520cd0582786a9addab3563f7e00e9459b2e6c1e82
7
- data.tar.gz: ca722daf6017b49ce6775249fa666bcff33aa7585b7ac43347b8110d95aa3035236b879d59246e4cf06d1a45a8482230d47f1341199ceb9c7825dfac9acbd920
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 'nhsta_vin'
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 nhsta_vin
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
@@ -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
- parse(JSON.parse(@raw_response))
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
- 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
-
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
@@ -1,3 +1,3 @@
1
1
  module NhtsaVin
2
- VERSION = '0.0.7'.freeze
2
+ VERSION = '0.0.8'.freeze
3
3
  end
@@ -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.7
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: 2018-02-21 00:00:00.000000000 Z
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.6.14
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