kernification kernification - 1 year ago 62
Ruby Question

Transform curl to open-uri in ruby?

I have a curl line like this:

curl -u 'private_user_key' -d 'checksum_type=paypal' -d 'amount=4200'

and I want to transform it into a open-uri call like this:

require 'open-uri'
open("", http_basic_authentication: ['private_user_key'])

Works so far, but how do I include the -d data-attributes like -d 'checksum_type=paypal' -d 'amount=4200'?

Thanks, Andreas

Answer Source

I think you'll be better off using Net::HTTP directly (instead of open-uri, which is just a convenience wrapper). This gives you more control over the request being made.

require 'net/http'
uri = URI("")
http =, uri.port)
request =
request.basic_auth("username", "password")
request.set_form_data('checksum_type' => 'paypal', 'amount' => 4200)
response = http.request(request)