Remove Edmunds API & Added NhtsaVin

This commit is contained in:
2018-03-03 12:38:56 -05:00
committed by GitHub
parent 88a6be0d27
commit 667d0bfa97

View File

@@ -41,7 +41,7 @@ class Vehicle < ActiveRecord::Base
# returns the style of the vehicle # returns the style of the vehicle
def style def style
begin begin
return @details['years'][0]['styles'][0]['name'] if @details return @details.trim if @details
rescue rescue
return nil return nil
end end
@@ -49,12 +49,12 @@ class Vehicle < ActiveRecord::Base
# returns the drive of the vehicle i.e. 2 wheel, 4 wheel, ect. # returns the drive of the vehicle i.e. 2 wheel, 4 wheel, ect.
def drive def drive
return @details['drivenWheels'].to_s.upcase if @details return @details.drive_type if @details
end end
# returns the number of doors of the vehicle # returns the number of doors of the vehicle
def doors def doors
return @details['numOfDoors'] if @details return @details.doors if @details
end end
# Force Upper Case for VIN numbers # Force Upper Case for VIN numbers
@@ -87,28 +87,23 @@ class Vehicle < ActiveRecord::Base
def get_details def get_details
if self.vin? if self.vin?
begin begin
@details = JSON.parse get_decoder.full(self.vin) query = NhtsaVin.get(self.vin)
raise @details['message'] if @details['status'].to_s.eql? "NOT_FOUND" raise error if not @details.valid?
raise @details['message'] if @details['status'].to_s.eql? "BAD_REQUEST" @details = query.response = NhtsaVin.get(self.vin)
rescue Exception => e rescue Exception => e
errors.add(:vin, e.message) errors.add(:vin, e.message)
end end
end end
end end
# returns the Edmunds decoder service
def get_decoder
return decoder = Edmunds::Vin.new(Setting.plugin_redmine_qbo['settingsEdmundsAPIKey'])
end
# decodes a vin and updates self # decodes a vin and updates self
def decode_vin def decode_vin
get_details get_details
if @details if @details
begin begin
self.year = @details['years'][0]['year'] self.year = @details.year
self.make = @details['make']['name'] self.make = @details.make
self.model = @details['model']['name'] self.model = @details.model
rescue Exception => e rescue Exception => e
errors.add(:vin, e.message) errors.add(:vin, e.message)
end end