Skip to content

Instantly share code, notes, and snippets.

@radar
Created May 10, 2016 23:24
Show Gist options
  • Save radar/2909756e32053b576309abccd5efede2 to your computer and use it in GitHub Desktop.
Save radar/2909756e32053b576309abccd5efede2 to your computer and use it in GitHub Desktop.
class Advert::UpsertVehicle
def self.call(vehicle)
@vehicle = vehicle
@outdoria = OutdoriaAPIService.new(vehicle.retailer.api_key)
return unless @request_body = VehicleData::ToRequestBody.(vehicle)
@vehicle_code = vehicle.custom_id
if @outdoria.advert_exists?(@vehicle_code)
self.update_advert
else
self.create_advert
end
end
def self.update_advert
self.catch_errors(@outdoria.update_advert(@request_body))
self.delete_images
self.create_images
end
def self.create_advert
self.catch_errors(@outdoria.create_advert(@request_body))
self.create_images
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment