lib/vin_service.rb in blackbook_client-0.1.1 vs lib/vin_service.rb in blackbook_client-0.1.2
- old
+ new
@@ -1,8 +1,10 @@
+require 'rest_client'
+
module VinService
+ include RestClient
- BASE_URL = 'https://service.blackbookcloud.com'.freeze
VEHICLE_BY_VIN_URL = "#{BASE_URL}/UsedCarWS/UsedCarWS/UsedVehicle/VIN".freeze
def range_by_vin(vin, query_params = {})
url = "#{VEHICLE_BY_VIN_URL}/#{vin}"
@@ -11,38 +13,6 @@
process_response(JSON.parse(response))
rescue => e
[{ error: e.to_s }, 500]
end
end
-
- def headers
- token = Base64.encode64("#{username}:#{password}")
- { Authorization: "Basic #{token}" }
- end
-
- def process_response(response)
- status = 200
-
- if response['error_count'].positive?
- response = { error: response['message_list'][0]['description'] }
- status = 400
- else
- response = map_fields(response)
- end
-
- [response, status]
- end
-
- def map_fields(response)
- return {} unless response && response['used_vehicles'] && response['used_vehicles']['used_vehicle_list']
- vehicle_range = response['used_vehicles']['used_vehicle_list'][0]
-
- return {
- range: {
- xclean: vehicle_range['adjusted_whole_xclean'],
- clean: vehicle_range['adjusted_whole_clean'],
- average: vehicle_range['adjusted_whole_avg'],
- rough: vehicle_range['adjusted_whole_rough']
- }
- }
- end
-end
\ No newline at end of file
+end