tags:

views:

83

answers:

3

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).

+1  A: 
system ("curl --insecure #{url}")
Brian Maltzan
+4  A: 

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("/")
Jonas Elfström
I got this an error. (StackOverflow won't let me print the whole thing, so here's the "important part"). Warning: post-commit hook failed (exit code 1) with output:/usr/lib/ruby/1.8/net/http.rb:586:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
Avry
Added code for handling invalid certificates.
Jonas Elfström
`open("#{REFRESH_DRADIS_URL}")` could be simplified to `open(REFRESH_DRADIS_URL)`.
eric
Jonas Elfström
+2  A: 

For such a simple problem, I wouldn't bother with shelling out to curl, I'd simply do

require 'net/https'

http = Net::HTTP.new('redmineserver+webappkey', 443)

http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

http.get('/')

And for more complex problems, I'd still not shell out to curl, but rather use one of the many Ruby libcurl bindings.

Jörg W Mittag
Making this one the answer since it was the first solution that was closest to the one that worked for me. For folks new to Ruby, the first argument to HTTP.new() is the URI of the server. http.get() takes the URL, starting from /as an argument.
Avry