I had a curl command which I converted using this.

This is the Ruby script:

 rabbitmqctl_url = CONFIG['rabbitmqctl']['url']
 rabbitmqctl_user = CONFIG['rabbitmqctl']['username']
 rabbitmqctl_password = CONFIG['rabbitmqctl']['password']
 uri = URI.parse("#{rabbitmqctl_url}/api/queues")
 request = Net::HTTP::Get.new(uri)
 request.basic_auth(rabbitmqctl_user, rabbitmqctl_password)
 req_options = { use_ssl: uri.scheme == 'https' }
 response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
 puts response.body

This is the curl command:

curl -u  username:password  http:localhost 15672/api/queue

This code is very lengthy.

  • 1
    \$\begingroup\$ You might want to look into gems that wrap some or all of this stuff in a simpler API, like httparty. With that you should be able to get closer to the simplicity of the curl command. The basic Ruby API is (on purpose) very bare bones, and doesn't try to be clever about things \$\endgroup\$ – Flambino Feb 28 '17 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.