Retry storing HTTP response into a variable until specific code
The 1.times ... redo thing is just awful. Replace that with an until loop, like this:

success = false
until success
  ...
  case response.code
  ...
  when "200"
    success = true
    "ok"
  else
    ...
  end 
end