Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the right syntax for Ruby to do a system call to curl?

Tags:

curl

ruby

To refresh Redmine, I need SVN to ping our Redmine installation from our post-commit hook. Our post-commit hook is a Ruby script that generates an email. I'd like to insert a call do this:

curl --insecure https://redmineserver+webappkey

This call works from the command line but when I try to do this:

#!/usr/bin/ruby -w

REFRESH_DRADIS_URL = "https://redmineserver+webappkey"
system("/usr/bin/curl", "--insecure", "#{REFRESH_DRADIS_URL}")

It doesn't work. How do I do this in ruby? I googled 'ruby system curl' but I just got a bunch of links to integrate curl into ruby (which is NOT what I'm interested in).

like image 636
Avery Avatar asked Sep 16 '10 12:09

Avery


1 Answers

There are many ways

REFRESH_DRADIS_URL = "https://redmineserver+webappkey"
result = `/usr/bin/curl --insecure #{REFRESH_DRADIS_URL}`

but I don't think you have to use curl at all. Try this

require 'open-uri'
open(REFRESH_DRADIS_URL)

If the certificate isn't valid then it gets a little more complicated

require 'net/https'
http = Net::HTTP.new("amazon.com", 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
resp, data = http.get("/")
like image 79
Jonas Elfström Avatar answered Sep 21 '22 23:09

Jonas Elfström