From 3dd712629b844a55098601e6f02c8bcf7b8505c9 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Tue, 12 Nov 2019 12:35:54 -0500 Subject: [PATCH] added local vin validation --- app/models/vehicle.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/vehicle.rb b/app/models/vehicle.rb index c6d29ea..184c3f9 100644 --- a/app/models/vehicle.rb +++ b/app/models/vehicle.rb @@ -104,9 +104,14 @@ private # init method to pull JSON details from Edmunds def get_details if self.vin? + #validate the vin before calling a remote server + validation = NhtsaVin.validate(self.vin) begin + #if the vin validation failed, raise an exception and exit + raise RuntimeError, validation.error unless validation.valid? + # query NHTSA for details on the vin query = NhtsaVin.get(self.vin) - raise RuntimeError, query.error unless query.valid? + raise RuntimeError, query.error unless query.valid? @details = query.response rescue Exception => e errors.add(:vin, e.message)