Fixed vin decoding

This commit is contained in:
2018-03-03 13:54:19 -05:00
parent 63fa94e6f2
commit 8838d36793

View File

@@ -83,15 +83,15 @@ class Vehicle < ActiveRecord::Base
where("vin LIKE ?", "%#{search}%") where("vin LIKE ?", "%#{search}%")
end end
private private
# init method to pull JSON details from Edmunds # init method to pull JSON details from Edmunds
def get_details def get_details
if self.vin? if self.vin?
begin begin
query = NhtsaVin.get(self.vin) query = NhtsaVin.get(self.vin)
raise error if not @details.valid? raise RuntimeError, query.error unless query.valid?
@details = query.response = NhtsaVin.get(self.vin) @details = query.response
rescue Exception => e rescue Exception => e
errors.add(:vin, e.message) errors.add(:vin, e.message)
end end
@@ -103,9 +103,9 @@ class Vehicle < ActiveRecord::Base
get_details get_details
if @details if @details
begin begin
self.year = @details.year self.year = @details.year unless @details.year.nil?
self.make = @details.make self.make = @details.make unless @details.make.nil?
self.model = @details.model self.model = @details.model unless @details.model.nil?
rescue Exception => e rescue Exception => e
errors.add(:vin, e.message) errors.add(:vin, e.message)
end end