nictrix nictrix - 3 months ago 17
Ruby Question

ruby httparty get response url or id after post

How can I get the response url or id from a rails project with httparty in a separate script after doing a post?

ruby script:

HTTParty.post('http://localhost:3000/change_logs', parameters)


response.body and all the others ones do not show the url and the response id

Answer

This works for me, there's probably a better way to do this though..

get_change_log_id = HTTParty.post('http://localhost:3000/change_logs.xml', parameters).to_a

get_change_log_id.each do |r|
  r.each do |sub|
    sub2 = sub.to_a
      sub2.each do |s|
        if s.index "id"
          @change_log_id = s.to_s.sub(/[i]/, '').sub(/[d]/, '')
        end
      end
  end
end
Comments