Created
February 7, 2014 03:14
-
-
Save addamh/8856908 to your computer and use it in GitHub Desktop.
style call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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