Skip to content

Instantly share code, notes, and snippets.

@addamh
Created February 7, 2014 03:14
Show Gist options
  • Save addamh/8856908 to your computer and use it in GitHub Desktop.
Save addamh/8856908 to your computer and use it in GitHub Desktop.
style call
def styles
vins = params[:vins].split(',')
@style_packages = {}
vins.each do |v|
response = Rails.cache.fetch("edmunds/#{squish_vin(v)}/styles", :expires_in => 2.seconds) do
begin
tries ||= 3
squish_package = Edmunds::SquishVin.new.squish_vin(squish_vin(v))
squish_package["years"].first["styles"]
rescue RestClient::Forbidden => e
sleep 0.2
tries -= 1
if tries > 0
logger.info "Retrying Edmunds call!"
retry
else
render json: {error: "Edmunds API error"}, status: 500
return
end
end
end
@style_packages[v] = response
end
render json: @style_packages, status: 200
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment