mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 17:04:23 -05:00
Remove Edmunds API & Added NhtsaVin
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user